You can do it manually:
test_case = FactoryGirl.build(:test_case) test = FactoryGirl.build(:test_data_value, :test_variable => FactoryGirl.build(:test_variable, :test_case => test_case ), :test_data_set => FactoryGirl.build(:test_data_set, :test_data_grid => FactoryGirl.build(:test_data_grid, :test_case => test_case ) ) ) test.test_variable.test_case == test.test_data_set.test_data_grid.test_case
Or write an auxiliary factory:
FactoryGirl.define do factory :test_data_value do ignore do test_case nil test_data_grid nil end test_variable do build :test_variable, :test_case => test_case || test_data_grid.try(:test_case) || build(:test_case) end test_data_set do build :test_data_set, :test_data_grid => test_data_grid || ( build :test_data_grid, :test_case => test_case || build(:test_case) ) end end end
Test version as a common ancestor:
test = FactoryGirl.create :test_data_value, :test_case => FactoryGirl.build(:test_case) test.test_variable.test_case == test.test_data_set.test_data_grid.test_case
Test case as a common ancestor and the same test_data_grid for each instance:
test_data_grid = FactoryGirl.build :test_data_grid, :test_case => FactoryGirl.build(:test_case) test = FactoryGirl.create :test_data_value, :test_data_grid => test_data_grid test.test_variable.test_case == test.test_data_set.test_data_grid.test_case
source share