capybara-email: open_email does not appear to work

    background do
      recipient_user = double()
      recipient_user.stub(:name) {'Ash Williams'}
      recipient_user.stub(:email) {'theKing@email.com'}

      message = mock_model( Message, 
        recipient: recipient_user
      )

      Mailer.sponsored_challenge_promotion(message).deliver!
      open_email('theKing@email.com')

    end

    scenario 'should say hello to the user' do
      current_email.should have_content "Hello, Ash"
    end

in this scenario, both open_email and current_email return nil

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 21 (1 by maintainers)

Most upvoted comments

From @ghost’s comment back in 2015, you may get an “undefined” error if you are trying to use the library in an email spec test. The DSL is not included by default in these tests. To include them, add

include Capybara::Email::DSL

to the top of the email spec.

I was able to access the email by passing the action that sends the email to perform_enqueued_jobs. My test looks like

scenario "User requests password reset" do
  visit "/forgot_password"
  fill_in "Email", with: email

  perform_enqueued_jobs do
    click_button "Reset Password"
  end

  open_email(email)
  current_email.click_link "reset your password here"

  fill_in "Password", with: new_password
  click_button "Set Password"

  expect(current_path).to eq "/user"
end

Hope this helps.

@joethrive Make sure you follow the setup guide for capybara-email: https://github.com/DavyJonesLocker/capybara-email#setting-your-test-host

Also, you might need to set your job queue adapter to inline for testing. config/environments/test.rb: config.active_job.queue_adapter = :inline