Skip to content

Loading…

Fix hash_including for rspec 1 #320

Merged
merged 2 commits into from

4 participants

@tamird

Alternative approach to #319 -- prevents webmock from overwriting hash_including from rspec. Fixes an edge case where a splat of solitary keys is passed to the method when using rspec 1.3.2.

@strongriley

Thanks @tamird - this seems like a better approach. Closing mine. @bblimke does this look good to you?

@tamird

@bblimke updated this pull to be less dependent on conditions at load-time. This should make it more resilient in the case where webmock is loaded, then rspec is loaded, then rspec is mixed in, and finally webmock is mixed in (the rspec implementation will still be used, now).

WDYT?

@strongriley

:+1: This seems more robust.

@bblimke
Owner

Clever! :)

@bblimke bblimke merged commit 9ec2fb1 into bblimke:master

1 check passed

Details default The Travis CI build passed
@tamird tamird deleted the unknown repository branch
@tamird

@bblimke thanks! would you mind cutting a release including this fix?

@bblimke
Owner

Released as 1.15.1. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 27, 2013
  1. @tamird

    Fix rspec deprecation warnings

    tamird committed
Commits on Oct 28, 2013
  1. @tamird
Showing with 15 additions and 16 deletions.
  1. +10 −11 lib/webmock/api.rb
  2. +5 −5 spec/unit/errors_spec.rb
View
21 lib/webmock/api.rb
@@ -15,8 +15,17 @@ def a_request(method, uri)
class << self
alias :request :a_request
- end
+ def included(mod)
+ unless mod.respond_to?(:hash_including)
+ mod.class_eval do
+ def hash_including(expected)
+ WebMock::Matchers::HashIncludingMatcher.new(expected)
+ end
+ end
+ end
+ end
+ end
def assert_requested(*args, &block)
if not args[0].is_a?(WebMock::RequestStub)
@@ -36,16 +45,6 @@ def assert_not_requested(*args, &block)
assert_request_not_requested(*args)
end
- def hash_including(expected)
- if defined?(::RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
- elsif defined?(::Spec::Mocks::ArgumentMatchers::HashIncludingMatcher)
- Spec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
- else
- WebMock::Matchers::HashIncludingMatcher.new(expected)
- end
- end
-
def remove_request_stub(stub)
WebMock::StubRegistry.instance.remove_request_stub(stub)
end
View
10 spec/unit/errors_spec.rb
@@ -29,11 +29,11 @@
end
it "should not be caught by a rescue block without arguments" do
- request_signature = mock(:to_s => "aaa")
- request_stub = mock
- WebMock::RequestStub.stub!(:from_request_signature).and_return(request_stub)
- WebMock::StubRequestSnippet.stub!(:new).
- with(request_stub).and_return(mock(:to_s => "bbb"))
+ request_signature = double(:to_s => "aaa")
+ request_stub = double
+ WebMock::RequestStub.stub(:from_request_signature).and_return(request_stub)
+ WebMock::StubRequestSnippet.stub(:new).
+ with(request_stub).and_return(double(:to_s => "bbb"))
exception = WebMock::NetConnectNotAllowedError.new(request_signature)
Something went wrong with that request. Please try again.