How to mock a Net::Http object?

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’)

On Tue, Mar 2, 2010 at 9:39 AM, Zhenning G. [email protected]
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

You can also use WebMock GitHub - bblimke/webmock: Library for stubbing and setting expectations on HTTP requests in Ruby.