I want to mock HTTP POST requests with Mocha. The code to be tested basically looks like
req=Net::HTTP::Post.new "whatever"
connection=Net::HTTP.new( "whatever", 80 )
result=connection.request( req ).body
Now, if this were Java, I’d hack around this class so I could inject some fake HTTPRequest objects and such, and I’d be ok. Is that really the way I have to do it in Ruby, since apparently no one on the entire Internet has ever done this and posted to tell about a better way to do it?
You seem to want to avoid gems, but I can’t say enough good things about https://github.com/bblimke/webmock/ . We had similar pain when trying to use just Mocha to stub/mock network requests. WebMock feels familiar and works great.