Class: WebMock::RequestPattern
- Inherits:
-
Object
- Object
- WebMock::RequestPattern
- Defined in:
- lib/webmock/request_pattern.rb
Instance Attribute Summary collapse
-
#body_pattern ⇒ Object
readonly
Returns the value of attribute body_pattern.
-
#headers_pattern ⇒ Object
readonly
Returns the value of attribute headers_pattern.
-
#method_pattern ⇒ Object
readonly
Returns the value of attribute method_pattern.
-
#uri_pattern ⇒ Object
readonly
Returns the value of attribute uri_pattern.
Instance Method Summary collapse
-
#initialize(method, uri, options = {}) ⇒ RequestPattern
constructor
A new instance of RequestPattern.
- #matches?(request_signature) ⇒ Boolean
- #to_s ⇒ Object
- #with(options = {}, &block) ⇒ Object
Constructor Details
#initialize(method, uri, options = {}) ⇒ RequestPattern
Returns a new instance of RequestPattern.
19 20 21 22 23 24 25 26 |
# File 'lib/webmock/request_pattern.rb', line 19 def initialize(method, uri, = {}) @method_pattern = MethodPattern.new(method) @uri_pattern = create_uri_pattern(uri) @body_pattern = nil @headers_pattern = nil @with_block = nil () end |
Instance Attribute Details
#body_pattern ⇒ Object (readonly)
Returns the value of attribute body_pattern.
17 18 19 |
# File 'lib/webmock/request_pattern.rb', line 17 def body_pattern @body_pattern end |
#headers_pattern ⇒ Object (readonly)
Returns the value of attribute headers_pattern.
17 18 19 |
# File 'lib/webmock/request_pattern.rb', line 17 def headers_pattern @headers_pattern end |
#method_pattern ⇒ Object (readonly)
Returns the value of attribute method_pattern.
17 18 19 |
# File 'lib/webmock/request_pattern.rb', line 17 def method_pattern @method_pattern end |
#uri_pattern ⇒ Object (readonly)
Returns the value of attribute uri_pattern.
17 18 19 |
# File 'lib/webmock/request_pattern.rb', line 17 def uri_pattern @uri_pattern end |
Instance Method Details
#matches?(request_signature) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/webmock/request_pattern.rb', line 35 def matches?(request_signature) content_type = request_signature.headers['Content-Type'] if request_signature.headers content_type = content_type.split(';').first if content_type @method_pattern.matches?(request_signature.method) && @uri_pattern.matches?(request_signature.uri) && (@body_pattern.nil? || @body_pattern.matches?(request_signature.body, content_type || "")) && (@headers_pattern.nil? || @headers_pattern.matches?(request_signature.headers)) && (@with_block.nil? || @with_block.call(request_signature)) end |
#to_s ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/webmock/request_pattern.rb', line 45 def to_s string = "#{@method_pattern.to_s.upcase}".dup string << " #{@uri_pattern.to_s}" string << " with body #{@body_pattern.to_s}" if @body_pattern string << " with headers #{@headers_pattern.to_s}" if @headers_pattern string << " with given block" if @with_block string end |
#with(options = {}, &block) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/webmock/request_pattern.rb', line 28 def with( = {}, &block) raise ArgumentError.new('#with method invoked with no arguments. Either options hash or block must be specified. Created a block with do..end? Try creating it with curly braces {} instead.') if .empty? && !block_given? () @with_block = block self end |