public
Created

webmock bug?

  • Download Gist
app.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
require 'excon'
 
class MyApp
def doit
e = Excon.new('http://google.com')
str = ''
e.request({
:method => 'GET',
:path => '/',
:response_block => lambda { |chunk, remaining, total|
str += chunk
}
})
return str
end
end
app_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
require 'webmock/rspec'
require './app'
 
describe 'app' do
it 'works' do
WebMock.disable_net_connect!
mystr = 'abcdef123'
stub_request(:get, 'http://google.com/').to_return(:status => 200,
:body => mystr)
a = MyApp.new
a.doit.should eq mystr
end
end
irb test
1 2 3 4 5 6 7 8 9 10 11
irb(main):001:0> require './app'
=> true
irb(main):002:0> puts MyApp.new.doit
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
=> nil
irb(main):003:0>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.