有人可以帮我找出标记为#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
不会导致范围问题返回一些内容 - Proc
。
答案 0 :(得分:0)
卫生署。慢我。它在it
块(或before
/ after
块中)时有效:
describe "#more_things" do
User.new.more_things = "#works" #works
subject.more_things = "#causes error" #causes error
it "should work now" do
subject.more_things = "#works now" #works
end
end
我想我应该永远记住它是主题:)