stubbing network calls

View: New views
3 Messages — Rating Filter:   Alert me  

stubbing network calls

by David Green :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a couple of methods which make networks calls. Where's the best place to stub them so they are stubbed for every description automatically? I tried in spec_helper.rb but they are no longer stubbed when a spec runs.

at the moment, I'm checking for the test environment in the methods themselves, and returning a dummy value, but I'm sure there's a better way.


Re: stubbing network calls

by Aslak Hellesoy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 8/22/07, David Green <justnothing@...> wrote:
>
> I have a couple of methods which make networks calls. Where's the best place
> to stub them so they are stubbed for every description automatically? I
> tried in spec_helper.rb but they are no longer stubbed when a spec runs.
>
> at the moment, I'm checking for the test environment in the methods
> themselves, and returning a dummy value, but I'm sure there's a better way.
>

Instead of stubbing methods on Socket (or whatever network class
you're using) I would design the client of the "network" class in such
a way that you can pass in whatever. The dependency injection
technique. Then you just pass it a mock.

Aslak

>
> --
> View this message in context: http://www.nabble.com/stubbing-network-calls-tf4312869.html#a12279004
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: stubbing network calls

by David Green :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 8/22/07, David Green <justnothing@tiscali.co.uk> wrote:
>
> I have a couple of methods which make networks calls. Where's the best place
> to stub them so they are stubbed for every description automatically? I
> tried in spec_helper.rb but they are no longer stubbed when a spec runs.
>
> at the moment, I'm checking for the test environment in the methods
> themselves, and returning a dummy value, but I'm sure there's a better way.
>

Instead of stubbing methods on Socket (or whatever network class
you're using) I would design the client of the "network" class in such
a way that you can pass in whatever. The dependency injection
technique. Then you just pass it a mock.

Aslak

thanks for the suggestion. I'd still need to do this every place there's a call to a network method right? My problem is the methods are used extensively. One is a before_filter so it's easy to stub. The other is in a general purpose class which various models and controllers use, i was hoping there would be one central place where I could stub that out