Reputation: 2830
How to write the following feature in rspec?
Feature: Signing in; In order to use the site as a user, I want to be able to sign in
Scenario: Signing in via confirmation Given there are the following users: |email |password| |[email protected] |password| And "[email protected]" opens the mail with subject "Confirmation instructions" And they click the first link in the email Then I should see "Your account was successfully confirmed" And I should see "Signed in as [email protected]"
Upvotes: 1
Views: 880
Reputation: 107728
This looks like the feature from the first edition of Rails 3 in Action, which I'm currently re-writing into a second edition. The second edition's feature goes like this:
feature 'Signing in' do
before do
Factory(:user, :email => "[email protected]")
end
scenario 'Signing in via confirmation' do
open_email "[email protected]", :with_subject => /Confirmation/
click_first_link_in_email
page.should have_content("Your account was successfully confirmed")
page.should have_content("Signed in as [email protected]")
end
end
This is using Capybara's new feature syntax, which for all intents and purposes is the same as RSpec's context
blocks. By using a before
you set up a user that you can use inside this feature. Inside the scenario, you use the open_email
method (provided by the email_spec gem) to open the email, and the click_first_link_in_email
method also provided by that gem to perform those two steps.
That then takes you to a page where you should be able to see the two messages as so desired.
Upvotes: 2