Skip to content

Commit

Permalink
Simpler way of checking whether body or query pattern is an RSpec Has…
Browse files Browse the repository at this point in the history
…hIncludingMatcher
  • Loading branch information
bblimke committed Mar 17, 2012
1 parent 369554f commit 0fe3c02
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/webmock/request_pattern.rb
@@ -1,5 +1,11 @@
module WebMock

module RSpecMatcherDetector
def rSpecHashIncludingMatcher?(matcher)
matcher.class.name =~ /R?Spec::Mocks::ArgumentMatchers::HashIncludingMatcher/
end
end

class RequestPattern

attr_reader :method_pattern, :uri_pattern, :body_pattern, :headers_pattern
Expand Down Expand Up @@ -73,6 +79,8 @@ def to_s


class URIPattern
include RSpecMatcherDetector

def initialize(pattern)
@pattern = pattern.is_a?(Addressable::URI) ? pattern : WebMock::Util::URI.normalize_uri(pattern)
end
Expand All @@ -82,8 +90,7 @@ def add_query_params(query_params)
query_params
elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher)
query_params
elsif (defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && query_params.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)) ||
(defined?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher) && query_params.is_a?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher))
elsif rSpecHashIncludingMatcher?(query_params)
WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(query_params)
else
Addressable::URI.parse('?' + query_params).query_values
Expand Down Expand Up @@ -145,6 +152,7 @@ def to_s


class BodyPattern
include RSpecMatcherDetector

BODY_FORMATS = {
'text/xml' => :xml,
Expand All @@ -162,8 +170,7 @@ class BodyPattern
def initialize(pattern)
@pattern = if pattern.is_a?(Hash)
normalize_hash(pattern)
elsif (defined?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher) && pattern.is_a?(RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)) ||
(defined?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher) && pattern.is_a?(Spec::Mocks::ArgumentMatchers::HashIncludingMatcher))
elsif rSpecHashIncludingMatcher?(pattern)
WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(pattern)
else
pattern
Expand Down

0 comments on commit 0fe3c02

Please sign in to comment.