我用 FactoryGril 生成 2 个 User 然后每个有 3 个 event
let (:user) {FactoryGirl.create :user,:with_events}
let (:user1) {FactoryGirl.create :user,:with_events}
但是测试生成的 events 数量的时候应该生成 6 个却是 3 个
Failure/Error: expect(json["events"].count).to eq 6
expected: 6
got: 3
(compared using ==)
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
谢啦!