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
1 answer

I'm having trouble understanding how to use webmock with a test for fetching a message from an api

I'm currently trying to write a test for this method: #fetch message from api def message_instance project_id = ENV['SIGNALWIRE_PROJECT_KEY'] project_tkn = ENV['SIGNALWIRE_TOKEN'] host_url = ENV['SIGNALWIRE_HOST'] @client =…
Ruby Newb
  • 53
  • 5
0
votes
0 answers

Do not resolve url in tests with Webmock and CarrierWave remote upload

CarrierWave has a nice feature for uploading images from remote locations https://github.com/carrierwaveuploader/carrierwave#uploading-files-from-a-remote-location I'm using Webmock to stub remote requests, but they don't play nicely together. I…
Max Paprikas
  • 579
  • 6
  • 16
0
votes
1 answer

"Too many open files" during rspec tests on MacOS

I am working on an open source Ruby on Rails project with a full suite of rspec tests. The tests work normally on the CI/CD pipeline server, but locally on my MacBook running Monterey they fail intermittently. Sometimes zero tests will fail,…
0
votes
1 answer

Upgrade Ruby 2.6 to 2.7 - WebMock no longer recognizes RegEx patterns on stub requests

I am upgrading a Rails 6.1.4 application from Ruby 2.6.10 to Ruby 2.7.6. With Ruby 2.7.6, WebMock no longer matches the Regular Expressions that worked perfectly in 2.6.10. I am using the latest version of the WebMock gem (3.14.0) in both cases, as…
Edward Caulfield
  • 448
  • 5
  • 12
0
votes
1 answer

Mock GoogleAPI request

I am using the google-maps gem. I am trying to mock/stub api requests unsuccessfully. module GoogleMap class Route attr_accessor :start_location, :end_location def initialize(start_location, end_location) @start_location =…
madav
  • 2,918
  • 1
  • 13
  • 17
0
votes
2 answers

Mocking login for remote services - Cucumber, Capybara, Rails

I have a Rails application that has changed from user authentication via devise to accessing a remote API for authentication. For the test suite, this requires that I mock the https request for authentication and return a valid response. We are…
Edward Caulfield
  • 448
  • 5
  • 12
0
votes
0 answers

received unexpected message :[] with (:id)

I am trying to mock an API get request (get_organization) to show a page with the organization's info. I am using an ApiClient service. It works in practice, but when I try to stub the api request I get: Failure/Error: if…
everyday_potato
  • 113
  • 1
  • 1
  • 14
0
votes
1 answer

Webmock test for failure to connect fails before finishing test

I have test to for connection error: context 'unsuccessful API request' do it 'responds like 500 if connection error is raised' do http_stub = instance_double(Net::HTTP) allow(Net::HTTP).to receive(:new).and_return(http_stub) …
everyday_potato
  • 113
  • 1
  • 1
  • 14
0
votes
1 answer

Stubbed request not allowing http connections (Real HTTP connections are disabled.)

I am trying to stub a POST request to an external API. The spec test does not replace the ENV variable with my fake one and goes to my local env (localhost:3000) in the stub request returning this error: Failure/Error: response =…
everyday_potato
  • 113
  • 1
  • 1
  • 14
0
votes
0 answers

Rails shared spec 'helpers' by /app and /spec

{Hi} all, we have the following conundrum with my team: We have some rspec tests in /spec for which we need to stub requests and at the same time we have cypress tests (a cypress controller in /app folder) where we also need to stub those requests.…
0
votes
1 answer

Is there a way to test whether a template has properties in an RSpec controller test?

So I'm working on my first Rails project and am working on getting some automated testing set up. Right now, I have a template for a form which has a select tag, which is getting its information dynamically based on a mocked API response. As of now,…
0
votes
0 answers

Webmock / RSpec - Net::HTTP - How to assert that read_timeout and open_timeout have been set on Net::HTTP instance in method

I am new rspec and webmock user! I am setting the read and open timeout values for a Net::HTTP instance in a method that I am unit testing: https = Net::HTTP.new(uri.host, uri.port) https.open_timeout = timeout #set the timeout from method…
anon_dcs3spp
  • 2,342
  • 2
  • 28
  • 62
0
votes
0 answers

How do you properly test a selenium web scraper?

I'm writing a scraper that uses selenium to navigate & login to a certain website; search for the newest data and then store it into a database. I'm using selenium-webdriver to navigate the website, and now I'm trying to write tests for the most…
Alvaro Alday
  • 343
  • 3
  • 19
0
votes
0 answers

How to simulate a POST request in Ruby with the webmock gem?

I am trying to simulate a POST request with rspec. I thought about using the webmock gem, after searching how it worked, my code looks like this: Gist_Request_spec.rb: require_relative '../Gist_Request.rb' require 'spec_helper' require…
0
votes
1 answer

How to use webmock to simulate a request?

My app create a github gist using API. I need to simulate a request to the API with rspec. I'm using the webmock gem but I don't quite understand how to use it for my application. I need a little help to get started. This is my…