Ah yes absolutely that was the cause. When you define methods outside of an RSpec describe (which creates a class) you are defining methods on `main`. So essentially you overwrote your method definition when you loaded all the specs and its just luck which one was active.
Glad you solved it! Cheers Jon Rowe --------------------------- [email protected] jonrowe.co.uk On 24 October 2018 at 08:31, belgoros wrote: > On Wednesday, 24 October 2018 09:13:39 UTC+2, belgoros wrote: > > > > > > On Wednesday, 24 October 2018 09:04:51 UTC+2, belgoros wrote: > > > > > > > > > On Tuesday, 23 October 2018 21:52:38 UTC+2, Jon Rowe wrote: > > > > Its looks like your doubles are some how leaking between examples, I’d > > > > wager its something to do with your service injector but I’m unsure > > > > without a proper example. > > > > > > > > Cheers > > > > Jon Rowe > > > > > > > > > > > > > > > > > > > > > > > > > I think the problem comes from #successful_response method, - I checked > > > and discovered that I had 2 ones in different specs, both are declared > > > outside of main RSpec.describe block like that: > > > > > > #spec_one_spec.rb > > > > > > RSpec.describe 'SpecOne' do > > > ...# some examples > > > end > > > > > > def successful_response > > > double(:response, code: 200) > > > end > > > > > > > > > #spec_two_spec.rb > > > > > > RSpec.describe 'SpecTwo' do > > > ...# some examples > > > > > > end > > > > > > def successful_response > > > double(:response, code: 200, body: '[{"sport_id": 1, "label": "sport-1"}, > > > {"sport_id": 2, "label": "sport-2"}]') > > > end > > > > > > > > > > > > What is the rule of thumb to declare such a kind of helper methods ? > > > Should we put them inside the main RSpec.describe block, outside, make > > > them private ? > > > > > > Cheers > > > > I moved the above methods inside the main RSpec.describe block and all the > > tests passed. So should we always keep them there or there is another best > > practice ? > > Thank you. > > > > > > > I re-opened the Effective Testing with RSpec-3 book by Myron Marston & Ian > Dees, and on page 11 you can already find the explanation: > > Each example group is a Ruby class, which means that we can define methods on > it. Right after the describe line, add the following code.... > > > def sandwich > > > Sandwich.new (http://Sandwich.new)('delicious', []) > > > end > > > > > > > So I refactored all the examples to fix that. Hope this helps. > > > > > > > > -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/dejalu-192-ec718996-7841-4b45-a3dd-3db9c2fee0a2%40jonrowe.co.uk. For more options, visit https://groups.google.com/d/optout.
