Our First Test: Get Homepage
Explore how to write and execute your first feature test in Ruby on Rails by creating a user registration feature file, running tests with Cucumber, and implementing step definitions to cover homepage interactions.
We'll cover the following...
Add our first test
The first step is to create a new file for our new feature.
The file can be generated using the following command:
$ touch features/user_registration.feature
We need to add the following text to the newly-generated file:
Run our test
As mentioned previously, the test guides everything we do moving forward. So, the logical next step will be to run the test and see what happens.
We’ll use the following command to run the test:
$ bundle exec cucumber features/user_registration.feature
Note: The
bundle execcan be omitted when running locally, depending on how your application is set up.
Running the test tells us we have one scenario with no step definitions defined yet. It also gives us a nice template to describe what each of those lines in our feature test means.
The SPA widget below shows our sample application. The features folder, along with all its files, has already been created. Clicking the “Run” button executes the tests by running the cucumber command.