27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

314 CHAPTER 12 Sending email<br />

To test all this, you’ll use the email_spec gem, which you first used back in<br />

chapter 6. This gem provides very useful Cucumber steps (and RSpec helpers!) that<br />

allow you to easily verify that an email was sent during a test, and you’ll be taking full<br />

advantage of these steps in the feature that you’ll be writing right now.<br />

12.1.1 Automatically watching a ticket<br />

This feature will initially test that a user automatically watches a ticket when they create<br />

it. Whenever someone else updates this ticket, the user who created it (and later,<br />

anybody else watching the ticket) will receive an email notification. You put this new<br />

feature in features/ticket_notifications.feature and fill it with the content from the following<br />

listing.<br />

Listing 12.1 features/ticket_notifications.feature<br />

Feature: Ticket Notifications<br />

Background:<br />

Given there are the following users:<br />

| email | password |<br />

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

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

Given a clear email queue<br />

Given there is a project called "TextMate 2"<br />

And "alice@ticketee.com" can view the "TextMate 2" project<br />

And "bob@ticketee.com" can view the "TextMate 2" project<br />

And "alice@ticketee.com" has created a ticket for this project:<br />

| title | description |<br />

| Release date | TBA very shortly. |<br />

Given I am signed in as "bob@ticketee.com"<br />

Given I am on the homepage<br />

Scenario: Ticket owner is automatically subscribed to a ticket<br />

When I follow "TextMate 2"<br />

And I follow "Release date"<br />

And I fill in "Text" with "Is it out yet?"<br />

And I press "Create Comment"<br />

B Clear received emails<br />

Then "alice@ticketee.com" should receive an email<br />

When "alice@ticketee.com" opens the email<br />

Then they should see "updated the Release date ticket" in the email body<br />

And they should see "[ticketee] TextMate 2 -<br />

Release date" in the email subject<br />

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

Then I should see "Release date" within "#ticket h2"<br />

You use the “Given a clear email queue” step B near the top of your Background,<br />

which will clear out any received emails from ActionMailer::Base.deliveries<br />

where the test deliveries are stored. This is important because two confirmation emails<br />

get sent out when you create the users, and you don’t want your “should receive an<br />

email” step in the scenario to retrieve those instead.

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

Saved successfully!

Ooh no, something went wrong!