[rspec-users] Cucumber - Testing ActionMailer

James Byrne lists at ruby-forum.com
Mon Apr 27 16:44:03 EDT 2009

I need some help with this.  I have installed email-spec (courtesy of
BMabey) and I have configure things thusly:

  Scenario: E-Mail Exchange Rates to notify parties
    Given a currency exchange feed from the Bank of Canada
    When the currency exchange retrieval script runs
    Then I should receive an email

Then /should receive (an|\d+) e-?mails?/ do |amount|
  amount = 1 if amount == "an"
  unread_emails_for(current_email_address).size.should == amount.to_i

# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.gem 'bmabey-email_spec', :lib => 'email_spec'

class MailerPublic < ActionMailer::Base
  def forex_daily_notice(address,rates)
    rates_effective = Date.today.to_s(:db)
    recipients  address.to_a
    from        "ForexService at harte-lyne.ca"
    reply_to    "support at harte-lyne.ca"
    subject     "#{rates_effective} - Foreign Exchange Rates Notice"
    body        :rates_effective => rates_effective, :rates => rates

Canada Customs foreign currency exchange rates for
currency conversion of shipments made on <%=@rates_effective%>

When I run this

# Format and email the results.
if fx_hash_array
  puts "got an array"
  send_to = 'test_email at example.com'
  puts ActionMailer::Base.deliveries.length
  ActionMailer::Base.deliveries.each { |m| puts m }

Then I see this:

got an array

This is my first attempt at using ActionMailer so no doubt I have
overlooked something basic.  Can anyone tell me what it is?
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list