Parent

Files

WebMock::BodyPattern

Constants

BODY_FORMATS

Public Class Methods

new(pattern) click to toggle source
     # File lib/webmock/request_pattern.rb, line 133
133:     def initialize(pattern)
134:       @pattern = pattern
135:       if (@pattern).is_a?(Hash)
136:         @pattern = normalize_hash(@pattern)
137:       end
138:     end

Public Instance Methods

matches?(body, content_type = "") click to toggle source
     # File lib/webmock/request_pattern.rb, line 140
140:     def matches?(body, content_type = "")
141:       if (@pattern).is_a?(Hash)
142:         return true if @pattern.empty?
143: 
144:         case BODY_FORMATS[content_type]
145:         when :json then
146:           Crack::JSON.parse(body) == @pattern
147:         when :xml then
148:           Crack::XML.parse(body) == @pattern
149:         else
150:           Addressable::URI.parse('?' + body).query_values == @pattern
151:         end
152:       else
153:         empty_string?(@pattern) && empty_string?(body) ||
154:           @pattern == body ||
155:           @pattern === body
156:       end
157:     end
to_s() click to toggle source
     # File lib/webmock/request_pattern.rb, line 159
159:     def to_s
160:       @pattern.inspect
161:     end

Private Instance Methods

empty_string?(string) click to toggle source
     # File lib/webmock/request_pattern.rb, line 165
165:     def empty_string?(string)
166:       string.nil? || string == ""
167:     end
normalize_hash(hash) click to toggle source
     # File lib/webmock/request_pattern.rb, line 169
169:     def normalize_hash(hash)
170:       JSON.parse(JSON.generate(hash))
171:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.