有人可以帮我弄清楚为什么标记的行#works
有效,但标记的行#causes error
会导致错误吗?(这是带有 rspec-rails 2.11.0 的 Rails 3.2.6)
错误:undefined method 'more_things=' for #<Proc:0x007fbd23d0b960> (NoMethodError)
规格:
describe User do
subject { User.new }
it "has no something" do
User.new.more_things = "#works" #works
subject.something.should be_empty #works
end
describe "#more_things" do
User.new.more_things = "#works" #works
subject.more_things = "#causes error" #causes error
end
end
模型:
class User
def something
[]
end
def more_things=(value)
end
end
我试着把另一个subject { User.new }
放在里面describe "#more_things" do
,认为它可能是某种范围问题,但这没有帮助(这不是范围问题,因为subject
确实返回了一些东西 - a Proc
.