Ruby on rails 针对远程主机测试ActionMailer交付

Ruby on rails 针对远程主机测试ActionMailer交付,ruby-on-rails,cucumber,capybara,actionmailer,Ruby On Rails,Cucumber,Capybara,Actionmailer,所以我有一个简单的场景,新注册的用户必须经过管理员的批准。批准后,他们会收到邮件通知。然而,测试在最后一步失败。这是一个理由: @javascript Scenario: approving users Given user exists with email: "user@site.com", approved: false And I am on the admin panel When I approve the user user@site.com Then user

所以我有一个简单的场景,新注册的用户必须经过管理员的批准。批准后,他们会收到邮件通知。然而,测试在最后一步失败。这是一个理由:

@javascript
Scenario: approving users
  Given user exists with email: "user@site.com", approved: false
    And I am on the admin panel
  When I approve the user user@site.com
  Then user should exist with email: "user@site.com", approved: true
    And the page should have no "approve" items
    And an email should have been sent to "user@site.com" with the subject "user_mailer.notify_approved.subject"
步骤定义(它的)尝试在ActionMailer deliveries中查找邮件,但找不到

导致测试失败的原因是,在我的测试设置中,我告诉Capybara不要运行服务器实例,而是连接到远程服务器(使用自签名证书的Thin)。以下是设置:

config.use_transactional_fixtures = false

config.include Devise::TestHelpers, type: :controller
config.include FactoryGirl::Syntax::Methods

config.before(:suite) do
  DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
  DatabaseCleaner.start
end

config.after(:each) do
  DatabaseCleaner.clean
end

# have to run the test env server separately, e.g. with thin:
# thin start -p 5678 --ssl -e test
Capybara.configure do |c|
  c.run_server = false
  c.server_port = 5678
  c.app_host = "https://localhost:%d" % c.server_port
end
邮件显然丢失了,因为邮件是从远程测试服务器发送的,由Capybara单击approve链接触发:

When /^I approve the user (.*?)$/ do |email|
  page.find(:xpath, "//tr[descendant::a[text()='#{email}']]/td[@class='actions']//li[@class='approve']/a").click
end

所以问题是,在这种情况下,是否有办法判断邮件是否真的送达了。我可以想到的一种方法是扩展上面的步骤,同时在本地更新相应的用户实例,该实例将在本地执行相同的代码,但这似乎有味道。不使用SSL可能是另一个w/a,但我真的应该使用https。还有其他选择吗

好吧,既然没有答案,下面是我如何解决的:

When /^I approve the user (.*?)$/ do |email|
  page.find(:xpath, "//tr[descendant::a[text()='#{email}']]/td[@class='actions']//li[@class='approve']/a").click

  u = User.find_by_email(email)
  u.approved = true
  u.save
end
添加的三行确保邮件通知回调也在本地触发