customerio / customerio-ruby

A ruby client for the Customer.io event API.
https://customer.io/docs/api/
MIT License
65 stars 75 forks source link

specs are failing #44

Closed gingerlime closed 7 years ago

gingerlime commented 7 years ago

I'm trying to run specs on this project, and most of them fail on a similar error

  26) Customerio::Client#anonymous_track allows sending of a timestamp
      Failure/Error: http.request(req)

      WebMock::NetConnectNotAllowedError:
        Real HTTP connections are disabled. Unregistered request: POST https://track.customer.io/api/v1/events with body 'name=purchase&data[type]=socks&data[price]=27.99&data[timestamp]=1561235678&timestamp=1561235678' with headers {'Authorization'=>'Basic U0lURV9JRDpBUElfS0VZ', 'Content-Type'=>'application/x-www-form-urlencoded'}

        You can stub this request with the following snippet:

        stub_request(:post, "https://track.customer.io/api/v1/events").
          with(:body => {"data"=>{"type"=>"socks", "price"=>"27.99", "timestamp"=>"1561235678"}, "name"=>"purchase", "timestamp"=>"1561235678"},
               :headers => {'Authorization'=>'Basic U0lURV9JRDpBUElfS0VZ', 'Content-Type'=>'application/x-www-form-urlencoded'}).
          to_return(:status => 200, :body => "", :headers => {})

        registered request stubs:

        stub_request(:post, "https://SITE_ID:API_KEY@track.customer.io/api/v1/events").
          with(:body => {"data"=>{"type"=>"socks", "price"=>"27.99", "timestamp"=>"1561235678"}, "name"=>"purchase", "timestamp"=>"1561235678"})

        ============================================================
      # /usr/local/bundle/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb:114:in `request'
      # ./lib/customerio/client.rb:119:in `block in request'
      # /usr/local/bundle/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb:123:in `start_without_connect'
      # /usr/local/bundle/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
      # ./lib/customerio/client.rb:118:in `request'
      # ./lib/customerio/client.rb:79:in `create_event'
      # ./lib/customerio/client.rb:73:in `create_anonymous_event'
      # ./lib/customerio/client.rb:53:in `anonymous_track'
      # ./spec/client_spec.rb:349:in `block (3 levels) in <top (required)>'

It looks like the client no longer passes the SITE_ID and API_KEY in the URL, but rather adds a basic authentication Authorization header, but the tests weren't updated to reflect this?

alisdair commented 7 years ago

Specs pass for me locally. Why are you running against webmock 2.3.2? The Gemfile.lock specifies 1.24.2, and the different gem versions may be what's causing the failures.

gingerlime commented 7 years ago

There's no Gemfile.lock file in the repo... And I think travis is also showing similar failures, no?

alisdair commented 7 years ago

Whoops, of course there isn't a Gemfile.lock, I forgot that it's not supposed to be committed for gems. So our gemspec is too lax with the dev dependencies, which should be fixed.

The Travis failures I looked at aren't related: they're caused by not updating the mock requests for the changes you made in the PR. But I see that on builds for newer Rubies we're hitting the same issue, which again I think is a gemspec bug. Will investigate, thanks!

gingerlime commented 7 years ago

Some early failures were my mistake (although I couldn't test it locally, so it was kinda unavoidable). But I think the most recent build failed due to similar issues as I reported here. I didn't check thoroughly, because there's a lot of noise.