当我在代码中遇到错误时,我遇到了如何让我的设计密码重置测试正常工作的问题:
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>