Questions tagged [webmock]

Library for stubbing and setting expectations on HTTP requests in Ruby.

Library for stubbing and setting expectations on HTTP requests in Ruby.

Features

  • Stubbing HTTP requests at low http client lib level (no need to change tests when you change HTTP library)
  • Setting and verifying expectations on HTTP requests
  • Matching requests based on method, URI, headers and body
  • Smart matching of the same URIs in different representations (also encoded and non encoded forms)
  • Smart matching of the same headers in different representations.
  • Support for Test::Unit
  • Support for RSpec 1.x and RSpec 2.x
  • Support for MiniTest

Supported HTTP libraries

  • Net::HTTP and libraries based on Net::HTTP (i.e RightHttpConnection, REST Client, HTTParty)
  • HTTPClient
  • Patron
  • EM-HTTP-Request
  • Curb (currently only Curb::Easy)
  • Typhoeus (currently only Typhoeus::Hydra)
  • Excon

Supported Ruby Interpreters

  • MRI 1.8.6
  • MRI 1.8.7
  • MRI 1.9.1
  • MRI 1.9.2
  • MRI 1.9.3
  • REE 1.8.7
  • JRuby
  • Rubinius

Source: https://github.com/bblimke/webmock

166 questions
0
votes
0 answers

HTTParty + Webmock | Invalid url inside specs

When running requests with disable_rails_query_string_format with such query params: query: {selected_ids: [1,2,3]} It works fine when running the code in the app, but when running specs, the url become truncated and only last element of the array…
pandomic
  • 607
  • 1
  • 6
  • 17
0
votes
1 answer

Disable rest-client output on minitest

I've searched for this, but without success. I have some tests (minitest) that use RestClient and Webmock. When passing for those tests I always have the request logged, polluting the test ouput: [$] rake …
lcguida
  • 3,787
  • 2
  • 33
  • 56
0
votes
0 answers

WebMock model's function when called via controller

I have existing functionality, where specs calls HTTP PUT method of a controller, which in-turn calls model's method to get some JSON data via. API. class SomeModel def GetData() uri =…
G J
  • 477
  • 9
  • 23
0
votes
2 answers

Ruby: Selenium and WebMock causing TypeError

The combination of WebMock and Selenium is causing a Type Error on the first call to visit Failure/Error: id['ELEMENT'] || id['element-6066-11e4-a52e-4f735466cecf'] TypeError: no implicit conversion of String into Integer #…
TIMBERings
  • 688
  • 1
  • 8
  • 28
0
votes
0 answers

How to solve the the Curl's "Couldn't connect to server"

I'm using Rspec with Capybara with WebMock for my tests (also I'm using Charles proxy), Getting the following error, never in a specific test. I've had this happen once in a while, using rspec-retry mostly to deal with it, but now I've noticed it…
Captain_Meow_Meow
  • 2,341
  • 5
  • 31
  • 44
0
votes
1 answer

How to stub HTTP request on Mechanize in Rails?

I have some codebase like this, and I wanna use rspec test favicon_href, but as you like, the favicon_href will call the page function, I know I can mock page function, but for this stage I wanna mock the HTTP request from the given url, so I use…
Hsiu Chuan Tsao
  • 1,396
  • 1
  • 12
  • 23
0
votes
0 answers

How to allow HTTP requests to other docker containers with RSpec?

I have a docker project with a few different moving parts, and I want one container to be able to call the API of another container. However, sending any kind of request in my rspec tests yields: WebMock::NetConnectNotAllowedError: Real HTTP…
Cisplatin
  • 2,860
  • 3
  • 36
  • 56
0
votes
1 answer

Test around amazon S3 upload fails only on Circle CI using WebMock

I have tests around uploading an image to S3, wherever it's tested I stub the request made. All the tests pass locally but on circle CI I get the following exception: WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled.…
NomNomCameron
  • 419
  • 5
  • 14
0
votes
1 answer

Webmock Unregistered request blows up my test

In my spec_helper, I have webmock setup like so: WebMock.disable_net_connect!(allow_localhost: true) RSpec.configure do |config| config.before(:each) do stub_request(:get, /cdn.\w+.io/). with(:headers => {'Accept-Encoding'=>'gzip',…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
0
votes
1 answer

Rails webmock stubbing out localhost api call

I have a controller, which has a post_review action which calls a Rest Client API call. def post_review ... headers = { "CONTENT_TYPE" => "application/json", "X_AUTH_SIG" =>…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
0
votes
1 answer

stub_request with Bearer Authorisation header not working in webmock 2

The following code works webmock 1.20.4 but not with 2.0.1 stub_request(:get, "http://www.myapi.com/my-endpoint") .with(headers: {'Authorization' => "Bearer fake_oauth_token"}) .to_return(:body => mock_response) This is the code I…
TTransmit
  • 3,270
  • 2
  • 28
  • 43
0
votes
1 answer

Stub request in a Rails gem with persistent HTTPClient

I'm trying to write an RSpec test that stubs out requests to api.box.com using the Boxr gem (https://github.com/cburnette/boxr). I've created a stub that goes to a fake Box class using the #to_rack method stub_request(:any,…
0
votes
1 answer

Rails Rspec Testing with WebMock. Stubbing Class initialize if not production env?

I'm new to testing and have run into a bit of a problem with testing external dependency responses. My use case is that I have a gem Foo that that sends back some data based on passed in data. I use this gem when I initialize a class FooBar. The…
CarlyL
  • 171
  • 1
  • 10
0
votes
1 answer

Web mock does not work with redirect_to in Rails controller

My controller has this piece of code: class MyController < App::BaseController def login redirect_to 'https://some.api.com/auth?params' end end Of course I don't want to be redirected to external website in tests. So I decided to add…
Filip Bartuzi
  • 5,711
  • 7
  • 54
  • 102
0
votes
1 answer

Make a webmock with port range

I'm using rspec and capybara with js: true in the describe but I have one problem : Failure/Error: visit '/users/sign_in' WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET…
Mio
  • 1,412
  • 2
  • 19
  • 41