Reputation: 16159
I use FactoryGril created two users, both with 3 events:
let (:user) {FactoryGirl.create :user,:with_events}
let (:user1) {FactoryGirl.create :user,:with_events}
But i get all events count 6, but i got 3,
Failure/Error: expect(json["events"].count).to eq 6
expected: 6
got: 3
(compared using ==)
Thanks!
Factories.rb
FactoryGirl.define do |f|
factory :user do
password "123123"
sequence(:name){|n| "张三#{n}" }
end
factory :event do
end_date "2015-05-30"
is_countdown "1"
end
trait :with_events do
after :create do |user|
FactoryGirl.create_list :event, 3, :user => user
end
end
end
Upvotes: 1
Views: 406
Reputation: 16159
Note that let is lazy-evaluated: it is not evaluated until the first time
the method it defines is invoked. You can use let! to force the method's
invocation before each example.
Change let!
replace let
make it!
Upvotes: 1