模型上的 rspec 和未定义方法 [英] rspec and undefined method on model

查看:50
本文介绍了模型上的 rspec 和未定义方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照集成测试中的 railscasts 进行操作,并且正在测试密码重置 url.我遇到了 NoMethodError 问题,我不确定发生了什么.

I'm trying to follow the railscasts on Integration Testing and am testing a password reset url. I am having a problem with NoMethodError and am not sure what is going on.

我有一个用户模型,它有一个 forgot_password 值,它只是一个哈希值,将通过电子邮件发送出去.

I have a user model that has a forgot_password value which is just a hash that will be emailed out.

这似乎有效

ruby-1.9.2-p290 :001 > u=User.find(1)
...
ruby-1.9.2-p290 :002 > u.forgot_password
 => "1280aceaf23f185a2d09a57b5534e7e3"

但我收到以下错误:

1) PasswordResets emails user when requesting password reset
   Failure/Error: click_button "jt"
   NoMethodError:
     undefined method `forgot_password=' for #<User:0x007ff916b03da0>
   # /Users/jt/rails-1/app/controllers/users_controller.rb:61:in `forgot_password_confirmation'
   # (eval):2:in `click_button'

这里是规范:

需要'spec_helper'

require 'spec_helper'

describe "PasswordResets" do
  it "emails user when requesting password reset" do
    user=Factory(:user)
    visit log_in_path
    click_link "password"
    fill_in "email", :with => user.email
    click_button "jt"
  end
end

NoMethodError 告诉我什么?看起来好像在 rails c 中,forgot_password 值存在.我错过了什么?

What does the the NoMethodError tell me? It looks as if from rails c, the forgot_password value exists. What am I missing?

谢谢

推荐答案

仅供未来搜索者使用:

当您看到类似 "attributename=" 的无方法错误时 -- 但您知道 active-record 正在将该 attr_accessor 添加到模型中,您应该确保您已运行:

When you see a no-method error with something like "attributename=" -- but you know active-record is adding that attr_accessor to the model, you should make sure you've run:

rake db:test:prepare

在您迁移之后.不能说这让我受了多少次!

After your migration. Can't say how many times this has got me!

这篇关于模型上的 rspec 和未定义方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆