-
Added support for Ruby 2.4
Thanks to Koichi ITO
-
Dropped support for Ruby 1.9.3
-
Added
refute_requested
as an alias forassert_not_requested
Thanks to Michael Grosser
-
Raising
Net::OpenTimeout
instead ofTimeout::Error
if available when a request stub is declaredto_timeout
Thanks to Gabe Martin-Dempesy
-
Added support for handling status messages in Excon responses.
Thanks to Tero Marttila for reporting the issue.
-
Added support for
on_debug
callback in Curb.Thanks to Pavel Jurašek
-
Added support for PATCH requests using Curb.
Thanks to Pavel Jurašek
-
Handling headers passed as an Array to Curl::Easy
Thanks to Chelsea for reporting the issue.
-
Removed Ruby warnings.
Thanks to Aaron Kromer
-
Using
Base64.strict_encode64
instead ofBase64.encode64
to handle long user:pass basic auth credentialsThanks to Jonathan Schatz
-
Fixed handling of Authorisation header provided as string instead of array when using em-http-request.
Thanks to Michael Richardson for reporing the issue.
-
Ensured
WebMock.net_connect_explicit_allowed?
always returns boolean.Thanks tp Jose Luis Honorato
-
Added code responsible for loading em-http-request if available, which has been removed by mistake.
Thanks to Vasiliy
-
WebMock loads "base64" if it's not yet loaded.
Thanks to Taiki Ono.
-
require 'webmock'
does not enable WebMock anymore.gem 'webmock'
can now be safely added to a Gemfile and no http client libs will be modified when it's loaded. CallWebMock.enable!
to enable WebMock.Please note that
require 'webmock/rspec'
,require 'webmock/test_unit'
,require 'webmock/minitest'
andrequire 'webmock/cucumber'
still do enable WebMock. -
Dropped support for Ruby < 1.9.3
-
Dropped support for em-http-request < 1.0.0
-
WebMock 2.0 does not match basic authentication credentials in the userinfo part of the url, with credentials passed in
Authorization: Basic ...
header anymore. It now treats the Authorization header and credentials in the userinfo part of a url as two completely separate attributes of a request.
The following stub declaration, which used to work in WebMock 1.x, is not going to work anymore
stub_request(:get, "user:[email protected]")
Net::HTTP.start('www.example.com') do |http|
req = Net::HTTP::Get.new('/')
req.basic_auth 'user', 'pass'
http.request(req)
end # ===> Failure
In order to stub a request with basic authentication credentials provided in the Authorization header, please use the following code:
stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
or
stub_request(:get, "www.example.com").
with(headers: 'Authorization' => "Basic #{ Base64.strict_encode64('user:pass').chomp}")
In order to stub a request with basic authentication credentials provided in the url, please use the following code:
stub_request(:get, "user:[email protected]")
RestClient.get('user:[email protected]') # ===> Success
-
Fixed issue with RUBY_VERSION comparison using old RubyGems.
Thanks to Chris Griego.
-
Support for http.rb >= 2.0.0
-
Fixed the issue with parsing query to a hash with nested array i.e.
a[][b][]=one&a[][c][]=two
Thanks to Tim Diggins for reporting the issue. Thanks to Cedric Pimenta for finding the solution.
-
Allow Net:HTTP headers keys to be provided as symbols if
RUBY_VERSION
>= 2.3.0Thanks to Alex Kestner
-
Added a clear message on an attempt to match a multipart encoded request body. WebMock doesn't support requests with multipart body... yet.
-
WebMock.disable_net_connect
:allow
option, provided as regexp, matches https URIs correctly. -
WebMock.disable_net_connect
:allow
option can be set as a url string with scheme, host and port.WebMock.disable_net_connect!(:allow => 'https://www.google.pl')
Thanks to Gabriel Chaney for reporting the issue.
-
Improve parsing of params on request
Thanks to Cedric Pimenta
-
HTTPClient adapter supports reading basic authentication credentials directly from Authorization header.
Thanks to Michiel Karnebeek
- Enabled support for Curb > 0.8.6
-
WebMock.disable_net_connect
accepts:allow
option with an object that responds to#call
, receiving aURI
object and returning a boolean:blacklist = ['google.com', 'facebook.com', 'apple.com'] allowed_sites = lambda{|uri| blacklist.none?{|site| uri.host.include?(site) } } WebMock.disable_net_connect!(:allow => allowed_sites) RestClient.get('www.example.org', '/') # ===> Allowed RestClient.get('www.facebook.com', '/') # ===> Failure RestClient.get('apple.com', '/') # ===> Failure
Thanks to Pablo Brasero
-
Support for HTTPClient stream responses with body chunks
Thanks to Cedric Pimenta
-
Fixes issue around WebMock restricting Addressable version, based on Ruby 1.8.7 for all versions of Ruby.
This change inverts that, and forces Ruby 1.8.7 users to specify in thier Gemfile an Addressable version < 2.4.0.
Thanks to PikachuEXE and Matthew Rudy Jacobs.
-
Fixes bug where WebMock tries to alias a method that is deprecated in Ruby Versions > 1.9.2 ('sysread' for class 'StringIO')
Thanks to Marcos Acosta for discovering this bug.
-
Adds support for JSONClient (a subclass of HTTPClient)
Thanks to Andrew Kozin
-
Adds support for Ruby 2.3.0
Thanks to Charles Pence
-
Adds support for http versions >= 1.0.0
Thanks to Alexey Zapparov
-
Fixes support for Ruby 1.8.7 by restrciting Addressable version < 2.4.0
Thanks to Matthew Rudy Jacobs
-
Return "effective_url" attribute in Typhoeus::Response
Thanks to Senya
-
Fix: prevents adding an extra =true to urls with parameters without values
Thanks to David Begin
-
Adds Rack as a development dependency and removes require rack/utils in main lib.
Thanks to Keenan Brock
All the credit for preparing this release go to David Begin!
-
Adds Manticore support.
Thanks to Mike Knepper, David Abdemoulaie
-
Update to Show a hash diff for requests that have stubs with a body.
Thanks to yurivm
-
Update to mirror Net::HTTP handling of headers as symbols
-
Update to ignore non-comparable-values error when sorting query values, because sorting is just a convience.
Thanks to Magne Land
-
Covert Boolean values to Strings when using them to define the body of a request.
Thanks to Krzysztof Rygielski
-
Fixes WebMock's parsing Multibyte characters
Thanks to Zhao Wen
-
Updates to be compatible with httpclient 2.6.0
-
Converts keys from symbols to strings when for QueryMapper.to_query
Thanks to Ramon Tayag
-
Restricts http.rb version to 0.7.3 for Ruby 1.8.7
-
Fixes issue emulating em-http-request's handling of multiple requests.
Thanks to Matt Palmer
-
WebMock requires only the necessary parts of crack to avoid pulling in safe_yaml
Thanks to Johannes Schlumberger
-
Support for http.rb >= 0.8.0
Thanks to Zachary Anker, Aleksey V. Zapparov
-
Support for http.rb 0.7.0
Thanks to Mattias Putman
-
Added support for RSpec3-like
and_return
,and_raise
,and_timeout
syntax.Thanks to Franky Wahl
-
Restricted Curb support up to version 0.8.6. WebMock specs fail with Curb 0.8.7.
- Fixed support for
hash_including
matcher in RSpec 3
-
with
method raises error if provided without options hash and without block -
with
andto_return
raise an error if invoked with invalid keys in options hash.
-
WebMock provides a helpful error message if an incompatible object is given as response body.
Thanks to Mark Lorenz
-
assert_requested
andassert_not_requested
acceptat_least_times
andat_most_times
optionsThanks to Dan Buettner
-
Silenced
instance variable undefined
warnings in Curb adapted.Thanks to Sven Riedel
-
Add support for on_missing callback of Curb::Easy
Thanks to Tasos Stathopoulos
-
Add at_least_times and at_most_times matchers
Thanks to Dan Buettner
-
Fixed issue with Excon adapter giving warning message when redirects middleware was enabled.
Thanks to Theo Hultberg for reporting that.
-
Fixed issue with
undefined method 'valid_request_keys' for Excon::Utils:Module
Thanks to Pablo Jairala
-
Fixed query mapper to encode
'one' => ['1','2']
as'one[]=1&one[]=2'
.Thanks to Insoo Buzz Jung
-
Improved cookies support for em-http-request
Thanks to Carlos Alonso Pérez
-
Fix HTTP Gem adapter to ensure uri attribute is set on response object.
Thanks to Aleksey V. Zapparov
-
Fixed HTTPClient adapter. The response header now receives
request_method
,request_uri
, andrequest_query
transferred from request headerThanks to trlorenz
-
Query mapper supports nested data structures i.e.
{"first" => [{"two" => [{"three" => "four"}, "five"]}]}
Thanks to Alexander Simonov
-
Fixed compatibility with latest versions of Excon which don't define
VALID_REQUEST_KEYS
anymore.Thanks to Pablo Jairala
-
Request method is always a symbol is request signatures. This fixes the issue of WebMock not matching Typhoeus requests with request method defined as string.
Thanks to Thorbjørn Hermanse
-
Stubbing instructions which are displayed when no matching stub is found, can be disabled with
Config.instance.show_stubbing_instructions = false
Thanks to Mark Lorenz
-
Notation used for mapping query strings to data structure can be configured i.e.
WebMock::Config.instance.query_values_notation = :subscript
. This allows setting:flat_array
notation which supports duplicated parameter names in query string.Thanks to tjsousa
-
Updated dependency on Addressable to versions >= 2.3.6
-
Added support for matching uris using RFC 6570 (URI Templates)
uri_template = Addressable::Template.new "www.example.com/{id}/" stub_request(:any, uri_template)
Thanks to Max Lincoln
-
Fixed content length calculation for Rack responses with UTF8 body
Thanks to Oleg Gritsenko
-
Add missing Curl::Easy aliases
Thanks to Hwan-Joon Choi
-
HTTP Gem >= 0.6.0 compatibility
Thanks to Aleksey V. Zapparov
-
Minitest 4 and 5 compatibility.
Thanks to SHIBATA Hiroshi
-
Update matchers for RSpec 3's matcher protocol
Thanks to Rob Olson
-
Fixed issue with Rack response removing 'Content-Type' header
Thanks to Bo Jeanes and Matthew Conway
-
Support for chunked responses in Curb
Thanks to Zachary Belzer
-
Fixed handling of request body passed as a hash to
Typhoeus.post
Thanks to Mason Chang for reporting.
-
Added missing license statements.
Thanks to Praveen Arimbrathodiyil
-
HTTP gem support!
Thanks to Aleksey V. Zapparov
-
Limited Excon gem requirement to version < 0.30 until the compatibility with version > 0.30.0 is fixed.
Thanks to Aleksey V. Zapparov
-
Fixed issue where empty query key caused a
TypeError
Thanks to Jon Rowe
-
Handling Typhoeus
on_headers
andon_body
params.Thanks to Matt Burke
-
Fixed "NameError: uninitialized constant WebMock::Response::Pathname" issue.
Thanks to Alex Stupakow and Karen Wang for the fix.
-
Allow a Pathname to be passed as a Response body
stub_request(:get, /example.com/).to_return( body: Rails.root.join('test/fixtures/foo.txt') )
Thanks to Ben Pickles
-
hash_including
matcher can be initialized with empty keys to match any values.stub_request(:post, "www.example.com").with(:body => hash_including(:a, :b => {'c'})) RestClient.post('www.example.com', '{"a":"1","b":"c"}', :content_type => 'application/json')
Thanks to Stefano Uliari
-
Fixed
hash_including
to accept a splat of solitary keys.Thanks to Tamir Duberstein and https://github.com/strongriley
-
Excon >= 0.27.5 compatibility.
Thanks to Brian D. Burns
-
Handling non UTF-8 characters in query params.
Thanks to Florian Dütsch for reporting the issue.
-
Added support for
request_block
param in ExconThanks to Dmitry Gutov for reporting the issue.
-
Fixed compatibility with latest Curb
Thanks to Ian Lesperance and Matthew Horan
-
Triggering errbacks assynchronously in em-http-request adapter.
Thanks to Ian Lesperance and Matthew Horan
-
Handling query params with a hashes nested inside arrays.
Thanks to Ian Asaff
-
Changed NetConnectNotAllowedError to inherit from Exception to allow it to bubble up into a test suite.
Thanks to Daniel van Hoesel
-
HTTPClient adapter is thread safe.
Thanks to Tom Beauvais
- Net::HTTP::Persistent compatibility. WebMock doesn't disconnect previously started connections upon a request anymore.
-
Fixed issue with handling Addressable::URI with query params passed to
Net::HTTP.get_response
Thanks to Leif Bladt
-
Fixed HTTPClient adapter to not raise an error if a request with multipart body is executed.
-
Fixed issue with handling request.path when Addressable::URI is passed to #request instead of URI with Ruby 2.0.
Thanks to Leif Bladt
-
Accept integers as query param values in request stubs
i.e.
stub_request(:get, /.*/).with(:query => {"a" => 1})
Thanks to Mitsutaka Mimura
-
Fixed Minitest < 5.0 compatibility
Thanks to Alex Tomlins for reporting the issue.
-
Not using Gem spec anymore to check loaded Curb version.
-
WebMock.disable_net_connect!
now accepts array of regexps as allow param:i.e.
WebMock.disable_net_connect!(:allow => [/google.com/, /yahoo.com/])
Thanks to Bastien Vaucher
-
Fixed
on_header
Curb callback behaviour in Curb adapterThanks to Joel Chippindale
-
Fixed aws-sdk compatibility with Ruby 2.0, by supporting
continue_timeout
accessor on Net::HTTP socket.Thanks to Lin Jen-Shin
-
Fixed WebMock::Server to not give "log writing failed. can't be called from trap context" warning with Ruby 2.0
Thanks to Murahashi Sanemat Kenichi
-
Added support for EM-HTTP-Request streaming data off disk feature.
Thanks to Lin Jen-Shin
-
Added compatibility with Minitest 5
Thanks to Tim Kurvers
-
Excon >= 0.22 compatibility.
-
README has nice sytnax hightlighting and fixed code styling!
Thanks to Ilya Vassilevsky
-
Compatibility with Rails 4
rack.session.options
Thanks to gotwalt
-
Excon >= 0.17 support.
Thanks to Nathan Sutton for reporting this issue and to Wesley Beary and Myron Marston for help.
- '+' in request path is treated as plus, but in query params always as a space.
-
'+' in request body is still treated as a space. This fixes a bug introduced in previous version.
Thanks to Erik Michaels-Ober for reporting this problem.
-
Fixed issue: response body declared as Proc was not evaluated again on subsequent requests.
Thanks to Rick Fletcher for reporting this issue.
-
'+' in query params is not treated as space anymore and is encoded as %2B
Thanks to goblin for reporting this issue.
-
added
remove_request_stub
method to the api to allow removing unused stubs i.e.stub_get = stub_request(:get, "www.example.com") remove_request_stub(stub_get)
-
assert_requested
andassert_not_requested
raise an error if a stub object is provided together with a block.
-
Fixed issue with unavailable constant Mutex in Ruby < 1.9
Thanks to Lucas Dohmen for reporting this issue.
-
Added support for Excon's :response_block parameter
Thanks to Myron Marston for reporting this issue.
-
Fix 'rack.errors' not being set for Rack apps
Thanks to Alex Grant
-
Added support for minitest assertions count
Thanks to Mokevnin Kirill
-
Fixed issues with registering http requests in multi-threaded environments
Thanks to Tom Beauvais
-
Bumped Crack version to >=0.3.2
Thanks to Jake Benilov
-
Fixed issues in Typhoeus 0.6. Defaulted method to GET when no method specified.
Thanks to Hans Hasselberg
-
Add license information to the gemspec
Thanks to Jordi Massaguer Pla and Murahashi Sanemat Kenichi
-
Added support for :expects option in Excon adapter
Thanks to Evgeniy Dolzhenko
-
Fixed Faye compatibility by treating StringIO in Net::HTTP adapter properly
Thanks to Pavel Forkert
-
Updated VCR link
Thanks to Rex Feng
-
Added support for Typhoeus >= 0.5.0 and removed support for Typhoeus < 0.5.0.
Thanks to Hans Hasselberg
-
Fix excon adapter to handle
:body => some_file_object
Thanks to Myron Marston
-
em-http-request fix. After request callbacks are correctly invoked for 3xx responses, when :redirects option is set.
Thanks to Myron Marston for reporting that issue.
-
Fixed compatibility with Net::HTTP::DigestAuth
Thanks to Jonathan Hyman for reporting that issue.
-
Fixed problem in em-http-request 0.x appending the query to the client URI twice.
Thanks to Paweł Pierzchała
-
Fixed problem with caching nil responses when the same HTTPClient instance is used.
Thanks to Myron Marston
-
Added support for Addressable >= 2.3.0. Addressable 2.3.0 removed support for multiple query value notations and broke backwards compatibility.
https://github.com/sporkmonger/addressable/commit/f51e290b5f68a98293327a7da84eb9e2d5f21c62 sporkmonger/addressable#77
-
Fixed Net::HTTP adapter so that it returns
nil
for an empty body response.Thanks to Myron Marston
-
Gemspec defines compatibility with Addressable ~> 2.2.8, not >= 2.3.0
-
Specs compatibility with Typhoeus 0.4.0
Thanks to Hans Hasselberg
-
Handling content types that specify a charset
Thanks to Kevin Glowacz
-
Fixed em-http-request adapter to correctly fetch authorization header from a request
Thanks to Julien Boyer
-
Fixing travis-ci image to report master's status
Thanks to Ryan Schlesinger
-
Fixed problem with em-http-request callback triggering if there were other EM::Deferred callbacks registered
Thanks to Jon Leighton
-
Fixed problem with em-http-request appending the query to the URI a second time, and the parameters are repeated.
Thanks to Jon Leighton
-
Compatibility with RSpec >= 2.10
Thanks to erwanlr for reporting this issue.
-
Add missing required rack environment variable SCRIPT_NAME
Thanks to Eric Oestrich
-
Fixed warnings due to @query_params not being initialized
Thanks to Ben Bleything
-
Pass through SERVER_PORT when stubbing to rack
Thanks to Eric Oestrich
-
Fixed problem with missing parenthesis in
WebMock#net_connect_allowed?
conditions.Thanks to aindustries
-
WebMock::RackResponse supports basic auth
Thanks to jugyo
-
Warning message is printed when an unsupported version of a http library is loaded.
Thanks to Alexander Staubo for reporting the problem and to Myron Marston for a help with solution.
-
Fixed compatibility with latest em-http-request
Thanks to Paul Cortens
-
Prevent Webmock
hash_including
from overriding RSpec version 1hash_including
method.Thanks to Joe Karayusuf
-
Ensured WebMock handles RSpec 1
hash_including
matcher for matching query params and body.
-
Ensured WebMock doesn't interfere with
em-synchrony
, whenem-synchrony/em-http
is not included.Thanks to Nick Recobra
-
Improved README
Thanks to Jordan Elver
-
Matching request body against partial hash.
stub_http_request(:post, "www.example.com"). with(:body => hash_including({:data => {:a => '1', :b => 'five'}})) RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1", :content_type => 'application/x-www-form-urlencoded') # ===> Success request(:post, "www.example.com"). with(:body => hash_including({:data => {:a => '1', :b => 'five'}}), :headers => 'Content-Type' => 'application/json').should have_been_made # ===> Success
Thanks to Marnen Laibow-Koser for help with this solution
-
Matching request query params against partial hash.
stub_http_request(:get, "www.example.com").with(:query => hash_including({"a" => ["b", "c"]})) RestClient.get("http://www.example.com/?a[]=b&a[]=c&x=1") # ===> Success request(:get, "www.example.com"). with(:query => hash_including({"a" => ["b", "c"]})).should have_been_made # ===> Success
-
Added support for Excon.
Thanks to Dimitrij Denissenko
-
Added support for setting expectations on the request stub with
assert_requested
stub_get = stub_request(:get, "www.example.com") stub_post = stub_request(:post, "www.example.com") Net::HTTP.get('www.example.com', '/') assert_requested(stub_get) assert_not_requested(stub_post)
Thanks to Nicolas Fouché
-
WebMock.disable_net_connect!
acceptsRegExp
as:allow
parameterThanks to Frank Schumacher
-
Ensure multiple values for the same header can be recorded and played back
Thanks to Myron Marston
-
Updated dependency on Addressable to version >= 2.2.7 to handle nested hash query values. I.e.
?one[two][three][]=four&one[two][three][]=five
-
Fixed compatibility with Curb >= 0.7.16 This breaks compatibility with Curb < 0.7.16
-
Fix #to_rack to handle non-array response bodies.
Thanks to Tammer Saleh
-
Added
read_timeout
accessor to StubSocket which fixes compatibility with aws-sdkThanks to Lin Jen-Shin
-
Fix warning "instance variable @query_params not initialized"
Thanks to Joe Van Dyk
-
Using bytesize of message instead of its length for content-length header in em-http-request adapter. This fixes a problem with messages getting truncated in Ruby >= 1.9
Thanks to Mark Abramov
-
Fixed problem with body params being matched even if params were different.
Thanks to Evgeniy Dolzhenko for reporting this issue.
- Yanked 1.7.9 and rebuilt gem on 1.8.7 to deal with syck/psych incompatibilties in gemspec.
-
Fixed support for native Typhoeus timeouts.
Thanks to Albert Llop
-
Fixed problem with WebMock and RSpec compatibility on TeamCity servers. See this article for more details.
Thanks to Christopher Pickslay from Two Bit Labs
- Fix each adapter so that it calls a
stub.with
block only once per request. Previously, the block would be called two or three times per request Myron Marston.
-
Passing response object to a block passed to
HTTPClient#do_get_block
. This fixesHTTPClient.get_content
failures. issue 130Thanks to Chris McGrath
-
Cleaned up ruby warnings when running WebMock code with
-w
.Thanks to Stephen Celis
-
Curb adapter now correctly calls on_failure for 4xx response codes.
Thanks to Eugene Pimenov
-
Support for the HTTPClient's request_filter feature
Thanks to Roman Shterenzon
-
Added support for Patron 0.4.15. This change is not backward compatible so please upgrade Patron to version >= 0.4.15 if you want to use it with WebMock.
Thanks to Andreas Garnæs
-
Added support for matching EM-HTTP-Request requests with body declared as a Hash
Thanks to David Yeu
-
Added
Get
,Post
,Delete
,Put
,Head
,Option
constants to replacedNet::HTTP
to make it possible to marshal objects with these constants assigned to properties. This fixed problem withtvdb_party
gem which serializes HTTParty responses.Thanks to Klaus Hartl for reporting this issue.
- Redefined
const_get
andconstants
methods on the replacedNet::HTTP
to return same values as originalNet::HTTP
-
Redefined
const_defined?
on the replacedNet::HTTP
so that it returns true if constant is defined on the originalNet::HTTP
. This fixes problems with"Net::HTTP::Get".constantize
.Thanks to Cássio Marques for reporting the issue and to Myron Marston for help with the solution.
-
Fixed Net::HTTP adapter to not break normal Net::HTTP behaviour when network connections are allowed. This fixes selenium-webdriver compatibility!!!
-
Added support for EM-HTTP-Request 1.0.x and EM-Synchrony. Thanks to Steve Hull
-
Added support for setting expectations to on a stub itself i.e.
stub = stub_request(:get, "www.example.com") # ... make requests ... stub.should have_been_requested
Thanks to Aidan Feldman
-
Minitest support! Thanks to Peter Higgins
-
Added support for Typhoeus::Hydra
-
Added support for
Curb::Easy#http_post
andCurb::Easy#http_post
with multiple arguments. Thanks to Salvador Fuentes Jr and Alex Rothenberg -
Rack support. Requests can be stubbed to respond with a Rack app i.e.
class MyRackApp def self.call(env) [200, {}, ["Hello"]] end end stub_request(:get, "www.example.com").to_rack(MyRackApp) RestClient.get("www.example.com") # ===> "Hello"
Thanks to Jay Adkisson
-
Added support for selective disabling and enabling of http lib adapters
WebMock.disable! #disable WebMock (all adapters) WebMock.disable!(:except => [:net_http]) #disable WebMock for all libs except Net::HTTP WebMock.enable! #enable WebMock (all adapters) WebMock.enable!(:except => [:patron]) #enable WebMock for all libs except Patron
-
The error message on an unstubbed request shows a code snippet with body as a hash when it was in url encoded form.
> RestClient.post('www.example.com', "data[a]=1&data[b]=2", :content_type => 'application/x-www-form-urlencoded') WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled.... You can stub this request with the following snippet: stub_request(:post, "http://www.example.com/"). with(:body => {"data"=>{"a"=>"1", "b"=>"2"}}, :headers => { 'Content-Type'=>'application/x-www-form-urlencoded' }). to_return(:status => 200, :body => "", :headers => {})
Thanks to Alex Rothenberg
-
The error message on an unstubbed request shows currently registered request stubs.
> stub_request(:get, "www.example.net") > stub_request(:get, "www.example.org") > RestClient.get("www.example.com") WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled.... You can stub this request with the following snippet: stub_request(:get, "http://www.example.com/"). to_return(:status => 200, :body => "", :headers => {}) registered request stubs: stub_request(:get, "http://www.example.net/") stub_request(:get, "http://www.example.org/")
Thanks to Lin Jen-Shin for suggesting this feature.
-
Fixed problem with matching requests with json body, when json strings have date format. Thanks to Joakim Ekberg for reporting this issue.
-
WebMock now attempts to require each http library before monkey patching it. This is to avoid problem when http library is required after WebMock is required. Thanks to Myron Marston for suggesting this change.
-
External requests can be disabled while allowing selected ports on selected hosts
WebMock.disable_net_connect!(:allow => "www.example.com:8080") RestClient.get("www.example.com:80") # ===> Failure RestClient.get("www.example.com:8080") # ===> Allowed.
Thanks to Zach Dennis
-
Fixed syntax error in README examples, showing the ways of setting request expectations. Thanks to Nikita Fedyashev
Many thanks to WebMock co-maintainer James Conroy-Finn who did a great job maintaining WebMock on his own for the last couple of months.
This is a quick slip release to regenerate the gemspec. Apparently
jeweler inserts dependencies twice if you use the gemspec
method in
your Gemfile and declare gem dependencies in your gemspec.
josevalim:
This just bit me. I just released a gem with the wrong dependencies because I have updated jeweler. This should have been opt-in, otherwise a bunch of people using jeweler are going to release gems with the wrong dependencies because you are automatically importing from the Gemfile.
-
Update the dependency on addressable to get around an issue in v2.2.5. Thanks to Peter Higgins.
-
Add support for matching parameter values using a regular expression as well as a string. Thanks to Oleg M Prozorov.
-
Fix integration with httpclient as the internal API has changed. Thanks to Frank Prößdorf.
-
Ensure Curl::Easy#content_type is always set. Thanks to Peter Higgins.
-
Fix bug with em-http-request adapter stubbing responses that have a chunked transfer encoding. Thanks to Myron Marston.
-
Fix a load of spec failures with Patron, httpclient, and specs that depended on the behaviour of example.com. Thanks to Alex Grigorovich.
-
Em-http-request adapter sets
last_effective_url
property. Thanks to Sam Stokes. -
Curb adapter supports
Curb::Easy#http_post
andCurb::Easy#http_put
without arguments (by settingpost_body
orput_data
beforehand). Thanks to Eugene Bolshakov
- Fixed issue with
webmock/rspec
which didn't load correctly ifrspec/core
was already required butrspec/expectations
not.
-
Simplified integration with Test::Unit, RSpec and Cucumber. Now only a single file has to be required i.e.
require 'webmock/test_unit' require 'webmock/rspec' require 'webmock/cucumber'
-
The error message on unstubbed request now contains code snippet which can be used to stub this request. Thanks to Martyn Loughran for suggesting this feature.
-
The expectation failure message now contains a list of made requests. Thanks to Martyn Loughran for suggesting this feature.
-
Added
WebMock.print_executed_requests
method which can be useful to find out what requests were made until a given point. -
em-http-request adapter is now activated by replacing EventMachine::HttpRequest constant, instead of monkeypatching the original class.
This technique is borrowed from em-http-request native mocking module. It allows switching WebMock adapter on an off, and using it interchangeably with em-http-request native mocking i.e:
EventMachine::WebMockHttpRequest.activate!
EventMachine::WebMockHttpRequest.deactivate!
Thanks to Martyn Loughran for suggesting this feature.
-
WebMock.reset_webmock
is deprecated in favour of newWebMock.reset!
-
Fixed integration with Cucumber. Previously documented example didn't work with new versions of Cucumber.
-
Fixed stubbing requests with body declared as a hash. Thanks to Erik Michaels-Ober for reporting the issue.
-
Fixed issue with em-http-request adapter which didn't work when :query option value was passed as a string, not a hash. Thanks to Chee Yeo for reporting the issue.
-
Fixed problem with assert_requested which didn't work if used outside rspec or test/unit
-
Removed dependency on json gem
-
Support for dynamically evaluated raw responses recorded with
curl -is
i.e.`curl -is www.example.com > /tmp/www.example.com.txt` stub_request(:get, "www.example.com").to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt" }))
-
:net_http_connect_on_start
option can be passed toWebMock.allow_net_connect!
andWebMock.disable_net_connect!
methods, i.e.WebMock.allow_net_connect!(:net_http_connect_on_start => true)
This forces WebMock Net::HTTP adapter to always connect on
Net::HTTP.start
. Check 'Connecting on Net::HTTP.start' in README for more information.Thanks to Alastair Brunton for reporting the issue and for fix suggestions.
-
Fixed an issue where Patron spec tried to remove system temporary directory. Thanks to Hans de Graaff
-
WebMock specs now use RSpec 2
-
rake spec NO_CONNECTION=true
can now be used to only run WebMock specs which do not make real network connections
-
Curb support!!! Thanks to the awesome work of Pete Higgins!
-
include WebMock
is now deprecated to avoid method and constant name conflicts. Pleaseinclude WebMock::API
instead. -
WebMock::API#request
is renamed toWebMock::API#a_request
to prevent method name conflicts with i.e. Rails controller specs. WebMock.request is still available. -
Deprecated
WebMock#request
,WebMock#allow_net_connect!
,WebMock#net_connect_allowed?
,WebMock#registered_request?
,WebMock#reset_callbacks
,WebMock#after_request
instance methods. These methods are still available, but only as WebMock class methods. -
Removed
WebMock.response_for_request
andWebMock.assertion_failure
which were only used internally and were not documented. -
:allow_localhost => true' now permits 0.0.0.0 in addition to 127.0.0.1 and 'localhost'. Thanks to Myron Marston and Mike Gehard for suggesting this.
-
Fixed issue with both RSpec 1.x and 2.x being available.
WebMock now tries to use already loaded version of RSpec (1.x or 2.x). Previously it was loading RSpec 2.0 if available, even if RSpec 1.3 was already loaded.
Thanks to Hans de Graaff for reporting this.
-
Changed runtime dependency on Addressable version 2.2.2 which fixes handling of percent-escaped '+'
-
External requests can be disabled while allowing selected hosts. Thanks to Charles Li and Ryan Bigg
This feature was available before only for localhost with
:allow_localhost => true
WebMock.disable_net_connect!(:allow => "www.example.org") Net::HTTP.get('www.something.com', '/') # ===> Failure Net::HTTP.get('www.example.org', '/') # ===> Allowed.
-
Fixed Net::HTTP adapter so that it preserves the original behavior of Net::HTTP.
When making a request with a block that calls #read_body on the request, Net::HTTP causes the body to be set to a Net::ReadAdapter, but WebMock was causing the body to be set to a string.
- Fixed Net::HTTP adapter to handle cases where a block with
read_body
call is passed torequest
. This fixes compatibility withopen-uri
. Thanks to Mark Evans for reporting the issue.
- Fixed handling of multiple values for the same response header for Net::HTTP. Thanks to Myron Marston for reporting the issue.
- Fixed compatibility with EM-HTTP-Request >= 0.2.9. Thanks to Myron Marston for reporting the issue.
-
The less hacky way to get the stream behaviour working for em-http-request. Thanks to Martyn Loughran
-
Fixed issues where Net::HTTP was not accepting valid nil response body. Thanks to Muness Alrubaie
-
Added support for em-http-request
-
Matching query params using a hash
stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}) RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made # ===> Success
-
Matching request body against a hash. Body can be URL-Encoded, JSON or XML.
(Thanks to Steve Tooke for the idea and a solution for url-encoded bodies)
stub_http_request(:post, "www.example.com"). with(:body => {:data => {:a => '1', :b => 'five'}}) RestClient.post('www.example.com', "data[a]=1&data[b]=five", :content_type => 'application/x-www-form-urlencoded') # ===> Success RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}', :content_type => 'application/json') # ===> Success RestClient.post('www.example.com', '<data a="1" b="five" />', :content_type => 'application/xml' ) # ===> Success request(:post, "www.example.com"). with(:body => {:data => {:a => '1', :b => 'five'}}, :headers => 'Content-Type' => 'application/json').should have_been_made # ===> Success
-
Request callbacks (Thanks to Myron Marston for all suggestions)
WebMock can now invoke callbacks for stubbed or real requests:
WebMock.after_request do |request_signature, response| puts "Request #{request_signature} was made and #{response} was returned" end
invoke callbacks for real requests only and except requests made with Patron client
WebMock.after_request(:except => [:patron], :real_requests_only => true) do |request_signature, response| puts "Request #{request_signature} was made and #{response} was returned" end
-
to_raise()
now accepts an exception instance or a string as argument in addition to an exception classstub_request(:any, 'www.example.net').to_raise(StandardError.new("some error")) stub_request(:any, 'www.example.net').to_raise("some error")
-
Matching requests based on a URI is 30% faster
-
Fixed constant namespace issues in HTTPClient adapter. Thanks to Nathaniel Bibler for submitting a patch.
- Fixed problem where ArgumentError was raised if query params were made up of an array e.g. data[]=a&data[]=b. Thanks to Steve Tooke
-
Changed license from GPL to MIT
-
Fixed gemspec file. Thanks to Razic
-
RSpec 2 compatibility. Thanks to Sam Phillips!
-
:allow_localhost => true' now permits 127.0.0.1 as well as 'localhost'. Thanks to Mack Earnhardt
-
Request URI matching in now 2x faster!
-
VCR compatibility. Many thanks to Myron Marston for all suggestions.
-
Support for stubbing requests and returning responses with multiple headers with the same name. i.e multiple Accept headers.
stub_http_request(:get, 'www.example.com'). with(:headers => {'Accept' => ['image/png', 'image/jpeg']}). to_return(:body => 'abc') RestClient.get('www.example.com', {"Accept" => ['image/png', 'image/jpeg']}) # ===> "abc\n"
-
When real net connections are disabled and unstubbed request is made, WebMock throws WebMock::NetConnectNotAllowedError instead of assertion error or StandardError.
-
Added WebMock.version()
-
Added support for Patron
-
Responses dynamically evaluated from block (idea and implementation by Tom Ward)
stub_request(:any, 'www.example.net'). to_return { |request| {:body => request.body} } RestClient.post('www.example.net', 'abc') # ===> "abc\n"
-
Responses dynamically evaluated from lambda (idea and implementation by Tom Ward)
stub_request(:any, 'www.example.net'). to_return(lambda { |request| {:body => request.body} }) RestClient.post('www.example.net', 'abc') # ===> "abc\n"
-
Response with custom status message
stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"]) req = Net::HTTP::Get.new("/") Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
-
Raising timeout errors (suggested by Jeffrey Jones) (compatibility with Ruby 1.8.6 by Mack Earnhardt)
stub_request(:any, 'www.example.net').to_timeout RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
-
External requests can be disabled while allowing localhost (idea and implementation by Mack Earnhardt)
WebMock.disable_net_connect!(:allow_localhost => true) Net::HTTP.get('www.something.com', '/') # ===> Failure Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
- Fixed issue where Net::HTTP adapter didn't work for requests with body responding to read (reported by Tekin Suleyman)
- Fixed issue where request stub with headers declared as nil was matching requests with non empty headers
- Fixed issue where response status code was not read from raw (curl -is) responses
-
Matching requests against provided block (by Sergio Gil)
stub_request(:post, "www.example.com").with { |request| request.body == "abc" }.to_return(:body => "def") RestClient.post('www.example.com', 'abc') # ===> "def\n" request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made #or assert_requested(:post, "www.example.com") { |req| req.body == "abc" }
-
Matching request body against regular expressions (suggested by Ben Pickles)
stub_request(:post, "www.example.com").with(:body => /^.*world$/).to_return(:body => "abc") RestClient.post('www.example.com', 'hello world') # ===> "abc\n"
-
Matching request headers against regular expressions (suggested by Ben Pickles)
stub_request(:post, "www.example.com").with(:headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc") RestClient.post('www.example.com', '', {'Content-Type' => 'image/png'}) # ===> "abc\n"
-
Replaying raw responses recorded with
curl -is
`curl -is www.example.com > /tmp/example_curl_-is_output.txt` raw_response_file = File.new("/tmp/example_curl_-is_output.txt") from file stub_request(:get, "www.example.com").to_return(raw_response_file) or string stub_request(:get, "www.example.com").to_return(raw_response_file.read)
-
Multiple responses for repeated requests
stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"}) Net::HTTP.get('www.example.com', '/') # ===> "abc\n" Net::HTTP.get('www.example.com', '/') # ===> "def\n"
-
Multiple responses using chained
to_return()
orto_raise()
declarationsstub_request(:get, "www.example.com"). to_return({:body => "abc"}).then. #then() just is a syntactic sugar to_return({:body => "def"}).then. to_raise(MyException) Net::HTTP.get('www.example.com', '/') # ===> "abc\n" Net::HTTP.get('www.example.com', '/') # ===> "def\n" Net::HTTP.get('www.example.com', '/') # ===> MyException raised
-
Specifying number of times given response should be returned
stub_request(:get, "www.example.com"). to_return({:body => "abc"}).times(2).then. to_return({:body => "def"}) Net::HTTP.get('www.example.com', '/') # ===> "abc\n" Net::HTTP.get('www.example.com', '/') # ===> "abc\n" Net::HTTP.get('www.example.com', '/') # ===> "def\n"
-
Added support for
Net::HTTP::Post#body_stream
This fixes compatibility with new versions of RestClient
-
WebMock doesn't suppress default request headers added by http clients anymore.
i.e. Net::HTTP adds `'Accept'=>'*/*'` to all requests by default
- Fixed issue where WebMock was not closing IO object passed as response body after reading it.
- Ruby 1.9.2 compat: Use
File#expand_path
for require path because "." is not be included in LOAD_PATH since Ruby 1.9.2
- Fixed HTTPClient adapter compatibility with Ruby 1.8.6 (reported by Piotr Usewicz)
- Net:HTTP adapter now handles request body assigned as Net::HTTP::Post#body attribute (fixed by Mack Earnhardt)
- Fixed issue where requests were not matching stubs with Accept header set.(reported by Piotr Usewicz)
- Fixed compatibility with Ruby 1.9.1, 1.9.2 and JRuby 1.3.1 (reported by Diego E. “Flameeyes” Pettenò)
- Fixed issue with response body declared as IO object and multiple requests (reported by Niels Meersschaert)
- Fixed "undefined method `assertion_failure'" error (reported by Nick Plante)
- Support for HTTPClient (sync and async requests)
- Support for dynamic responses. Response body and headers can be now declared as lambda. (Thanks to Ivan Vega ( @ivanyv ) for suggesting this feature)
- Support for stubbing and expecting requests with empty body
- Executing non-stubbed request leads to failed expectation instead of error
- Basic authentication now works correctly
- Fixed problem where WebMock didn't call a block with the response when block was provided
- Fixed problem where uris with single slash were not matching uris without path provided
- Clarified documentation
- Fixed some issues with loading of Webmock classes
- Test::Unit and RSpec adapters have to be required separately
- Added support for matching escaped and non escaped URLs