我正在进行一些Cucumber / Capybara测试。我一直在使用email_spec gem检查电子邮件的内容。某些'和'someone@email.com“应该接收电子邮件的步骤。当我使用rack_test驱动程序运行测试时,它们没有问题。但是,使用selenium驱动程序时它们会失败:
And "someone@email.com" should receive an email
expected: 1
got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)
你能帮帮我吗?感谢
答案 0 :(得分:2)
您必须将电子邮件放入文件中,因为默认情况下,test environemnt中的rails将它们保存在无法从测试线程访问的静态变量中。如果你在黄瓜环境中使用rails3 set delivery方法到:file
。如果你在轨道上2.x将它放入你的黄瓜初始化器中:
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