Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Feature Tests in Rails


Wet vs. DRY

Test's should not be very dry. WET tests allow you to continually learn about your system, and understand the impact of feature changes.

For example.

  1. You have eight tests that describe the user registration process.
  2. The progression through the process is dried up in Step Definitions or a helper.
  3. You change conditional to show a confirmation dialog and edit the test helper to match.
  4. You miss the fact that in one of the other tests, the user should still see the dialog.

The problem is hidden because the test helper provided no context about the different scenarios.

Some DRY guidelines:

Feature files

Instead, establish a background at the start of test and mitigate the risk that the whole story is not played out by:

For example, the following test is focused on the action of getting the "widget app".

Feature: 'Downloading our awesome widget app'
Given John is logged in
When he visits the download page
And he downloads the widget app
Then he has our awesome widget app 

There is no evidence that he can register and log in to do so. That's ok, so long as a test exists for A user registers with the site and A registered user can log in.

It is possible that between Register and Login and between Login and Download that something could change and invalidate a test. Perhaps the download link no longer appears on the page you see after login. This is where you do need travelling tests.

Smoke and travelling tests