可以来给我解释一下为什么必须使用let!而不是在这种情况下让?仅当我包含 ! 时测试才通过。我以为我理解 let 会在该块中的每个“it”语句之前自动执行,但显然情况并非如此。
describe Artist do
before do
@artist = Artist.new(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { @artist }
describe "virtual requests" do
let!(:virtual1) { FactoryGirl.create(:virtual_request, artist: @artist ) }
let!(:virtual2) { FactoryGirl.create(:virtual_request, artist: @artist ) }
it "should be multiple" do
@artist.virtual_requests.count.should == 2
end
end
end