On Mon, Feb 9, 2009 at 2:35 AM, Sergio Bayona <li...@ruby-forum.com> wrote: > how could this test pass? > > I have: > > class PropertiesController < ApplicationController > def show > @property = Property.non_existing_method #causes a method missing > error > end > end > > > describe PropertiesController do > def mock_property(stubs={}) > @mock_property ||= mock_model(Property, stubs) > end > > describe "responding to GET show" do > it "should expose the requested property as @property" do > Property.should_receive(:non_existing_method).and_return(mock_property) > get :show, :id => "37" > assigns[:property].should equal(mock_property) > end > end > end > > SB-MacBook-Pro:test sb$ ruby > ./spec/controllers/properties_controller_spec.rb > . > > Finished in 0.134667 seconds > > 1 example, 0 failures > > > why zero failures? more specifically, why would :non_existing_method > return mock_property?
Because you have stubbed the class method Property#non_existing_method with: Property.should_receive(:non_existing_method).and_return(mock_property) It doesn't make any difference whether this method is already defined or not. Once the stub is set up, calls to the stubbed method will return what you told it to return. > and why would the assigns[:property] be equal to > mock_property? Because your controller's #show method assigns @property with the value returned from Property#non_existing_method (which you stubbed). > did I eat some bad mushrooms? > That I don't know. Why do you think this behaviour is strange/hallucinating? Aslak > Sergio > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Aslak (::) _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users