On Sun, Feb 8, 2009 at 7:35 PM, 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)
* should_receive does not care if the object actually responds to the method - if you tell the object to expect it, it will respond to it * and_return is a declaration of a stub value to return when the object receives the message that it should receive Put that together, and this line says exactly what it looks like it says: The Property class should receive :non_existing_method, and when it does, it should return mock_property to whatever code is calling it. That make any sense now? > 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? 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