rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 358 forks source link

should_receive different behaviour in Sinatra and Rails #187

Closed HoneyryderChuck closed 12 years ago

HoneyryderChuck commented 12 years ago

Hi,

consider two AR models, in which one has an has_many association to the other. I wrote the following spec and let it run in two different applications, one in Sinatra and one Rails, which are sharing the same models implementations (I'm currently using factory_girl for fixture generation, I don't know if the info is relevant):


describe Iceman do
  describe "dummy test" do
    subject{ build_stubbed(:iceman) }
    let(:icecreams) { subject.icecreams }
    it "should not raise exception" do
      icecreams.should_receive(:create).once
      icecreams.create(:flavour => "vanilla")
    end
  end
end

This bit works in Rails. It doesn't in Sinatra. Basically the expectation was not matched (0 instead of 1 times). Anyway, in another side of the code, I also have expectations for the create method set on some collection association of a stubbed model. In Rails, it works fine. In Sinatra, the AR Exception is raised (that I cannot create associated models when the parent is not saved). So, in Rails, the expectation ate the raised Exception, which was the right behaviour. In Sinatra, it didn't. I would like to know which component is handling the exception, assuming the rspec mocks are not responsible for it.

Regards

myronmarston commented 12 years ago

There's nothing here that suggests to me that it's an RSpec issue. It sounds like an ActiveRecord/Sinatra integration problem.

We use github issues for demonstrable bugs and feature requests, but there's nothing actionable we can do here for you. Please use stackoverflow or one of the mailing lists (rails, sinatra, rspec) to ask for help with general questions like this.

If you're able to isolate a reproducible example that demonstrates a problem with RSpec, we can re-open and address the RSpec issue, but for now I'm going to close this.

Good luck!

HoneyryderChuck commented 12 years ago

Well, I think it does. If I remove the expectation from both tests, both respond correctly by throwing the exception. Just when the expectation is there, on one example it "silences" the exception, and it doesn't do that on the other. But ok, I'll try getting an answer in stack overflow.