我在我的 RSpec 测试中使用let. 我从来没有遇到过使用问题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
为什么会这样?