[rspec-users] cucumber - when to stub/mock
bkocik at gmail.com
Tue May 5 13:31:25 EDT 2009
My absolute favorite solution for this:
I use that in an application I'm building that uses Twitter's OAuth,
and otherwise heavily uses the Twitter API. It allows me to easily
fake out all of Twitter's responses so I can do
unit/integration/acceptance tests (with Cucumber and WebRat for the
latter) without touching the network.
As a matter of good practice, I always do this first:
FakeWeb.allow_net_connect = false
That ensures that any outbound HTTP requests that I forgot to fake out
will cause FakeWeb to blow up in my face and let me know that I've
missed something rather than silently letting it go by.
On Tue, May 5, 2009 at 12:34 PM, Pat Maddox <pat.maddox at gmail.com> wrote:
> Don't mock the Geolp library directly. Wrap it with an API that fits
> your domain better. Then write a very simple object that implements
> the same API but doesn't hit the network. You can use a switch
> somewhere in env.rb to use your fake implementation or the Geolp one.
> On Sunday, May 3, 2009, Matthew Van Horn <mattvanhorn at gmail.com> wrote:
>> I'm just curious about this, since my solution involved stubbing a call to GeoIp.
>> Is there a good rule of thumb for when you make exceptions to the 'no stubbing' philosophy of Cucumber?
>> My step was: "Given I am accessing the site from Japan," but I can think of other situations - mostly when interacting with web services, that I'd probably want to stub something, rather than requiring a net connection for testing.
>> thanks for any advice,
>> Matt Van Horn
>> rspec-users mailing list
>> rspec-users at rubyforge.org
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users