【发布时间】:2013-07-29 17:31:09
【问题描述】:
我在使用 let 的 RSpec 测试中遇到了一个奇怪的行为。我在使用let 时从来没有遇到过问题,这就是为什么这很奇怪。在以下测试中,my_model let 定义返回 nil:
describe '.process' do
let(:my_model){ Fabricate(:my_model) }
it 'doesnt work' do
# my_model returns nil but it should be returning the fabricated model
my_model = Processor.process(my_model)
my_model.special_attribute.should == 'foo'
end
it 'works' do
my_model = Fabricate(:my_model)
# my_model is now correctly fabricated
my_model = Processor.process(my_model)
my_model.special_attribute.should == 'foo'
end
end
为什么会这样?
【问题讨论】:
标签: rspec