2016-06-17 17 views
1

で開かれた私は、キュウリとカピバラを使用して、いくつかのQAの自動化に取り組んでステップを持っています:がletter_opener宝石

When(/^I follow the reset password link in the email$/) do 
    last_email = ActionMailer::Base.deliveries.last 
    password_reset_url = last_email.body.match(/http.*\/users\/password\/edit.*$/) 
    visit password_reset_url 
end 

ステップがで失敗します。また

undefined method `body' for nil:NilClass (NoMethodError) 

、最初の行の後にbinding.pryを削除すると、last_emailの場合はnilになり、これは変です。

ここで起こっている理由についてアドバイスや考えがありますか?

+0

解決策を見つけましたか? –

答えて

3

letter_openerを使用している場合、電子メールはActionMailer配信には向かず、Capybaraが管理していないブラウザで開かれています。カピバラで電子メールを扱う場合は、letter_openerではなくcapybara-emailの宝石を見てください。 Letter_openerは、テストではなく開発環境をもっと目指しています。

0

Tom Walpole's answerは絶対に正しい内容であり、capybara-email gemの方向に向いています。

ここでは、パスワードのリセット命令を送信するボタン/リンクをクリックした別のキュウリのステップ持っていると仮定して、あなたのコードサンプルを変更することができる方法の潜在的な例です:あなたは、リンクをクリックした後

When(/^I follow the reset password link in the email (.*)$/) do |email| 
    # finds the last email sent to the passed in email address. 
    # This also sets the `current_email` object, which you can think 
    # of as similar to Capybara's `page` object, but for an email. 
    open_email(email) 
    # Assuming the email link to change your password is called 
    # 'Change my password', you can just click it, just as you would 
    # on a Capybara `page`. 
    current_email.click_link 'Change my password' 
end 

pageに行き、そこでfill_in 'New password', with: 'foobar'などに進むことができます。これは別のキュウリのステップでカバーされていると仮定しています。