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

In Cucumber on Ruby w/rspec, how do I expect/assert a webmocked call in a Then clause?

I'm writing a gem that acts as a client for a remote API, so I'm using webmock to mock out the remote API, testing with Cucumber with rspec-mock present too. As part of my Cucumber tests I intend to stub my API in a Given clause but then I would…
otupman
  • 1,238
  • 10
  • 20
0
votes
1 answer

Does webmock auto detects `?` in the url

I am using webmock for stubbing requests. I stubbed a request using the following code. stub_request(:delete, "https://graph.facebook.com/v2.0/1741/likes?access_token=this_is_a_test_token").to_return(body: "true") And I get the following error…
Nishutosh Sharma
  • 1,926
  • 2
  • 24
  • 39
0
votes
1 answer

How to register a request stub using 80 port with webmock?

I am using webmock to stub and set expectations on HTTP requests in Ruby. Also I am using rspec. Here is my spec/feature/***.rb's code: require 'webmock/rspec' require 'net/http' require 'uri' # ... it 'Request third-part API' do …
s-cho-m
  • 967
  • 2
  • 13
  • 28
0
votes
1 answer

Getting Webmock to stub HTTParty requests

I am having trouble getting Webmock to work. I am using HTTParty to make GET requests. I would like to have the following request return an error: require 'spec_helper' require 'api_parser' require 'httparty' describe ApiParser do describe…
user3809888
  • 377
  • 1
  • 6
  • 23
0
votes
1 answer

Ruby - Webmock: Match URI using regular expression

I'm working with rspec and webmock and I'm looking into stubbing request. I do have a problem when I try to use regex to match the URI. Everything was working fine when I used the stub below, without matching a specific URI (/.*/) it "returns nil…
AlessioG
  • 576
  • 5
  • 13
  • 32
0
votes
1 answer

curl not piping to file when querying the google maps api

I am working on a ruby application that uses the geocoder gem to generate location information from addresses. I am trying to use webmock to stub out calls to the api during testing. Webmock has the option of creating a mock response from a file and…
Peter Saxton
  • 4,466
  • 5
  • 33
  • 51
0
votes
2 answers

Stub XMLRPC::Client call in rails test with rspec

I'm trying to stub XMLRPC::Client.call in my rspec tests in rails. Here is my method: def xmlrpc_call(location, repeat, func, *args) Rails.logger.debug("XML_RPC: calling #{func}(#{args.inspect})") timeout = XMLRPC_TIMEOUT ?…
retgoat
  • 2,414
  • 1
  • 16
  • 21
0
votes
1 answer

Is there a Ruby WebMock equivalent for the Lua language?

I have a Lua module I'm writing for making requests to a public API: -- users.lua local http = require("socket.http") local base_url = 'http://example.com' local api_key = "secret" local users = {} function users.info(user_id) local…
Chip Castle
  • 2,132
  • 3
  • 20
  • 34
0
votes
0 answers

Using webmock to mock XMLRPC client in rspec-rails

I'm trying to spec a client that goes through the following series of calls via XMLRPC: post (https) myservice.auth.login (with params login, password) post (http) myservice.items.list (with sessionid from login) I'm trying to mock these so I don't…
Steve Ross
  • 4,134
  • 1
  • 28
  • 40
0
votes
1 answer

How to test stubbed status in response using webmock?

I am testing some service require 'spec_helper' feature 'MyAPIService' do before do stub_request(:get, "http://my_app.com/persisted_session"). with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). to_return(status: 200, body:…
tomekfranek
  • 6,852
  • 8
  • 45
  • 80
0
votes
1 answer

Integration test for a method that redirects to an external website

This method redirects to an external website. How do I test this behaviour? I know that the method works correctly because I tested in the browser, but I can't get the test to pass. def create if @order.save redirect_to…
dee
  • 1,848
  • 1
  • 22
  • 34
0
votes
2 answers

webmock and crack 0.3.2 issue

I installed the webmock gem but my rspec tests wouldn't work anymore but instead this error: (I use guard for autotesting) /home/neilmarion/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.4/lib/bundler/spec_set.rb:90:in `block in materialize':…
neilmarion
  • 2,372
  • 7
  • 21
  • 36
0
votes
2 answers

stub_request chain to_return from array of files

i have an array of raw_responses using web_mock i want use them as args of to_return method and chain to stub_request method: #["file1.txt", "subfolder/file_n.txt", "awsome_name.txt"] rr = Dir.glob(File.expand_path("../../markups/*.txt",…
Danil
  • 2,497
  • 2
  • 19
  • 27
-1
votes
1 answer

Is it possible to use VCR gem in Ruby to record an outgoing message and expect that the correct message is sent?

This would be the same functionality as Webmock. Except it would take a cassette instead of a string. Something like expect(Webmock)to receive...
B Seven
  • 44,484
  • 66
  • 240
  • 385
-2
votes
2 answers

Webmock: no implicit conversion of nil into String

When I am trying to mock a http request with the following code snippet. mocked_payload = { test: 'testing' }.to_json stub_request(:get, application_url) .with(body: platform.user_credentials) .to_return(status: 200, body: mocked_payload) I…
DenicioCode
  • 8,668
  • 4
  • 18
  • 33
1 2 3
11
12