Class: Savon::MockExpectation
- Inherits:
-
Object
- Object
- Savon::MockExpectation
- Defined in:
- lib/savon/mock/expectation.rb
Overview
A single test expectation set up by Savon's mock interface. One expectation covers one operation call in one test.
Records the expected operation name and message, captures what was actually called, and either returns a synthetic response or raises an error on mismatch.
Instance Method Summary collapse
- #actual(operation_name, _builder, _globals, locals) ⇒ Object
-
#initialize(operation_name) ⇒ MockExpectation
constructor
A new instance of MockExpectation.
-
#response! ⇒ Transport::Response
Builds and returns a Transport::Response from the configured response hash.
- #returns(response) ⇒ Object
- #verify! ⇒ Object
- #with(locals) ⇒ Object
Constructor Details
#initialize(operation_name) ⇒ MockExpectation
Returns a new instance of MockExpectation.
14 15 16 17 |
# File 'lib/savon/mock/expectation.rb', line 14 def initialize(operation_name) @expected = { operation_name: operation_name } @actual = nil end |
Instance Method Details
#actual(operation_name, _builder, _globals, locals) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/savon/mock/expectation.rb', line 30 def actual(operation_name, _builder, _globals, locals) @actual = { operation_name: operation_name, message: locals[:message] } end |
#response! ⇒ Transport::Response
Builds and returns a Transport::Response from the configured response hash.
51 52 53 54 55 56 57 |
# File 'lib/savon/mock/expectation.rb', line 51 def response! unless @response raise ExpectationError, "This expectation was not set up with a response." end Transport::Response.new(@response[:code], @response[:headers], @response[:body]) end |
#returns(response) ⇒ Object
24 25 26 27 28 |
# File 'lib/savon/mock/expectation.rb', line 24 def returns(response) response = { code: 200, headers: {}, body: response } if response.is_a?(String) @response = response self end |
#verify! ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/savon/mock/expectation.rb', line 37 def verify! unless @actual raise ExpectationError, "Expected a request to the #{@expected[:operation_name].inspect} operation, " \ "but no request was executed." end verify_operation_name! end |
#with(locals) ⇒ Object
19 20 21 22 |
# File 'lib/savon/mock/expectation.rb', line 19 def with(locals) @expected[:message] = locals[:message] self end |