Webmock compatibility is broken #196

Closed
challengee opened this Issue Jul 5, 2012 · 24 comments

Projects

None yet

9 participants

@challengee
Contributor

Webmock chokes on the accessor global_hooks that is gone on Hydra.

stacktrace:

/Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:41:in `remove_after_request_callback': undefined method `global_hooks' for Typhoeus::Hydra:Class (NoMethodError)
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:23:in `disable!'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:39:in `block in enable!'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each_adapter'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:38:in `enable!'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:123:in `<module:WebMock>'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:1:in `<top (required)>'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock.rb:47:in `require'
    from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock.rb:47:in `<top (required)>'
@i0rek
Member
i0rek commented Jul 5, 2012

Thanks for reporting. I know that and I'll fix it.
There is no stubbing/mocking functionality in typhoeus right now at all.

@ifesdjeen
Contributor

I've started an effort of renewing the hook code. I hope to have a working version by end of week.

For now unfortunately I can only ask to use an older (0.4.0 iirc) version..

alex p

Am 05.07.2012 um 15:39 schrieb Mattias Putmanreply@reply.github.com:

Webmock chokes on the accessor global_hooks that is gone on Hydra.

stacktrace:

/Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:41:in `remove_after_request_callback': undefined method `global_hooks' for Typhoeus::Hydra:Class (NoMethodError)
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:23:in `disable!'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:39:in `block in enable!'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each_adapter'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:38:in `enable!'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:123:in `<module:WebMock>'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock/webmock.rb:1:in `<top (required)>'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock.rb:47:in `require'
   from /Users/mattias/.rvm/gems/ruby-1.9.3-p125/gems/webmock-1.8.7/lib/webmock.rb:47:in `<top (required)>'

Reply to this email directly or view it on GitHub:
#196

@myronmarston
Contributor

The existing typhoeus adapter in WebMock uses monkey patching. I opened an issue (bblimke/webmock#200) there to suggest reducing the amount of monkey patching WebMock does. Given that Typhoeus had (and presumably will have again) a proper public stubbing API, I think it'd be best to have WebMock use only the public APIs. I suspect WebMock went the monkey patching route because it had some needs beyond what the old public APIs allowed. This is a good chance to improve this.

So...please involve @bblimke in any discussion about the new public stubbing APIs. It'd be great to improve them to the point where libraries like WebMock can get by w/o monkey patching, which should in turn lead to great stability and less maintenance work on both sides to keep things working.

@i0rek
Member
i0rek commented Aug 18, 2012

For some reasons I didn't even thought about removing the monkey patch, but this is a great idea. Will check!

@bblimke Do you already have something in mind?

@bblimke
bblimke commented Aug 20, 2012

@myronmarston thank you for suggesting more collaboration between Webmock and Typhoeus :)

@i0rek I can't remember the exact reasons for why Typhoeus stubbing api was not flexible enough
to be used in WebMock. It would be great if we could find a way to add some low level hooks
to Typhoeus so that WebMock doesn't need to do monkey patching anymore.
I'll have a look at Typhoeus adapter when I get a moment, but would be great if you
could also have a look if you see any easy way to add a hook to Typhoeus
to get rid of monkey patch from WebMock.

@i0rek
Member
i0rek commented Aug 23, 2012

Its almost done: https://github.com/i0rek/webmock/tree/typhoeus_0.5.0.
There are two failing specs left:

Failures:

  1) Typhoeus::Hydra with WebMock when after_request callback is declared should pass request signature to the callback
     Failure/Error: @request_signature.uri.to_s.should == "http://www.example.com:80/"
     NoMethodError:
       undefined method `uri' for nil:NilClass
     # ./spec/acceptance/shared/callbacks.rb:44:in `block (3 levels) in <top (required)>'

  2) Typhoeus::Hydra with WebMock when after_request callback is declared passes the same request signature instance to the callback that was passed to the global stub callback
     Failure/Error: global_stub_request_sig.should be(after_request_request_sig)

       expected #<NilClass:4> => nil
            got #<WebMock::RequestSignature:70308068427640> => GET http://www.example.com/ with headers {'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}

       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       'actual.should == expected' if you don't care about
       object identity in this example.
     # ./spec/acceptance/shared/callbacks.rb:63:in `block (3 levels) in <top (required)>'

Finished in 41.6 seconds
3166 examples, 2 failures

@bblimke could you please have a look at these two remaining failures?

The monkey patch is still there, but I won't release unless he is gone!

@myronmarston
Contributor

I can't remember the exact reasons for why Typhoeus stubbing api was not flexible enough
to be used in WebMock.

If memory serves correctly, I believe Typhoeus' first version of it's stubbing API only supported "static" stubs -- e.g. the user of the API told typhoeus how to match requests, similar to the FakeWeb and WebMock APIs. Later, I worked with David to add the block-based stubbing API that's more "dynamic", so that VCR can do it's own request matching. I believe WebMock added Typhoeus support between these two versions of the stubbing API. The block-based API that VCR uses could also be used by WebMock to do just about anything, I think. My understanding is that it hasn't been added back to Typhoeus 0.5 yet but @i0rek plans to add it since VCR needs it and it makes things so flexible. I think the monkey patch can be removed in favor of that once it's added.

@i0rek
Member
i0rek commented Aug 23, 2012

@myronmarston From what I see in the webmock monkey patch you remember right. And yes, the flexible API will make it back into typhoeus.

Removing the monkey patch is not only nice but necessary because the with typhoeus 0.5.0 not every request goes through the hydra. I've the choice to remove the monkey patch or add another one - thats not a hard decision :).

@bblimke
bblimke commented Aug 24, 2012

@i0rek excellent! I'll investigate these two failing specs when I have some spare time.

@bblimke
bblimke commented Aug 26, 2012

@i0rek I had a look at these failing specs and the reason they are failing is that the response.request is nil here https://github.com/i0rek/webmock/blob/typhoeus_0.5.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb#L111

Where is the code in Typhoeus that sets the request attribute on response object?

@i0rek
Member
i0rek commented Aug 27, 2012

@bblimke Thanks! Its GREEN!

@bblimke
bblimke commented Aug 27, 2012

@i0rek Awesome!! I'll merge it and release as soon as you are ready to release Typhoeus 0.5.0.

@i0rek i0rek closed this Sep 14, 2012
@ifightcrime

I'm still getting this error in 0.5.0 with webmock 1.8.11 (exact same stack trace as originally mentioned)

@i0rek
Member
i0rek commented Oct 30, 2012

Its because webmock with typhoeus 0.5 support is not yet released.

You could use my branch for now: https://github.com/i0rek/webmock/tree/typhoeus_0.5.0.

@ifightcrime

Ah, my bad. Thanks!

@Kequc
Kequc commented Mar 14, 2013

I am new here and I am getting a very similar error.

/Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:50:in `remove_after_request_callback': undefined method `on_complete' for Typhoeus:Module (NoMethodError)
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:24:in `disable!'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/webmock.rb:39:in `block in enable!'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb:16:in `each_adapter'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/webmock.rb:38:in `enable!'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/webmock.rb:123:in `<module:WebMock>'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock/webmock.rb:1:in `<top (required)>'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock.rb:48:in `require'
    from /Users/nathan/.rvm/gems/ruby-2.0.0-p0/gems/webmock-1.11.0/lib/webmock.rb:48:in `<top (required)>'
@bblimke
bblimke commented Mar 14, 2013

What version of Typhoeus do you use?

@Kequc
Kequc commented Mar 14, 2013

Using typhoeus (0.4.2)

This is in a Rails 4 environment with minitest, I'm not sure if it's the most common setup due to that.

@bblimke
bblimke commented Mar 14, 2013

WebMock is not compatible with 0.4.2 for a time. I suggest you upgrade to the latest Typhoeus.

@Kequc
Kequc commented Mar 14, 2013

Not sure what it was that installed such an old version. Defining the version I wanted explicitly and running bundle update fixed the problem as you expect.

Thank you

@i0rek
Member
i0rek commented Mar 14, 2013

@Kequc Glad it works for you!
@bblimke thanks for helping!

@KranthiKishore

Hi All,
I'm getting the below error
undefined method on_complete' for Typhoeus:Module /home/kranthi/.rvm/gems/ruby-1.9.3-p327@sh3/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:50:inremove_after_request_callback'
/home/kranthi/.rvm/gems/ruby-1.9.3-p327@sh3/gems/webmock-1.11.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:24:in `disable!'

Can anyone help me..My rails version is
rails (3.2.12)
typhoeus (0.5.0, 0.4.2)
tzinfo (0.3.37)
uglifier (1.3.0)
uuidtools (2.1.3)
vegas (0.1.11)
webmock (1.11.0)
websocket (1.0.7)
xpath (0.1.4)
Thanks in advance.

@achikin
achikin commented Apr 10, 2014

webmock 1.17.4 and the same error.

@i0rek
Member
i0rek commented Apr 10, 2014

You should update your Typhoeus I think.

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