WebMock v1.7.0 Release Notes
-
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.