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

How do you use VCR and Webmock to stub a post request with basic auth?

Disclaimer: I'm new to APIs and I'm well beyond lost after a week trying to solve this seemingly simple problem. I have code that interacts with Github's API that is already implemented correctly but I want to go back and test it using RSpec,…
Aaron
  • 6,466
  • 7
  • 37
  • 75
1
vote
1 answer

Why am I getting this 'no implicit conversion of Hash into String' when mocking Stripe with WebMock

I'm trying to mock Stripe like this: stub_request(:post, "https://api.stripe.com/v1/tokens").with( :body => {"card" => {"number" => "4242424242424242", "exp_month"=> "12", "exp_year" => "2018", "cvc" => "123"}} ). to_return(:status => 200, :headers…
steven_noble
  • 4,133
  • 10
  • 44
  • 77
1
vote
1 answer

VCR with Webmock incorrectly stubbing Typhoeus (undefined method `>=' for nil:NilClass)

What I want: External API calls to return the same thing each time the tests run What I get: First time VCR saves it, second time Typhoeus returns an error What happens is I run the test once, it makes the actual requests (that happens when I create…
Tom Prats
  • 7,364
  • 9
  • 47
  • 77
1
vote
0 answers

Writing webmock stubs on Modules specs

My problem is I'm creating a wrapper to deal with a connection to an external server (GeoNetwork) and treat its response. While I had my request in my Search Controller, it was working fine. Then I tried to follow this solution for the…
Thiago Alves
  • 53
  • 1
  • 5
1
vote
3 answers

Why does my rspec test pass by itself but fails when I give a specific test to run?

When I run rspec to run all tests, they all pass, but when I give a specific filename, it fails. $ rspec spec/controllers/refinery/books/admin/books_controller_spec.rb 2) Refinery::Books::Admin::BooksController GET :new responds 200 success …
Chloe
  • 25,162
  • 40
  • 190
  • 357
1
vote
1 answer

How would I use VCR (with WebMock) in this scenario?

I'm developing a DSL for building API wrappers, named Hendrix. I am having problems with the testing of the DSL. As it is a API wrapper, it needs to interact with external services. I am not sure how to approach this in terms of testing. I'm using…
user2005477
1
vote
1 answer

Webmock + ":allow_localhost => true" still allow access to 3rd party sites?

I've written a successful cucumber and capybara test, which executes a purchase using paypal sandbox. However, I want stub paypal sandbox request so that my test isn't dependent on the paypal sandbox being up. I'm not 100% familiar with Webmock and…
1
vote
0 answers

how to test twitter api method in application controller using cucumber -rails 3

I have been trying to test/stub application method method that calls a twitter api but i am not getting any success because the method is still calling the original method.Am i missing something because i have been using cucumber and fakeweb...now i…
Milind
  • 4,535
  • 2
  • 26
  • 58
1
vote
2 answers

How do i access the stub_request from within Cucumber > VCR

I would like to fake a network timeout in my cucumber step definition like so: Given(/^the network is timing out$/) do stub_request(:any, 'www.example.com').to_raise(RestClient::GatewayTimeout) end It will give the error that stub_request does…
Mischa Molhoek
  • 164
  • 1
  • 9
1
vote
1 answer

Ruby WebMock: Getting Actual Parameters Passed Through a Method and Using Them in Spec File

I'm using WebMock to stub out HTTP requests. I have this one particular call where, instead of creating dummy data to pass through, I want to be able to capture the actual parameters I would pass into my send() method. Therefore, I need access to…
user1717344
  • 133
  • 1
  • 8
1
vote
0 answers

rails webmock in development mode breaks app

I try to mock the twitter api, therefore I am using webmock in the following way. In an initializer I do save a http response with page = 'curl - is twitterurl with json dataresponse' then I do stub_request(:get, %r|friends/list|).to_return(page) it…
dc10
  • 2,160
  • 6
  • 29
  • 46
1
vote
1 answer

Using cucumber and simulating a redirect to paypal and back

I have a cucumber test which tests a user adding paypal pre-approval. In my controller, I redirect to the paypal pre-approval url. if @payment_method.valid? key = @payment_method.preapprove_paypal redirect_to…
JustNeph
  • 761
  • 3
  • 10
  • 25
1
vote
1 answer

Using Webmock to fake successful ActiveMerchant response

I'm using ActiveMerchant to integrate with Authorize.net CIM. I'm in the middle of writing up automated tests, and I've begun putting into place Webmock calls so that my tests aren't actually hitting Authorize.net each time that they run. I've…
Bryce
  • 2,802
  • 1
  • 21
  • 46
0
votes
0 answers

VCR installation breaks my current specs with WebMock

I'm working on a project which already had a lot of specs using WebMock. Now we decided to try to install VCR and a couple of things are happening. I created a test that runs inside a VCR.use_cassette block Now that test fails if I dont add the…
PedroNeves
  • 110
  • 10
0
votes
1 answer

Problem when trying to stub API requests on Rails

I'm trying to stub an API request using Webmock. Instead of getting the "real" data from my Rails controller, I want to return dummy data, for test purposes only. I have a React frontend with a button that fetches my api endpoint: const handleClick…
baggiogiacomo
  • 179
  • 10