开发者

rspec if giving a NoMethodError for Updating a User.field

Why does:

User.stuff_to_extract = 'boo'

work in the rails c

But in rspec it fails with this:

 Failure/Error: @user1.stuff_to_extract = 'XXXXXX'
 NoMethodError:
   undefined method `stuff_to_extract=' for #<User:0x105cd4e60>



require 'factory_girl'

Factory.define :user do |f|
  f.sequence(:fname) { |n| "fname#{n}" }
  f.sequence(:lname) { |n| "lname#{n}" }
  f.sequence(:email) { |n| "email#{n}@google.com" }
  f.password      开发者_如何学JAVA         "password"
  f.password_confirmation { |u| u.password }
  f.invitation_code        "xxxxxxx"
  f.email_signature_to_extract        ""
end


In the first case you are calling the method on the User class. In the second you are calling it on a User instance. To fix the second example use:

User.stuff_to_extract = 'XXXXXX'

or redefine your function to be available to the instance:

class User
  def stuff_to_extract= stuff
    ...
  end
end

instead of being available to the class:

class User
  def self.stuff_to_extract= stuff
    ...
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜