2011-11-22 71 views
3

我运行了一些黄瓜/水豚测试。我一直在使用email_spec gem来检查电子邮件。某些步骤中的“And”[email protected]应该收到一封电子邮件。当我使用rack_test驱动程序运行测试时,它们没有任何问题。黄瓜/水豚/电子邮件规格与Selenium驱动程序无法正常工作

And "[email protected]" should receive an email                 
    expected: 1 
     got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError) 

你能帮我:但是,他们使用硒驱动程序时失败?谢谢

回答

2

你必须把你的电子邮件放到一个文件中,因为默认情况下,测试环境中的rails将它们保存在无法从测试线程访问的静态变量中。如果您在黄瓜环境中使用rails3设置传送方式为: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 
+0

嗨。我在我的黄瓜环境中放置了'config.action_mailer.delivery_method =:file',测试仍然失败。还有什么我应该做的? – sauronnikko

+0

我读过将其设置为':file'将电子邮件保存在'tmp/mails'文件夹中。在发送电子邮件之后(仍在发送,因为我可以在服务器日志中看到它)之后,我进行了调试,我可以看到,不仅没有任何文件,而且文件夹本身也没有。此外,当我使用该传递方法尝试我的rack_test测试时,它们也失败(它们之前没有失败)。这是怎么回事? – sauronnikko