Skip to content

Webmock incompatibility with http gem #176

Closed

Description

@tjsousa

Is this a support request?
No

Describe the bug
NameError:
undefined method perform' for class HTTP::Client'

When LD SDK gem is included in Gemfile of a project using the latest version of Webmock, this error shows up.

To reproduce
Include both LD SDK gem and Webmock in the same project and run RSpec.

Expected behavior
Would expect the client to interact cleanly with http gem.

Logs

Failure/Error: require File.expand_path('../config/environment', __dir__)
NameError:
  undefined method `perform' for class `HTTP::Client'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb/client.rb:3:in `alias_method'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb/client.rb:3:in `<class:Client>'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb/client.rb:2:in `<module:HTTP>'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb/client.rb:1:in `<top (required)>'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb_adapter.rb:32:in `require'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock/http_lib_adapters/http_rb_adapter.rb:32:in `<top (required)>'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock.rb:49:in `require_relative'
# ./vendor/bundle/ruby/2.5.0/gems/webmock-3.12.1/lib/webmock.rb:49:in `<top (required)>'
# /usr/local/bundle/gems/bundler-2.2.21/lib/bundler.rb:174:in `require'
# ./config/application.rb:17:in `<top (required)>'
# ./config/environment.rb:4:in `require_relative'
# ./config/environment.rb:4:in `<top (required)>'
# ./spec/rails_helper.rb:6:in `require'

SDK version
6.2.0

Language version, developer tools
Ruby 2.5.9

OS/platform
MacOS Big Sur

Additional context
Add any other context about the problem here.

Activity

  1. eli-darkly commented on Jul 8, 2021

    @eli-darkly
    Contributor

    It seems likely that the issue here is not that the SDK isn't "cleanly interacting with the http gem", but that the SDK and webmock want two different versions of the http gem. This is a common issue in Ruby and really in any language that has a package manager, but it's largely outside of our control.

    You can see in our gemspec that the SDK is requesting version "~>4.4.1" of http— that is, 4.4.1 or a higher compatible version.

    And in Webmock's gemspec, there is a requirement for version ">=0.8.0" of http. That's a very broad requirement (0.8.0 was 6 years ago)— which would be fine if Webmock really were OK with any version greater than or equal to 0.8.0, but it seems like it is not.

    From the information you provided, there's no way for me to know what version of http you actually have— which could also be affected by other dependencies in your project. If it were 4.4.1, I would not expect this error from Webmock because the specific failure that Webmock is having (not being able to find a perform method in HTTP::Client) doesn't make sense for any recent version of http, since the perform method does exist in those. (It does not exist in 0.8.0 though, so I don't know why they declared their requirement in that way; in other words, at first glance it looks to me like Webmock would not actually work with what they say is their minimum http version. But, due to our SDK's request for a higher version, I would not expect that such an old version would be loaded.)

    I can't really say more without being able to see the list of dependency gems/versions as they are declared in your project (and how you are installing them, like, are you using Bundler?) as well as which versions actually got installed. This looks very much like a basic dependency conflict; I don't think there is anything un-"clean" about how we are using the http gem, we are simply declaring a requirement for a recent version. It's possible that we made the requirement overly recent, that is, we might also be able to work with earlier versions, but I think that is probably a different issue. Webmock claims to be compatible with http 4.4.1 so this does not make a lot of sense to me.

  2. eli-darkly commented on Jul 8, 2021

    @eli-darkly
    Contributor

    By the way, I did try to reproduce this, but wasn't able to. What you wrote under "steps to reproduce" was very general; "Include both LD SDK gem and Webmock in the same project and run RSpec" would be enough if it were really true that any project using both gems would reproduce the problem, but that doesn't seem to be the case. So if you could provide a minimal project that demonstrates the error, that would be helpful.

    Here's what I did:

    1. Started with Ruby 2.5.9 on MacOS 10.15.7, with no gems installed except bundler 2.2.22 (and ffi, because there is a MacOS problem where you have to preinstall ffi in a particular way)

    2. Created this Gemfile:

    source "https://rubygems.org"
    
    gem "launchdarkly-server-sdk", "6.2.0"
    gem "webmock", "3.12.1"
    gem "rspec", "3.4.0"
    

    (Your wrote "the latest version of Webmock", which is 3.13.0 rather than 3.12.1, but it looks like 3.12.1 was what you were using so that's what I used.)

    1. Ran bundle install successfully. I noted in the output that it installed version 4.4.1 of http.

    2. Created a minimal spec file test.rb:

    require "launchdarkly-server-sdk"
    require "webmock"
    
    describe "stub test" do
      it "loads" do  	
      end
    end
    1. Ran bundle exec rspec test.rb.
    Finished in 0.00024 seconds (files took 0.98972 seconds to load)
    1 example, 0 failures
    

    Based on the error output you showed, I would have expected this problem to happen as soon as it hit require "webmock", so it shouldn't matter whether the spec actually does anything.

  3. added a commit that references this issue on Dec 9, 2021
  4. eli-darkly commented on Dec 9, 2021

    @eli-darkly
    Contributor

    Closing this issue because 1. we were not able to reproduce it and 2. it does not seem to be a problem with the SDK itself, but rather, that the developer is trying to use a test library that wants a very old version of http.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions