Class: Hardmock::MockControl
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#format_method_call_string
Constructor Details
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
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)
@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)
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_expectations ⇒ Object
46
47
48
49
|
# File 'lib/hardmock/mock_control.rb', line 46
def clear_expectations
@expectations = []
@disappointed = false
end
|
#disappointed? ⇒ Boolean
16
17
18
|
# File 'lib/hardmock/mock_control.rb', line 16
def disappointed?
@disappointed
end
|
#happy? ⇒ Boolean
12
13
14
|
# File 'lib/hardmock/mock_control.rb', line 12
def happy?
@expectations.empty?
end
|
40
41
42
43
44
|
# File 'lib/hardmock/mock_control.rb', line 40
def verify
@disappointed = !happy?
raise VerifyError.new("Unmet expectations", @expectations) unless happy?
end
|