Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Stubbing a POST request with body in hash format does NOT work with Typhoeus #348

Closed
changmason opened this Issue · 3 comments

3 participants

@changmason

I created a spec, it seems like stubbing a POST request with body in hash format does not work properly with Typhoeus but work fine with HttpClient. The resulting error is,

Failures:

  1) Webmock stubbing post request with body in hash format should work with typhoeus
     Failure/Error: response = Typhoeus.post('http://example.com/path', :body => {:data => 'blah~'})
     NoMethodError:
       undefined method `split' for {:data=>"blah~"}:Hash
     # ./mock_post_body_spec.rb:13:in `block (2 levels) in <top (required)>'

Here is the spec file, (filename is: mock_post_body_spec.rb)

require 'typhoeus'
require 'httpclient'
require 'webmock/rspec'

describe "Webmock stubbing post request with body in hash format" do
  before do
    stub_request(:post, 'http://example.com/path').
      with(:body => {:data => 'blah~'}).
      to_return({:status => 200, :body => 'Success!'})
  end

  it "should work with typhoeus" do
    response = Typhoeus.post('http://example.com/path', :body => {:data => 'blah~'})
    expect(response.body).to eq('Success!')
  end

  it "should work with httpclient" do
    response = HTTPClient.post('http://example.com/path', {:data => 'blah~'})
    expect(response.body).to eq('Success!')
  end
end
@bblimke
Owner

Fixed in version 1.17.2

@bblimke bblimke closed this
@erwanlr

Awesome, thx :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.