Class: WebMock::BodyPattern
- Inherits:
-
Object
- Object
- WebMock::BodyPattern
- Includes:
- RSpecMatcherDetector
- Defined in:
- lib/webmock/request_pattern.rb
Constant Summary collapse
- BODY_FORMATS =
{ 'text/xml' => :xml, 'application/xml' => :xml, 'application/json' => :json, 'text/json' => :json, 'application/javascript' => :json, 'text/javascript' => :json, 'text/html' => :html, 'application/x-yaml' => :yaml, 'text/yaml' => :yaml, 'text/plain' => :plain }
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern) ⇒ BodyPattern
constructor
A new instance of BodyPattern.
- #matches?(body, content_type = "") ⇒ Boolean
- #to_s ⇒ Object
Methods included from RSpecMatcherDetector
#rSpecHashExcludingMatcher?, #rSpecHashIncludingMatcher?
Constructor Details
#initialize(pattern) ⇒ BodyPattern
Returns a new instance of BodyPattern.
239 240 241 242 243 244 245 246 247 |
# File 'lib/webmock/request_pattern.rb', line 239 def initialize(pattern) @pattern = if pattern.is_a?(Hash) normalize_hash(pattern) elsif rSpecHashIncludingMatcher?(pattern) WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(pattern) else pattern end end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
237 238 239 |
# File 'lib/webmock/request_pattern.rb', line 237 def pattern @pattern end |
Instance Method Details
#matches?(body, content_type = "") ⇒ Boolean
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/webmock/request_pattern.rb', line 249 def matches?(body, content_type = "") assert_non_multipart_body(content_type) if (@pattern).is_a?(Hash) return true if @pattern.empty? matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type) elsif (@pattern).is_a?(WebMock::Matchers::HashIncludingMatcher) @pattern == body_as_hash(body, content_type) else empty_string?(@pattern) && empty_string?(body) || @pattern == body || @pattern === body end end |
#to_s ⇒ Object
264 265 266 |
# File 'lib/webmock/request_pattern.rb', line 264 def to_s @pattern.inspect end |