class WebTrap::RSpec::Matchers::SendRequest
@api private Provides the implementation for send_request
.
Not intended to be instantiated directly.
@see www.rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol RSpec
Matcher Protocol
Public Class Methods
Initialize a new matcher.
Unless more constraints are chained, this matcher will pass as long as any HTTP request gets intercepted.
@see Shared::Validators::RequestSentValidator
# File lib/webtrap/rspec/matchers/send_request.rb, line 23 def initialize add_validator(Shared::Validators::RequestSentValidator.new) end
Public Instance Methods
@api private Message to be shown if no request is intercepted for which all validators are successful.
@return [String]
# File lib/webtrap/rspec/matchers/send_request.rb, line 62 def failure_message return if failed_validator.nil? failed_validator.failure_message end
@api private Whether a request was intercepted that matches all validators.
Executes the provided proc, intercepting all transmitted HTTP requests and running them through the set of validators.
@param transmission_proc [Proc]
The proc that is expected to send the requests.
@return {Boolean}
# File lib/webtrap/rspec/matchers/send_request.rb, line 52 def matches?(transmission_proc) perform_transmission(transmission_proc) failure_message.nil? end
@api private Allows the matcher to be used with block expectations.
@return [true]
# File lib/webtrap/rspec/matchers/send_request.rb, line 71 def supports_block_expectations? true end
@api public Specifies the XML payload of the request.
The expectation will pass only if a request is sent with a payload that is considered equivalent to the reference.
@param xml [String]
The reference XML payload.
@return [SendRequest]
This matcher instance, to allow further chaining.
@see Shared::Validators::EquivalentXmlContentValidator
# File lib/webtrap/rspec/matchers/send_request.rb, line 38 def with_xml(xml) add_validator(Shared::Validators::EquivalentXmlContentValidator.new(xml)) self end
Private Instance Methods
# File lib/webtrap/rspec/matchers/send_request.rb, line 81 def add_validator(validator) validators << validator end
# File lib/webtrap/rspec/matchers/send_request.rb, line 98 def app @_app ||= Shared::RackApp.new(validators) end
# File lib/webtrap/rspec/matchers/send_request.rb, line 85 def failed_validator validators.find(&:failed?) end
# File lib/webtrap/rspec/matchers/send_request.rb, line 89 def perform_transmission(transmission_proc) WebMock.disable_net_connect! WebMock::API.stub_request(:any, /.*/).to_rack(app) transmission_proc.call WebMock.allow_net_connect! end
# File lib/webtrap/rspec/matchers/send_request.rb, line 77 def validators @_validators ||= [] end