3

I'm pretty new to rspec so I'm not sure how to word this properly so I'll give an example of my situation instead:

subject(:test) { SomeModel.create(name: name, depend: depend) }
let(:name){ "test name" }
let(:depend){ create(:depend, //something here with id of creation of SomeModel) }

Depend belongs to SomeModel and so I need the id of SomeModel to create Depend. Is there some way of retrieving the id of the SomeModel I created in the first line? Sorry if this is very unclear as I'm not too sure how to word it.

5
  • 2
    subject.id or test.id Nov 28, 2017 at 7:13
  • How this question got two upvotes? Flagged for mod’s attention on who’s upvoted. Nov 28, 2017 at 7:19
  • @mudasobwa: if there was a voting ring, this user's rep would have been higher :) Nov 28, 2017 at 7:22
  • @SergioTulentsev not necessarily, it might be a slave asking dumb questions that yield the attention because of upvotes. Nov 28, 2017 at 7:23
  • @mudasobwa sorry if it seemed like too dumb of a question -- turns out I was doing the right thing but because I was still getting an error I thought I was doing something wrong when trying to reference the subject. Turns out something else is wrong with my factories, thanks anyway for the help :)
    – E. Jel
    Nov 28, 2017 at 7:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.