0

コードでエラーが発生したため、Devise パスワード リセット テストを正しく機能させる方法について問題が発生しています。

require 'spec_helper'

describe "Passwords" do
    describe "Forgot Password" do
        let(:user) { FactoryGirl.create(:user) }
        it 'should reset a users password' do
            reset_mailer
            visit '/'
            click_link 'Sign In'
            fill_in 'Password', :with => 'fakepass'
            fill_in 'Email', :with => user.email
            click_button "Sign in"
            current_path.should == user_session_path
            page.should have_content 'Invalid email or password.'
            click_link 'Forgot your password?'
            current_path.should == new_user_password_path
            page.should have_content 'Forgot Password'
            fill_in 'Email', :with => user.email
            click_button 'Send me password reset instructions'
            current_path.should == user_session_path
            page.should have_content 'You will receive an email'

            last_email.to.should include(user.email)
            open_email(user.email)
            current_email.first(:link, 'Change My password').click

            within('body') do
                page.should have_content 'Change Your Password'
            end

            fill_in "user[password]", :with => "password"
            fill_in "user[password_confirmation]", :with => "password"
            click_button "Change My Password"

            within('body') do
                page.should have_content 'password changed.'
            end

        end
    end
end

私のエラーより:

Passwords Forgot Password should reset a users password
     Failure/Error: last_email.to.should include(user.email)
     NameError:
       undefined local variable or method `last_email' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xb788c18>

なぜこのエラーが発生するのですか? どうすれば修正できますか?

アップデート

features/email_steps.rb

# Commonly used email steps
#
# To add your own steps make a custom_email_steps.rb
# The provided methods are:
#
# last_email_address
# reset_mailer
# open_last_email
# visit_in_email
# unread_emails_for
# mailbox_for
# current_email
# open_email
# read_emails_for
# find_email
#
# General form for email scenarios are:
#   - clear the email queue (done automatically by email_spec)
#   - execute steps that sends an email
#   - check the user received an/no/[0-9] emails
#   - open the email
#   - inspect the email contents
#   - interact with the email (e.g. click links)
#

更新されたコード:

open_last_email.to.should include(user.email)
open_email(user.email)
current_email.first(:link, 'Change My Password').click

Failure/Error: current_email.first(:link, 'Change My Password').click
     NoMethodError:
       undefined method `first' for #<Mail::Message:0xb560dc8>
4

2 に答える 2

0

私はそれを機能させることができました。問題は にありemail_steps.rbます。練習用に既製のアプリケーションを実行しているので、私はそれについて知りませんでした。

私が問題を抱えていたコード領域に関して:

エラーのある私のコードは次のとおりです。

last_email.to.should include(user.email)
open_email(user.email)
current_email.first(:link, 'Change My password').click

テストを通過した新しいコード:

open_last_email.to.should include(user.email)
open_email(user.email)
click_first_link_in_email
于 2013-06-12T14:48:59.393 に答える