所以我有一个简单的场景,新注册的用户必须得到管理员的批准。 经批准后,他们会收到邮件通知。 然而,测试在最后一步失败了。 这是cuke:
@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交付中查找邮件,但无法找到它。
使测试失败的原因是,在我的测试设置中,我告诉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点击批准链接触发:
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。 还有其他选择吗?
So I have a simple scenario where a newly registered user must be approved by an admin. Upon approval, they receive a mail notification. The test, however, fails at the last step. Here's the cuke:
@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"The step definition (it's here) tries to look up the mail in ActionMailer deliveries and can't find it.
What makes the test fail is that in my test setup, I tell Capybara not to run a server instance but connect to a remote server (Thin with a self-signed cert). Here's the setup:
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 endThe delivery is missing apparently because the mail is sent from the remote test server, triggered by Capybara clicking an approve link:
When /^I approve the user (.*?)$/ do |email| page.find(:xpath, "//tr[descendant::a[text()='#{email}']]/td[@class='actions']//li[@class='approve']/a").click endSo the question is if there is a way to somehow tell if the mail really got delivered in this scenario. One way I can think of is extend the step above to also update the corresponding user instance locally which would execute the same code locally, but that seems to smell. Not using SSL could be another w/a, but I should really run over https. Are there any other options?
最满意答案
好的,因为缺乏答案,这就是我如何解决它:
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添加的三行确保邮件通知回调也在本地触发。
OK so for the lack of an answer, here's how I solved it:
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 endThe three lines added ensure the mail notification callback is also triggered locally.
更多推荐
发布评论