Rspec 未定义的局部变量或方法;最后一封电子邮件;

Rspec 未定义的局部变量或方法;最后一封电子邮件;,rspec,devise,ruby-on-rails-3.2,capybara,Rspec,Devise,Ruby On Rails 3.2,Capybara,当我在代码中遇到错误时,我遇到了如何使Desive密码重置测试正常工作的问题: require 'spec_helper' describe "Passwords" do describe "Forgot Password" do let(:user) { FactoryGirl.create(:user) } it 'should reset a users password' do reset_mailer

当我在代码中遇到错误时,我遇到了如何使Desive密码重置测试正常工作的问题:

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>
更新代码:

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>
open\u last\u email.to.应包括(user.email)
打开电子邮件(user.email)
当前电子邮件。首先(:链接“更改我的密码”)。单击
失败/错误:当前电子邮件。首先(:链接“更改我的密码”)。单击
命名错误:
未定义的方法“first”#

我能让它工作。问题在于
电子邮件\u 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

最后一封电子邮件没有在任何地方定义,但您在这里使用它:
last\u email.to.应该包括(user.email)
@Arjan我应该在哪里定义它?我不知道。这个规范是你自己写的,还是你在什么地方得到的?如果是后者,你能告诉我你从哪里得到的吗。这可能会有帮助。@Arjan我写了大部分,我从这里得到了“电子邮件块”:我明白了,你添加了Desive test_助手了吗?这可能会解决问题。检查
open_last_email.to.should include(user.email)
open_email(user.email)
click_first_link_in_email