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.

Real-world email<br />

Listing 12.13 config/initializers/mail.rb<br />

ActionMailer::Base.smtp_settings = {<br />

:user_name => "youraccount@gmail.com",<br />

:password => "password",<br />

:address => "smtp.gmail.com",<br />

:port => 587,<br />

:tls => true<br />

}<br />

With these settings in this file, you can rerun bin/cucumber features/gmail.feature<br />

to see that it passes now up to the last two steps, which are undefined:<br />

When /^I log into gmail with:$/ do |table|<br />

# table is a Cucumber::Ast::Table<br />

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

end<br />

Then /^there should be an email from Ticketee in my inbox$/ do<br />

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

end<br />

With these step definitions, you’ll be able to connect to Gmail using settings specified<br />

in a Cucumber table format and then check for the email, which should be sent by<br />

steps earlier in this feature. You need to define these now.<br />

12.3.3 Connecting to Gmail<br />

You’ve now sent the email to the server, but you don’t have any steps in place to read<br />

these emails from your Gmail account and check that one of the emails is from Ticketee.<br />

As you can almost anticipate, there’s a gem that can help you with this, called<br />

quite simply gmail. This gem will let you connect to a Gmail server using the username<br />

and password you just used to set up an SMTP connection, and also read the<br />

emails for that account. The code it uses looks like this:<br />

Gmail.connect(username, password)<br />

Figure 12.9<br />

Configuring other<br />

mail clients<br />

You’ll also use this gem in the next section, when we look at how you can receive<br />

emails into your application. It’s a pretty neat gem, and it’s got a great README, which<br />

can be seen at http://github.com/nu7hatch/gmail.<br />

337

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

Saved successfully!

Ooh no, something went wrong!