WebMock.disable! can break Net::HTTP::DigestAuth and Net::HTTP::Persistent #206

Closed
jonhyman opened this Issue Aug 19, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@jonhyman

In my RSpec tests, I disable WebMocks so that tests wanting to use it need to explicitly enable it.

before :each { WebMock.disable! }

However, if this line is executed before Net::HTTP loads /digest_auth and /persistent, the disabling of the WebMock prevents those modules from loading. When my test tries to call Net::HTTP::DigestAuth or Net::HTTP::Persistence, it exceptions out with '#<NameError: uninitialized constant Net::HTTP::DigestAuth>'.

Even if I try to require those libraries explicitly in the classes that need them, it doesn't work.

I can get around this by requiring 'net/http/digest_auth' and 'net/http/persistence' in my spec_helper before I require 'webmock/rspec'.

@bblimke

This comment has been minimized.

Show comment Hide comment
@bblimke

bblimke Aug 20, 2012

Owner

Thanks for reporting that.
Can you please provide a sample code snippet that shows this error?

Currently WebMock has more problems with Net::HTTP::Persistence than just this one
so I'd like to collect as many failing specs as possible to fix it.

Owner

bblimke commented Aug 20, 2012

Thanks for reporting that.
Can you please provide a sample code snippet that shows this error?

Currently WebMock has more problems with Net::HTTP::Persistence than just this one
so I'd like to collect as many failing specs as possible to fix it.

@jonhyman

This comment has been minimized.

Show comment Hide comment
@jonhyman

jonhyman Aug 20, 2012

Check it out in an IRB console. The ordering of requires changes the outcome.

jonathan:~$ irb
1.9.3p194 :001 > require 'webmock'
=> true
1.9.3p194 :002 > require 'net/http/digest_auth'
=> true
1.9.3p194 :003 > WebMock.disable!
=> {:net_http=>WebMock::HttpLibAdapters::NetHttpAdapter, :curb=>WebMock::HttpLibAdapters::CurbAdapter, :em_http_request=>WebMock::HttpLibAdapters::EmHttpRequestAdapter, :excon=>WebMock::HttpLibAdapters::ExconAdapter}
1.9.3p194 :004 > Net::HTTP::DigestAuth
NameError: uninitialized constant Net::HTTP::DigestAuth
from (irb):4
from /Users/jonathan/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `

'

jonathan:~$ irb
re1.9.3p194 :001 > require 'net/http/digest_auth'
=> true
1.9.3p194 :002 > require 'webmock'
=> true
1.9.3p194 :003 > WebMock.disable!
=> {:net_http=>WebMock::HttpLibAdapters::NetHttpAdapter, :curb=>WebMock::HttpLibAdapters::CurbAdapter, :em_http_request=>WebMock::HttpLibAdapters::EmHttpRequestAdapter, :excon=>WebMock::HttpLibAdapters::ExconAdapter}
1.9.3p194 :004 > Net::HTTP::DigestAuth
=> Net::HTTP::DigestAuth

Check it out in an IRB console. The ordering of requires changes the outcome.

jonathan:~$ irb
1.9.3p194 :001 > require 'webmock'
=> true
1.9.3p194 :002 > require 'net/http/digest_auth'
=> true
1.9.3p194 :003 > WebMock.disable!
=> {:net_http=>WebMock::HttpLibAdapters::NetHttpAdapter, :curb=>WebMock::HttpLibAdapters::CurbAdapter, :em_http_request=>WebMock::HttpLibAdapters::EmHttpRequestAdapter, :excon=>WebMock::HttpLibAdapters::ExconAdapter}
1.9.3p194 :004 > Net::HTTP::DigestAuth
NameError: uninitialized constant Net::HTTP::DigestAuth
from (irb):4
from /Users/jonathan/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `

'

jonathan:~$ irb
re1.9.3p194 :001 > require 'net/http/digest_auth'
=> true
1.9.3p194 :002 > require 'webmock'
=> true
1.9.3p194 :003 > WebMock.disable!
=> {:net_http=>WebMock::HttpLibAdapters::NetHttpAdapter, :curb=>WebMock::HttpLibAdapters::CurbAdapter, :em_http_request=>WebMock::HttpLibAdapters::EmHttpRequestAdapter, :excon=>WebMock::HttpLibAdapters::ExconAdapter}
1.9.3p194 :004 > Net::HTTP::DigestAuth
=> Net::HTTP::DigestAuth

@bblimke

This comment has been minimized.

Show comment Hide comment
@bblimke

bblimke Aug 26, 2012

Owner

This is fixed in master and will be part of the next patch release.

Owner

bblimke commented Aug 26, 2012

This is fixed in master and will be part of the next patch release.

@bblimke bblimke closed this Aug 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment