Class: Hardmock::MockControl

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/hardmock/mock_control.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#format_method_call_string

Constructor Details

#initializeMockControl

Returns a new instance of MockControl.



8
9
10
# File 'lib/hardmock/mock_control.rb', line 8

def initialize
  clear_expectations
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/hardmock/mock_control.rb', line 6

def name
  @name
end

Instance Method Details

#add_expectation(expectation) ⇒ Object



20
21
22
23
# File 'lib/hardmock/mock_control.rb', line 20

def add_expectation(expectation)
#      puts "MockControl #{self.object_id.to_s(16)} adding expectation: #{expectation}"
  @expectations << expectation
end

#apply_method_call(mock, mname, args, block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hardmock/mock_control.rb', line 25

def apply_method_call(mock,mname,args,block)
  # Are we even expecting any sort of call?
  if happy?
    @disappointed = true
    raise ExpectationError.new("Surprise call to #{format_method_call_string(mock,mname,args)}")
  end

  begin
    @expectations.shift.apply_method_call(mock,mname,args,block)
  rescue Exception => ouch
    @disappointed = true
    raise ouch
  end
end

#clear_expectationsObject



46
47
48
49
# File 'lib/hardmock/mock_control.rb', line 46

def clear_expectations
  @expectations = []
  @disappointed = false
end

#disappointed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hardmock/mock_control.rb', line 16

def disappointed?
  @disappointed
end

#happy?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/hardmock/mock_control.rb', line 12

def happy?
  @expectations.empty?
end

#verifyObject

Raises:



40
41
42
43
44
# File 'lib/hardmock/mock_control.rb', line 40

def verify
#      puts "MockControl #{self.object_id.to_s(16)} verify: happy? #{happy?}"
  @disappointed = !happy?
  raise VerifyError.new("Unmet expectations", @expectations) unless happy?
end