Forum: RSpec how to mock a Net::Http object?

Posted by Zhenning Guan (rubyernewbie)
on 2010-03-02 09:39
one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' =>
"american"})
two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' =>
"english"})

I have a code similar like above code in my application, so how to mock
a a object like above? if only post_from once, I just need to stub
post_form, but now, it has different parameter, how to do it?

Net::HTTP.stub!(:post_form).and_return('my_data')
Posted by Aslak Hellesøy (aslakhellesoy)
on 2010-03-02 09:52
(Received via mailing list)
On Tue, Mar 2, 2010 at 9:39 AM, Zhenning Guan <lists@ruby-forum.com> 
wrote:

> one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' =>
> "american"})
> two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' =>
> "english"})
>
> I have a code similar like above code in my application, so how to mock
> a a object like above? if only post_from once, I just need to stub
> post_form, but now, it has different parameter, how to do it?
>
>
http://github.com/blaine/fakeweb

Aslak
Posted by Bartosz Blimke (bartoszblimke)
on 2010-03-19 00:02
You can also use WebMock http://github.com/bblimke/webmock
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.