Class: Esse::RSpec::Matchers::EsseReceiveRequest
- Inherits:
-
Object
- Object
- Esse::RSpec::Matchers::EsseReceiveRequest
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/esse/rspec/matchers.rb
Constant Summary collapse
- STATUS_ERRORS =
{ 300 => Esse::Transport::MultipleChoicesError, 301 => Esse::Transport::MovedPermanentlyError, 302 => Esse::Transport::FoundError, 303 => Esse::Transport::SeeOtherError, 304 => Esse::Transport::NotModifiedError, 305 => Esse::Transport::UseProxyError, 307 => Esse::Transport::TemporaryRedirectError, 308 => Esse::Transport::PermanentRedirectError, 400 => Esse::Transport::BadRequestError, 401 => Esse::Transport::UnauthorizedError, 402 => Esse::Transport::PaymentRequiredError, 403 => Esse::Transport::ForbiddenError, 404 => Esse::Transport::NotFoundError, 405 => Esse::Transport::MethodNotAllowedError, 406 => Esse::Transport::NotAcceptableError, 407 => Esse::Transport::ProxyAuthenticationRequiredError, 408 => Esse::Transport::RequestTimeoutError, 409 => Esse::Transport::ConflictError, 410 => Esse::Transport::GoneError, 411 => Esse::Transport::LengthRequiredError, 412 => Esse::Transport::PreconditionFailedError, 413 => Esse::Transport::RequestEntityTooLargeError, 414 => Esse::Transport::RequestURITooLongError, 415 => Esse::Transport::UnsupportedMediaTypeError, 416 => Esse::Transport::RequestedRangeNotSatisfiableError, 417 => Esse::Transport::ExpectationFailedError, 418 => Esse::Transport::ImATeapotError, 421 => Esse::Transport::TooManyConnectionsFromThisIPError, 426 => Esse::Transport::UpgradeRequiredError, 450 => Esse::Transport::BlockedByWindowsParentalControlsError, 494 => Esse::Transport::RequestHeaderTooLargeError, 497 => Esse::Transport::HTTPToHTTPSError, 499 => Esse::Transport::ClientClosedRequestError, 500 => Esse::Transport::InternalServerError, 501 => Esse::Transport::NotImplementedError, 502 => Esse::Transport::BadGatewayError, 503 => Esse::Transport::ServiceUnavailableError, 504 => Esse::Transport::GatewayTimeoutError, 505 => Esse::Transport::HTTPVersionNotSupportedError, 506 => Esse::Transport::VariantAlsoNegotiatesError, 510 => Esse::Transport::NotExtendedError }
Instance Method Summary collapse
- #and_call_original ⇒ Object
- #and_raise(error_class, response = nil) ⇒ Object
- #and_raise_http_status(status, response = nil) ⇒ Object
- #and_return(response) ⇒ Object
- #at_least(times) ⇒ Object
- #at_most(times) ⇒ Object
- #description ⇒ Object
- #exactly(times) ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(*args) ⇒ EsseReceiveRequest
constructor
A new instance of EsseReceiveRequest.
- #matches?(index_or_cluster) ⇒ Boolean
- #once ⇒ Object
- #twice ⇒ Object
- #with(definition) ⇒ Object
Constructor Details
#initialize(*args) ⇒ EsseReceiveRequest
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/esse/rspec/matchers.rb', line 53 def initialize(*args) @transport_method = args.shift unless Esse::Transport.instance_methods.include?(@transport_method) raise ArgumentError, "expected #{@transport_method.inspect} to be a Esse::Transport method" end @definition = {} if (hash = args.last).is_a?(Hash) @definition.merge!(hash.transform_keys(&:to_sym)) end end |
Instance Method Details
#and_call_original ⇒ Object
103 104 105 106 |
# File 'lib/esse/rspec/matchers.rb', line 103 def and_call_original @and_call_original = true self end |
#and_raise(error_class, response = nil) ⇒ Object
97 98 99 100 101 |
# File 'lib/esse/rspec/matchers.rb', line 97 def and_raise(error_class, response = nil) @error_class = error_class @response = response if response self end |
#and_raise_http_status(status, response = nil) ⇒ Object
84 85 86 87 88 |
# File 'lib/esse/rspec/matchers.rb', line 84 def and_raise_http_status(status, response = nil) @error_class = STATUS_ERRORS[status] || Esse::Transport::ServerError @response = response if response self end |
#and_return(response) ⇒ Object
91 92 93 94 |
# File 'lib/esse/rspec/matchers.rb', line 91 def and_return(response) @response = response self end |
#at_least(times) ⇒ Object
122 123 124 125 |
# File 'lib/esse/rspec/matchers.rb', line 122 def at_least(times) @at_least = times self end |
#at_most(times) ⇒ Object
128 129 130 131 |
# File 'lib/esse/rspec/matchers.rb', line 128 def at_most(times) @at_most = times self end |
#description ⇒ Object
65 66 67 |
# File 'lib/esse/rspec/matchers.rb', line 65 def description "esse receive request" end |
#exactly(times) ⇒ Object
108 109 110 111 |
# File 'lib/esse/rspec/matchers.rb', line 108 def exactly(times) @times = times self end |
#failure_message ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/esse/rspec/matchers.rb', line 133 def "expected that #{@cluster.id} cluster would receive `#{@transport_method}` with #{@definition}".tap do |str| if @error_class str << " and raise #{@error_class}" str << " with #{@response}" if @response elsif @response str << " and return #{@response}" end end end |
#failure_message_when_negated ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/esse/rspec/matchers.rb', line 144 def "expected that #{@cluster.id} cluster would not receive `#{@transport_method}` with #{@definition}".tap do |str| if @error_class str << " and raise #{@error_class}" str << " with #{@response}" if @response elsif @response str << " and return #{@response}" end end end |
#matches?(index_or_cluster) ⇒ Boolean
69 70 71 72 73 74 |
# File 'lib/esse/rspec/matchers.rb', line 69 def matches?(index_or_cluster) normalize_actual_args!(index_or_cluster) allow(@cluster).to receive(:api).and_return(transport) allow(transport).to receive_expected receive_expected.matches?(transport) end |
#once ⇒ Object
113 114 115 |
# File 'lib/esse/rspec/matchers.rb', line 113 def once exactly(1) end |
#twice ⇒ Object
117 118 119 |
# File 'lib/esse/rspec/matchers.rb', line 117 def twice exactly(2) end |
#with(definition) ⇒ Object
77 78 79 80 |
# File 'lib/esse/rspec/matchers.rb', line 77 def with(definition) @definition.update(definition.transform_keys(&:to_sym)) self end |