Created
October 18, 2012 12:36
-
-
Save goblin/3911514 to your computer and use it in GitHub Desktop.
webmock bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment