two expectations for a controller action

7 views
Skip to first unread message

Matthew Vincent

unread,
May 21, 2015, 12:50:42 PM5/21/15
to rs...@googlegroups.com
I'm trying to setup the best way to setup several expectations against a controller action. Everything I'm running across seems to suggest that this should be working, but only the first expectation will pass. If I switch the order, it doesn't matter, it is always the first one that passes. I'm sure I'm missing something obvious at this point and I need a second pair of eyes to help me. Any thoughts?



subject(:post_image) { -> { post :create, location_id: location.id, reconstruction_id: reconstruction.id, image: {image: Rack::Test::UploadedFile.new(Rails.root.join('spec', 'fixtures', 'files', 'test1500white.png'), 'image/png') } } }

it { is_expected.to change(Image, :count).by(1) }
it { is_expected.to change(AssetRelation, :count).by(1) }

Myron Marston

unread,
May 21, 2015, 1:12:19 PM5/21/15
to rs...@googlegroups.com
There's nothing obviously wrong from the snippet you posted.  My best guess is that it has to do with the state change not being fully reset between examples.  For example, if your DB isn't being rolled back or cleaned out between examples, it could allow the first example to pass but could cause the second example to fail due to data left around from the first example.

If you're able to put together a reproducible example so we can play with it, we can help more, but without that, we can only guess as to the problem.

HTH,
Myron

Matthew Vincent

unread,
May 21, 2015, 1:22:26 PM5/21/15
to rs...@googlegroups.com
Thanks Myron, I've been talking it out with a couple friends and we've come up with the strange conclusion. I'm going to try and uncomplicate some of my models a bit more here and re-approach this. It does help to know that, at leas theoretically, this is setup in what should be the right way. If I am still facing this same problem, I'll come back with more code... otherwise hopefully this was just me stumbling in the dark for a little while.

Thanks!
Reply all
Reply to author
Forward
0 new messages