Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
stubbing after_create
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
fearless_fool  
View profile  
 More options Feb 1 2011, 7:41 pm
From: fearless_fool <rdp...@gmail.com>
Date: Tue, 1 Feb 2011 16:41:39 -0800 (PST)
Local: Tues, Feb 1 2011 7:41 pm
Subject: stubbing after_create
You could argue that it's a bad idea, but I've created a model that
accesses the web in its after_create method:

  class Premise < ActiveRecord::Base
    after_create :lookup_elevation
    ...
    def lookup_elevation
      (call google elevation service via Mechanize)
    end
    ...
  end

Of course, this immediately broke all of my RSpec tests, since
creating a Premise (even via FactoryGirl) will call lookup_elevation
which raises a WebMock::NetConnectNotAllowedError.

Is there a simple way to create a global stub?  Or do I have to
sprinkle webmock stubs throughout my RSpec tests?  (The latter would
make me sad, since it doesn't seem right to be stubbing web access in
tests that have nothing to to with accessing the web.)

TIA.

- ff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bartosz Blimke  
View profile  
 More options Feb 1 2011, 8:02 pm
From: Bartosz Blimke <bartosz.bli...@gmail.com>
Date: Wed, 2 Feb 2011 01:02:33 +0000
Local: Tues, Feb 1 2011 8:02 pm
Subject: Re: stubbing after_create

What about declaring the stub in a spec_helper.rb ?

Rspec.configure do |config|
  config.before :each do
    stub_request(.....)
  end
end

Bartosz

2011/2/2 fearless_fool <rdp...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fearless_fool  
View profile  
 More options Feb 5 2011, 7:16 pm
From: fearless_fool <rdp...@gmail.com>
Date: Sat, 5 Feb 2011 16:16:10 -0800 (PST)
Local: Sat, Feb 5 2011 7:16 pm
Subject: Re: stubbing after_create
On Feb 1, 5:02 pm, Bartosz Blimke <bartosz.bli...@gmail.com> wrote:

> What about declaring the stub in a spec_helper.rb ?

> Rspec.configure do |config|
>   config.before :each do
>     stub_request(.....)
>   end
> end

> Bartosz

Ah - perfect! I didn't know you could declare a stub like that.  (Uh,
can you point me to documentation for Rpec.configure ... ?)

Thanks.

- ff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »