Skip to content

Instantly share code, notes, and snippets.

@alvinslee
Created January 26, 2016 03:10
Show Gist options
  • Save alvinslee/404effdac99e1675a5c3 to your computer and use it in GitHub Desktop.
Save alvinslee/404effdac99e1675a5c3 to your computer and use it in GitHub Desktop.
Test interface in Cucumber 1 Time Only

Test the interface 1 time only

There were examples in our Cucumber tests where the first scenario test really seemed to be testing that the interface does what it was supposed to, while all subsequent tests were simply checks that the controller did what it was supposed to when given different POST data. This causes a lot of overhead. For example:

Scenario: Signing up a new user creates guest account and sends invitation email

Given I am on the sign up page
When I enter "John" as the first name for the new user
And I enter "Smith" as the last name for the new user
And I enter "johnsmith@gmail.com" as the email for the new user
And I click on the save button
Then I should be on the guest home page
And I should have 1 guest
And I should be logged in as guest 1
And guest 1 should receive an invitation email

Scenario: Signing up a new user using existing account credentials sends login help instructions

Given I have 1 guest
And the email for guest 1 is "johnsmith@gmail.com"
And I am on the sign up page
When I enter "John" as the first name for the new user
And I enter "Smith" as the last name for the new user
And I enter "johnsmith@gmail.com" as the email for the new user
And I click on the save button
Then I should be on the guest home page
And I should have 1 guest
And I should be logged in as guest 1
And guest 1 should receive a login help instructions email

The first test is sufficient to ensure that the sign up page interface works as it ought to. But the second test brings a lot of redundancy, re-testing all of the interface unnecessarily. The goal of the second test, actually, is not to check the interface. It is to check that the controller action for receiving a new sign up sends the correct email (in this case a "login help instructions" email) if the guest with this email already exists. This test should be removed from Cucumber, and instead an RSpec controller test should be written in its place.

General principle: Use a Cucumber scenario to test the functionality of the interface 1 time only. After that, if you're really just testing correct controller response to different data inputs, then use an RSpec controller (or model) test instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment