Class: Savon::SpecHelper::Interface

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

Instance Method Summary collapse

Instance Method Details

#expectationsObject



23
24
25
# File 'lib/savon/mock/spec_helper.rb', line 23

def expectations
  @expectations ||= []
end

#expects(operation_name) ⇒ Object



17
18
19
20
21
# File 'lib/savon/mock/spec_helper.rb', line 17

def expects(operation_name)
  expectation = MockExpectation.new(operation_name)
  expectations << expectation
  expectation
end

#mock!Object



9
10
11
# File 'lib/savon/mock/spec_helper.rb', line 9

def mock!
  Savon.observers << self
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/savon/mock/spec_helper.rb', line 27

def notify(operation_name, builder, globals, locals)
  expectation = expectations.shift

  if expectation
    expectation.actual(operation_name, builder, globals, locals)

    expectation.verify!
    expectation.response!
  else
    raise ExpectationError, "Unexpected request to the #{operation_name.inspect} operation."
  end
rescue ExpectationError
  @expectations.clear
  raise
end

#unmock!Object



13
14
15
# File 'lib/savon/mock/spec_helper.rb', line 13

def unmock!
  Savon.observers.clear
end

#verify!Object



43
44
45
46
47
48
49
# File 'lib/savon/mock/spec_helper.rb', line 43

def verify!
  return if expectations.empty?
  expectations.each(&:verify!)
rescue ExpectationError
  @expectations.clear
  raise
end