Class: Savon::MockExpectation
- Inherits:
-
Object
- Object
- Savon::MockExpectation
- Defined in:
- lib/savon/mock/expectation.rb
Instance Method Summary collapse
- #actual(operation_name, builder, globals, locals) ⇒ Object
-
#initialize(operation_name) ⇒ MockExpectation
constructor
A new instance of MockExpectation.
- #response! ⇒ Object
- #returns(response) ⇒ Object
- #verify! ⇒ Object
- #with(locals) ⇒ Object
Constructor Details
#initialize(operation_name) ⇒ MockExpectation
Returns a new instance of MockExpectation.
7 8 9 10 |
# File 'lib/savon/mock/expectation.rb', line 7 def initialize(operation_name) @expected = { :operation_name => operation_name } @actual = nil end |
Instance Method Details
#actual(operation_name, builder, globals, locals) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/savon/mock/expectation.rb', line 23 def actual(operation_name, builder, globals, locals) @actual = { :operation_name => operation_name, :message => locals[:message] } end |
#response! ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/savon/mock/expectation.rb', line 40 def response! unless @response raise ExpectationError, "This expectation was not set up with a response." end env = Faraday::Env.from(status: @response[:code], response_headers: @response[:headers], response_body: @response[:body]) Faraday::Response.new(env) end |
#returns(response) ⇒ Object
17 18 19 20 21 |
# File 'lib/savon/mock/expectation.rb', line 17 def returns(response) response = { :code => 200, :headers => {}, :body => response } if response.kind_of?(String) @response = response self end |
#verify! ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/savon/mock/expectation.rb', line 30 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
12 13 14 15 |
# File 'lib/savon/mock/expectation.rb', line 12 def with(locals) @expected[:message] = locals[:message] self end |