Reputation: 5435
I've running some Cucumber/Capybara tests. I've been using the email_spec gem to check email stuff. Some steps where of the kind 'And "[email protected]" should receive an email'. They give no problem when I run the test using the rack_test driver. However, they fail when using the selenium driver:
And "[email protected]" should receive an email
expected: 1
got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)
Can you help me? Thanks
Upvotes: 3
Views: 823
Reputation: 5192
You have to put your emails into a file because by default rails in test environemnt saves them in static variable that cannot be accessed from test thread. If you're using rails3 set delivery method to :file
in cucumber environment. If you're on rails 2.x put this into your cucumber initializer:
ActionMailer::Base.class_eval do
DELIVERIES_CACHE_PATH =
File.join(RAILS_ROOT,'tmp','cache',"action_mailer_cache_deliveries {ENV['TEST_ENV_NUMBER']}.cache")
def perform_delivery_cache(mail)
deliveries = File.open(DELIVERIES_CACHE_PATH, 'r') do |f|
Marshal.load(f)
end
deliveries << mail
File.open(DELIVERIES_CACHE_PATH,'w') { |f| Marshal.dump(deliveries, f) }
end
def self.cached_deliveries
File.open(DELIVERIES_CACHE_PATH,'r') { |f| Marshal.load(f) }
end
end
config.action_mailer.delivery_method = :cache
Upvotes: 2