2009/2/8 Sergio Bayona <li...@ruby-forum.com> > 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? and why would the assigns[:property] be equal to > mock_property?
Because that's what you're saying with your and_return call above. The and_return method is not part of the expectation: it allows you to specify what value you want to be returned each time the expected message is received. You can find more info at http://rspec.info/documentation/mocks/message_expectations.html. Regards, Matías A. Flores > did I eat some bad mushrooms? > > Sergio > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users