Story-based acceptance testing
In my previous post I talked a bit about Behaviour Driven Development and RSpec’s beautiful syntax for writing specifications.
This week I stumbled upon acceptance testing in RSpec and a very pretty way of writing those tests.
A simple acceptance test would look like this:
Story: A user sends an invitation The invitation page should allow users to invite friends Scenario: Sending an invitation Given a new unused email When the user goes to /invite/create And the user types 'Test' into the invite_name field And the user types 'User' into the invite_surname field And the user types 'someemail@email.com' into the invite_email field And the user clicks the commit button Then the page should contain the text 'Test User was invited' Scenario: Sending an invitation to an already used email address Given an already used email address someemail@email.com When the user goes to /invite/create And the user types 'Test' into the invite_name field And the user types 'User' into the invite_surname field And the user types 'someemail@email.com' into the invite_email field And the user clicks the commit button Then the page should contain the text 'Email already exists'
Now these tests don’t do anything by themselves, you need to run them against the application.
This is where Selenium comes in. Using RSpec’s story runner, you can feed these plain-text stories to Selenium.
Selenium will open your web application in a browser and go to URL’s, enter data, click buttons/checkboxes/radiobuttons. It’s kinda spooky to see your browser navigate to pages by itself
Here’s another test that checks the login function
Story: A user logs in Scenario: Logging in fails Given a user with username 'Arie' and password 'test' When the user goes to /login And the user types 'Arie' into the login field And the user types 'not-test' into the password field And the user clicks the commit button Then the page should contain the text 'Unable to login' Scenario: Logging in successfully Given a user with username 'Arie' and password 'test' When the user goes to /login And the user types 'Arie' into the login field And the user types 'test' into the password field And the user clicks the commit button Then the page should contain the text 'Logged in'
For now I’m not planning on covering my entire application with tests like this. I’m just going to make a few tests that I can show to my school when I finish my internship.
[...] Again a post about plain text user stories [...]