John Feminella
2011-Sep-07 12:08 UTC
[rspec-users] Warning (but not failing) if a method wasn''t called?
Is there a way to warn but not fail if a particular method wasn''t called? That is, I''m looking for something that''s halfway between obj.stub(...) and obj.should_receive(...). I''m trying to do something like this: shared_context "with a stubbed geocoder" do before(:each) do @geocoding_client = Geocoding::FakeGeoClient.new # generate warning if the spec doesn''t cause a hit to Geocoding.client Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) end end ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/
Justin Ko
2011-Sep-07 13:34 UTC
[rspec-users] Warning (but not failing) if a method wasn''t called?
On Wed, Sep 7, 2011 at 6:08 AM, John Feminella <johnf at bitsbuilder.com>wrote:> Is there a way to warn but not fail if a particular method wasn''t > called? That is, I''m looking for something that''s halfway between > obj.stub(...) and obj.should_receive(...). I''m trying to do something > like this: > > shared_context "with a stubbed geocoder" do > before(:each) do > @geocoding_client = Geocoding::FakeGeoClient.new > > # generate warning if the spec doesn''t cause a hit to Geocoding.client > Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) > end > end > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersWhy would you want a warn? I can''t get my head around this. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110907/cbd0cba7/attachment.html>
David Chelimsky
2011-Sep-07 13:51 UTC
[rspec-users] Warning (but not failing) if a method wasn''t called?
On Sep 7, 2011, at 7:08 AM, John Feminella wrote:> Is there a way to warn but not fail if a particular method wasn''t > called? That is, I''m looking for something that''s halfway between > obj.stub(...) and obj.should_receive(...). I''m trying to do something > like this: > > shared_context "with a stubbed geocoder" do > before(:each) do > @geocoding_client = Geocoding::FakeGeoClient.new > > # generate warning if the spec doesn''t cause a hit to Geocoding.client > Geocoding.warn_if_not_received(:client).and_return(@geocoding_client) > end > endThere''s no support for this in rspec-mocks. You can do the following, but I would not recommend it: before do @geocoding_received_client = false Geocoding.stub(:client) do @geocoding_received_client = true @geocoding_client end end after do warn "Geocoding did not receive :client" unless @@geocoding_received_client end Cheers, David