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

Webmock + HTTParty: stubbed request with real response inside

I have a test, where I test logging. it "logs out correct messages" do resp = stub_request(:post, "https://api.sandbox.ebay.com/identity/v1/oauth2/token").and_return( headers: { "Content-Type" => "application/json" }, …
Dende
  • 545
  • 6
  • 19
0
votes
1 answer

How do you set a Content-Type Header for the Ruby AWS SDK?

I'm using Webmock to test http requests made by the ruby aws-sdk (in this case aws-sdk-batch). Webmock handles json requests with a much more convenient hash diff and partial matching when the requests fail, but it will only do so if the…
Jacob Dalton
  • 1,643
  • 14
  • 23
0
votes
1 answer

How to stub headless_chrome requisitions with web_mock on src attributes on img tags

I'm trying to use Webmock to stub headless chrome requisitions. I simply want to test the following: Given a select and a carousel tags (the carousel is implemented using Swiper), if I change the select tag, the current showing image of the carousel…
PuckXY
  • 59
  • 3
0
votes
1 answer

Configure Webmock to return the passed body hash

Using Webmock, I'd like the stub to simply return the called body params. For example, I am calling the Mandrill API and passing an options hash. I've tried this, but it is giving me an error: @mandrill = stub_request(:any,…
port5432
  • 5,889
  • 10
  • 60
  • 97
0
votes
1 answer

Test: Using self, expected: 1 time with arguments received: 0 times

I'm currently working on writting test for a Proxy Class that uses Boxr gem to make http calls to Box API. Currently, I have the following method: class BoxApi #### def upload_file_to_box(file_path, file, box_folder_id) …
Steven Aguilar
  • 3,107
  • 5
  • 39
  • 89
0
votes
1 answer

Am I stubbing data correctly?

Imagine I have an app that uses Twitter API. In my app I only have a textarea and a button in which if I submit the form it will tweet to my account. In my app I have the following routes: resources :tweets, :only => [:index, :new, :create] In my…
dcangulo
  • 1,888
  • 1
  • 16
  • 48
0
votes
0 answers

How to test a function called within a thread in ruby using minitest?

The function fetch_details is called within the thread. It has a post request which raises the CustomError in case of failure. I need to test the CustomError without actually making the actual post request. Thread.new { begin …
sparkstar
  • 593
  • 1
  • 7
  • 14
0
votes
1 answer

How to write functioning Webmock stubs with nested data?

I'm trying to write rspec tests. Some of them have to stub calls to external service. Some of these calls send nested data, and this data never seems to be processed by Webmock correctly. describe 'calc' do before do stub_request(:any,…
Steve Redka
  • 108
  • 1
  • 10
0
votes
2 answers

Implement Rest test with database

@RestController @RequestMapping("/transactions") public class PaymentTransactionsController { @Autowired private PaymentTransactionRepository transactionRepository; @GetMapping("{id}") public ResponseEntity get(@PathVariable…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
0
votes
1 answer

How do I make the gem WebMock work with json that includes [square brackets]?

The Rails app in question uses Rspec, Capybara, and WebMock in tests. In one test scenario, this code WORKS: response = RestClient.post 'the.domain.com', { "dados": { "head": { "servico": "autenticacao", "chave": "" …
vivipoit
  • 160
  • 2
  • 11
0
votes
1 answer

how to test stripe failure case with rspecs?

I have the following endpoint in payment controller that completes the purchase. I am using rspecs for testing. For mocking stripe i am using webmock gem. Now i would like to test the failure case i.e rescue Stripe::CardError => e part. I have…
kofhearts
  • 3,607
  • 8
  • 46
  • 79
0
votes
0 answers

using webmock to mock curb Curl::easy

I have a RoR site using curb, and I currently have the line: - password = Curl::Easy.perform("http://www.dinopass.com/password/simple").body_str I am already including webmock, and I see that it claims that it can mock this case. But I don't see…
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
0
votes
1 answer

Unable to stub external request - Wrong regexp?

I'm trying to craft a stub_request that matches all requests to fcm.googleapis.com. Our backend is supposed to send a push notification to its users when new Posts or Comments is created. Our tests trigger a lot of requests to fcm.googleapis.com,…
martins
  • 9,669
  • 11
  • 57
  • 85
0
votes
0 answers

Stub Resolv::DNS UDPSocket requests in rspec

I have the problem, where ruby 2.4.3p205 can't handle domains with german umlauts in them. For example when you try this you get an error [1] pry(main)> Resolv::DNS.new.getresource("exämple.com", Resolv::DNS::Resource::IN::MX) …
23tux
  • 14,104
  • 15
  • 88
  • 187
0
votes
1 answer

How to use webmock with an address that has a variable?

I am using the webmock gem to stub requests for rspec tests. One of my requests makes a request to a microservice that includes a type and a timestamp in the address: e.g. www.microservice.com/type=1?timestamp=1521493200 I can stub the type…
Rachel
  • 157
  • 2
  • 8