ruby on rails - How to configure factories with complicated dependencies -


i can test work poor rspec design. i'm trying move dependencies in factories it's not working. can't figure out way both have data_service available call in test, , have automatically created data_service_owner factory.

here's spec file:

describe foo    shared_context "notify"     let!(:subscriber) { factorygirl.create(:subscriber) }     let!(:foo) { factorygirl.create(:foo) }     let!(:message) { factorygirl.create(:message) }     let!(:bar) { factorygirl.create(:bar) }   end    describe "#notify(subscriber)"   include_context "notify"      "notifies bars"       bar.foo = foo #shouldn't have       bar.save #shouldn't have       expect { foo.notify_on_subscribe(subscriber) }.to change { notification.all.count }.by(1)     end end 

i've tested of individual factories successfully. here data_service_owner factory:

factory :bar     boolean_attr true     employee     foo #if put factorygirl.create(:foo) here, not associated same foo object defined in let! statement   end 

thanks.

you should able associate in let block doing like

let!(:bar) { factorygirl.create(:bar, foo: foo) } 

and should associate foo you'd created above


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -