Class: Savon::MockExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/mock/expectation.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation_name) ⇒ MockExpectation

Returns a new instance of MockExpectation.



6
7
8
9
# File 'lib/savon/mock/expectation.rb', line 6

def initialize(operation_name)
  @expected = { :operation_name => operation_name }
  @actual = nil
end

Instance Method Details

#actual(operation_name, builder, globals, locals) ⇒ Object



22
23
24
25
26
27
# File 'lib/savon/mock/expectation.rb', line 22

def actual(operation_name, builder, globals, locals)
  @actual = {
    :operation_name => operation_name,
    :message        => locals[:message]
  }
end

#response!Object



39
40
41
42
43
44
45
# File 'lib/savon/mock/expectation.rb', line 39

def response!
  unless @response
    raise ExpectationError, "This expectation was not set up with a response."
  end

  HTTPI::Response.new(@response[:code], @response[:headers], @response[:body])
end

#returns(response) ⇒ Object



16
17
18
19
20
# File 'lib/savon/mock/expectation.rb', line 16

def returns(response)
  response = { :code => 200, :headers => {}, :body => response } if response.kind_of?(String)
  @response = response
  self
end

#verify!Object



29
30
31
32
33
34
35
36
37
# File 'lib/savon/mock/expectation.rb', line 29

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!
  verify_message!
end

#with(locals) ⇒ Object



11
12
13
14
# File 'lib/savon/mock/expectation.rb', line 11

def with(locals)
  @expected[:message] = locals[:message]
  self
end