27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

# Email Spec helpers<br />

require 'email_spec'<br />

require 'email_spec/cucumber'<br />

6.3.2 Confirming confirmation<br />

Confirmation link sign-in<br />

With the email_spec gem now fully installed and set up, let’s write a feature for signing<br />

users in when they click the confirmation link they should receive in their email.<br />

Insert the following listing at features/signing_in.feature.<br />

Listing 6.3 features/signing_in.feature<br />

Feature: Signing in<br />

In order to use the site<br />

As a user<br />

I want to be able to sign in<br />

Scenario: Signing in via confirmation<br />

Given there are the following users:<br />

| email | password |<br />

| user@ticketee.com | password |<br />

And "user@ticketee.com" opens the email with subject<br />

➥"Confirmation instructions"<br />

And they click the first link in the email<br />

Then I should see "Your account was successfully confirmed"<br />

And I should see "Signed in as user@ticketee.com"<br />

With this scenario, you make sure that when users are created, they receive an email<br />

called “Confirmation instructions” that should contain confirmation instructions.<br />

This email will contain a link, and when users click it, they should see two things: a<br />

message saying “Your account was successfully confirmed” and notification that they<br />

are now “Signed in as user@ticketee.com” where user@ticketee.com represents the<br />

username.<br />

The first step in this scenario is currently undefined, so when you run this feature<br />

using bin/cucumber features/signing_in.feature, it fails with the undefined step:<br />

Given /^there are the following users:$/ do |table|<br />

pending # express the regexp above with the code you wish you had<br />

end<br />

This step definition allows you to create as many users as you wish using Cucumber’s<br />

table syntax. Put this step definition inside a new file called features/step_definitions/<br />

user_steps.rb, using the code from the following listing.<br />

Listing 6.4 features/step_definitions/user_steps.rb<br />

Given /^there are the following users:$/ do |table|<br />

table.hashes.each do |attributes|<br />

@user = User.create!(attributes)<br />

end<br />

end<br />

123

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!