Forum: RSpec Warning (but not failing) if a method wasn't called?

74283a8aa16c958f3d48d41d96c99577?d=identicon&s=25 John Feminella (Guest)
on 2011-09-07 15:27
(Received via mailing list)
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/
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 Justin Ko (Guest)
on 2011-09-07 16:04
(Received via mailing list)
On Wed, Sep 7, 2011 at 6:08 AM, John Feminella
<johnf@bitsbuilder.com>wrote:

>    Geocoding.warn_if_not_received(:client).and_return(@geocoding_client)
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


Why would you want a warn? I can't get my head around this.
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2011-09-07 16:36
(Received via mailing list)
On Sep 7, 2011, at 7:08 AM, John Feminella wrote:

>    Geocoding.warn_if_not_received(:client).and_return(@geocoding_client)
>  end
> end

There'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
This topic is locked and can not be replied to.