5

我在 Cucumber 中有一个分配给我的故事列表,其中一个是“然后用户应该收到一封确认电子邮件”。我认为测试用户是否收到它超出了应用程序的能力,但我如何测试一封电子邮件是否刚刚发送?

4

5 回答 5

7

您可以使用此步骤定义:

Then "the user should receive a confirmation email" do
  # this will get the first email, so we can check the email headers and body.
  email = ActionMailer::Base.deliveries.first
  email.from.should == "admin@example.com"
  email.to.should == @user.email
  email.body.should include("some key word or something....")
end

使用 Rails 3.2 测试

资源

于 2013-04-02T00:50:22.150 回答
2

email_spec + action_mailer_cache_delivery gems 是你这样做的朋友

于 2014-08-15T10:13:48.980 回答
0

检查造船厂/水豚电子邮件gem:

feature 'Emailer' do
  background do
    # will clear the message queue
    clear_emails
    visit email_trigger_path
    # Will find an email sent to test@example.com
    # and set `current_email`
    open_email('test@example.com')
  end

  scenario 'following a link' do
    current_email.click_link 'your profile'
    expect(page).to have_content 'Profile page'
  end

  scenario 'testing for content' do
    expect(current_email).to have_content 'Hello Joe!'
  end

  scenario 'testing for a custom header' do
    expect(current_email.headers).to include 'header-key'
  end

  scenario 'testing for a custom header value' do
    expect(current_email.header('header-key')).to eq 'header_value'
  end

  scenario 'view the email body in your browser' do
    # the `launchy` gem is required
    current_email.save_and_open
  end
end
于 2015-01-27T08:37:43.217 回答
0

我建议您last_response在某些操作发生后进行验证,例如用户单击按钮或类似的操作。

或者,如果您在执行某项操作后更新记录,请检查updated_at属性以查看它是否已更改。

于 2013-02-06T18:24:52.707 回答
0

另一种选择是PutsBox。您可以发送电子邮件到whatever-you-want@putsbox.com,等待几秒钟(SMTP 内容不是即时的),然后通过http://preview.putsbox.com/p/whatever-you-检查您的电子邮件想要/最后

这个帖子教程有一些例子。

于 2015-08-06T12:14:39.573 回答