minilab 1.0.0-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -0
- data/CHANGES +2 -0
- data/LICENSE +19 -0
- data/README +107 -0
- data/Rakefile +145 -0
- data/config/environment.rb +15 -0
- data/config/objects.yml +22 -0
- data/lib/analog_io.rb +30 -0
- data/lib/digital_auxport_io.rb +49 -0
- data/lib/digital_configuration.rb +66 -0
- data/lib/digital_port_io.rb +68 -0
- data/lib/extension/extconf.rb +4 -0
- data/lib/extension/minilab_hardware.c +235 -0
- data/lib/extension/minilab_hardware.so +0 -0
- data/lib/library_translator.rb +48 -0
- data/lib/minilab.rb +149 -0
- data/lib/minilab_context.rb +39 -0
- data/lib/result_verifier.rb +14 -0
- data/test/integration/analog_input_output_test.rb +43 -0
- data/test/integration/connect_to_hardware_test.rb +13 -0
- data/test/integration/digital_input_output_test.rb +114 -0
- data/test/integration/integration_test.rb +53 -0
- data/test/integration/require_minilab_test.rb +9 -0
- data/test/system/analog_input.test +3 -0
- data/test/system/analog_output.test +37 -0
- data/test/system/digital_port_input.test +5 -0
- data/test/system/digital_port_output.test +39 -0
- data/test/system/digital_port_read_byte.test +26 -0
- data/test/system/digital_screw_terminals_input.test +2 -0
- data/test/system/digital_screw_terminals_output.test +11 -0
- data/test/system/minilab_driver.rb +85 -0
- data/test/test_helper.rb +11 -0
- data/test/unit/analog_io_test.rb +87 -0
- data/test/unit/digital_auxport_io_test.rb +114 -0
- data/test/unit/digital_configuration_test.rb +136 -0
- data/test/unit/digital_port_io_test.rb +117 -0
- data/test/unit/library_translator_test.rb +100 -0
- data/test/unit/minilab_context_test.rb +82 -0
- data/test/unit/minilab_hardware_test.rb +83 -0
- data/test/unit/minilab_test.rb +131 -0
- data/test/unit/result_verifier_test.rb +33 -0
- data/vendor/behaviors/lib/behaviors.rb +50 -0
- data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
- data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
- data/vendor/behaviors/test/behaviors_test.rb +50 -0
- data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
- data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
- data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
- data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
- data/vendor/constructor/Rakefile +44 -0
- data/vendor/constructor/config/environment.rb +12 -0
- data/vendor/constructor/lib/constructor.rb +132 -0
- data/vendor/constructor/test/constructor_test.rb +366 -0
- data/vendor/constructor/test/helper.rb +3 -0
- data/vendor/diy/README +26 -0
- data/vendor/diy/Rakefile +18 -0
- data/vendor/diy/lib/constructor.rb +114 -0
- data/vendor/diy/lib/diy.rb +329 -0
- data/vendor/diy/proto/context.rb +117 -0
- data/vendor/diy/proto/context.yml +20 -0
- data/vendor/diy/test/diy_test.rb +370 -0
- data/vendor/diy/test/files/broken_construction.yml +7 -0
- data/vendor/diy/test/files/cat/cat.rb +4 -0
- data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
- data/vendor/diy/test/files/cat/heritage.rb +2 -0
- data/vendor/diy/test/files/cat/needs_input.yml +3 -0
- data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
- data/vendor/diy/test/files/dog/dog_model.rb +4 -0
- data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
- data/vendor/diy/test/files/dog/dog_view.rb +2 -0
- data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
- data/vendor/diy/test/files/dog/other_thing.rb +2 -0
- data/vendor/diy/test/files/dog/simple.yml +11 -0
- data/vendor/diy/test/files/donkey/foo.rb +8 -0
- data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
- data/vendor/diy/test/files/fud/objects.yml +13 -0
- data/vendor/diy/test/files/fud/toy.rb +15 -0
- data/vendor/diy/test/files/gnu/objects.yml +14 -0
- data/vendor/diy/test/files/gnu/thinger.rb +8 -0
- data/vendor/diy/test/files/goat/base.rb +8 -0
- data/vendor/diy/test/files/goat/can.rb +6 -0
- data/vendor/diy/test/files/goat/goat.rb +6 -0
- data/vendor/diy/test/files/goat/objects.yml +12 -0
- data/vendor/diy/test/files/goat/paper.rb +6 -0
- data/vendor/diy/test/files/goat/plane.rb +8 -0
- data/vendor/diy/test/files/goat/shirt.rb +6 -0
- data/vendor/diy/test/files/goat/wings.rb +8 -0
- data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
- data/vendor/diy/test/files/horse/objects.yml +7 -0
- data/vendor/diy/test/files/yak/core_model.rb +4 -0
- data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/core_view.rb +1 -0
- data/vendor/diy/test/files/yak/data_source.rb +1 -0
- data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
- data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
- data/vendor/diy/test/files/yak/my_objects.yml +21 -0
- data/vendor/diy/test/test_helper.rb +40 -0
- data/vendor/hardmock/CHANGES +8 -0
- data/vendor/hardmock/LICENSE +7 -0
- data/vendor/hardmock/README +48 -0
- data/vendor/hardmock/Rakefile +100 -0
- data/vendor/hardmock/TODO +7 -0
- data/vendor/hardmock/config/environment.rb +12 -0
- data/vendor/hardmock/homepage/demo.rb +21 -0
- data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
- data/vendor/hardmock/homepage/index.html +65 -0
- data/vendor/hardmock/init.rb +3 -0
- data/vendor/hardmock/lib/hardmock.rb +634 -0
- data/vendor/hardmock/lib/method_cleanout.rb +14 -0
- data/vendor/hardmock/rcov.rake +18 -0
- data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
- data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
- data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
- data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
- data/vendor/hardmock/test/test_helper.rb +23 -0
- data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
- data/vendor/hardmock/test/unit/expector_test.rb +56 -0
- data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
- data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
- data/vendor/hardmock/test/unit/mock_test.rb +273 -0
- data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
- data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
- data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
- data/vendor/systir/systir.rb +403 -0
- data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
- data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
- metadata +235 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'method_cleanout'
|
3
|
+
|
4
|
+
class MethodCleanoutTest < Test::Unit::TestCase
|
5
|
+
class Victim
|
6
|
+
OriginalMethods = instance_methods
|
7
|
+
include Hardmock::MethodCleanout
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@victim = Victim.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_remove_most_methods_from_a_class
|
15
|
+
expect_removed = Victim::OriginalMethods.reject { |m|
|
16
|
+
Hardmock::MethodCleanout::SACRED_METHODS.include?(m)
|
17
|
+
}
|
18
|
+
expect_removed.each do |m|
|
19
|
+
assert !@victim.respond_to?(m), "should not have method #{m}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_leave_the_sacred_methods_defined
|
24
|
+
Hardmock::MethodCleanout::SACRED_METHODS.each do |m|
|
25
|
+
assert @victim.respond_to?(m)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_include_certain_important_methods_in_the_sacred_methods_list
|
30
|
+
%w|__id__ __send__ equal? object_id send nil? class kind_of? respond_to? inspect method to_s instance_variables instance_eval|.each do |m|
|
31
|
+
assert Hardmock::MethodCleanout::SACRED_METHODS.include?(m), "important method #{m} is not included in SACRED_METHODS"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'hardmock'
|
3
|
+
|
4
|
+
class MockControlTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@unmock = OpenStruct.new( :_name => 'fakemock' )
|
8
|
+
|
9
|
+
@control = MockControl.new
|
10
|
+
assert @control.happy?, "Control should start out happy"
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# HELPERS
|
18
|
+
#
|
19
|
+
|
20
|
+
class MyExp
|
21
|
+
attr_reader :mock, :mname, :args, :block
|
22
|
+
def apply_method_call(mock, mname, args, block)
|
23
|
+
@mock = mock
|
24
|
+
@mname = mname
|
25
|
+
@args = args
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class BoomExp < MyExp
|
31
|
+
def apply_method_call(mock, mname, args, block)
|
32
|
+
super
|
33
|
+
raise "BOOM"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# TESTS
|
39
|
+
#
|
40
|
+
|
41
|
+
def test_add_exepectation_and_apply_method_call
|
42
|
+
e1 = MyExp.new
|
43
|
+
|
44
|
+
@control.add_expectation e1
|
45
|
+
assert !@control.happy?
|
46
|
+
|
47
|
+
@control.apply_method_call @unmock, 'some_func', [ 'the', :args ], nil
|
48
|
+
assert @control.happy?
|
49
|
+
|
50
|
+
assert_same @unmock, e1.mock, "Wrong mock"
|
51
|
+
assert_equal 'some_func', e1.mname, "Wrong method"
|
52
|
+
assert_equal [ 'the', :args ], e1.args, "Wrong args"
|
53
|
+
|
54
|
+
@control.verify
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_add_exepectation_and_apply_method_call_with_block
|
58
|
+
e1 = MyExp.new
|
59
|
+
|
60
|
+
@control.add_expectation e1
|
61
|
+
assert !@control.happy?
|
62
|
+
|
63
|
+
runtime_block = Proc.new { "hello" }
|
64
|
+
@control.apply_method_call @unmock, 'some_func', [ 'the', :args ], runtime_block
|
65
|
+
assert @control.happy?
|
66
|
+
|
67
|
+
assert_same @unmock, e1.mock, "Wrong mock"
|
68
|
+
assert_equal 'some_func', e1.mname, "Wrong method"
|
69
|
+
assert_equal [ 'the', :args ], e1.args, "Wrong args"
|
70
|
+
assert_equal "hello", e1.block.call, "Wrong block in expectation"
|
71
|
+
|
72
|
+
@control.verify
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_add_expectation_then_verify
|
76
|
+
e1 = MyExp.new
|
77
|
+
|
78
|
+
@control.add_expectation e1
|
79
|
+
assert !@control.happy?, "Shoudn't be happy"
|
80
|
+
err = assert_raise VerifyError do
|
81
|
+
@control.verify
|
82
|
+
end
|
83
|
+
assert_match(/unmet expectations/i, err.message)
|
84
|
+
|
85
|
+
@control.apply_method_call @unmock, 'some_func', [ 'the', :args ], nil
|
86
|
+
assert @control.happy?
|
87
|
+
|
88
|
+
assert_same @unmock, e1.mock, "Wrong mock"
|
89
|
+
assert_equal 'some_func', e1.mname, "Wrong method"
|
90
|
+
assert_equal [ 'the', :args ], e1.args, "Wrong args"
|
91
|
+
|
92
|
+
@control.verify
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_expectation_explosion
|
96
|
+
be1 = BoomExp.new
|
97
|
+
|
98
|
+
@control.add_expectation be1
|
99
|
+
|
100
|
+
err = assert_raise RuntimeError do
|
101
|
+
@control.apply_method_call @unmock, 'a func', [:arg], nil
|
102
|
+
end
|
103
|
+
assert_match(/BOOM/i, err.message)
|
104
|
+
|
105
|
+
assert_same @unmock, be1.mock
|
106
|
+
assert_equal 'a func', be1.mname
|
107
|
+
assert_equal [:arg], be1.args
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_disappointment_on_bad_verify
|
111
|
+
@control.add_expectation MyExp.new
|
112
|
+
assert !@control.happy?, "Shouldn't be happy"
|
113
|
+
assert !@control.disappointed?, "too early to be disappointed"
|
114
|
+
|
115
|
+
# See verify fails
|
116
|
+
err = assert_raise VerifyError do
|
117
|
+
@control.verify
|
118
|
+
end
|
119
|
+
assert_match(/unmet expectations/i, err.message)
|
120
|
+
|
121
|
+
assert !@control.happy?, "Still have unmet expectation"
|
122
|
+
assert @control.disappointed?, "We should be disappointed following that failure"
|
123
|
+
|
124
|
+
@control.apply_method_call @unmock, 'something', [], nil
|
125
|
+
assert @control.happy?, "Should be happy"
|
126
|
+
assert @control.disappointed?, "We should be skeptical"
|
127
|
+
|
128
|
+
@control.verify
|
129
|
+
|
130
|
+
assert !@control.disappointed?, "Should be non-disappointed"
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_disappointment_from_surprise_calls
|
134
|
+
assert @control.happy?, "Should be happy"
|
135
|
+
assert !@control.disappointed?, "too early to be disappointed"
|
136
|
+
|
137
|
+
# See verify fails
|
138
|
+
err = assert_raise ExpectationError do
|
139
|
+
@control.apply_method_call @unmock, "something", [], nil
|
140
|
+
end
|
141
|
+
assert_match(/surprise/i, err.message)
|
142
|
+
|
143
|
+
assert @control.happy?, "Happiness is an empty list of expectations"
|
144
|
+
assert @control.disappointed?, "We should be disappointed following that failure"
|
145
|
+
|
146
|
+
@control.verify
|
147
|
+
assert !@control.disappointed?, "Disappointment should be gone"
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_disappointment_from_bad_calls
|
151
|
+
be1 = BoomExp.new
|
152
|
+
assert !@control.disappointed?, "Shouldn't be disappointed"
|
153
|
+
@control.add_expectation be1
|
154
|
+
assert !@control.disappointed?, "Shouldn't be disappointed"
|
155
|
+
|
156
|
+
err = assert_raise RuntimeError do
|
157
|
+
@control.apply_method_call @unmock, 'a func', [:arg], nil
|
158
|
+
end
|
159
|
+
assert_match(/BOOM/i, err.message)
|
160
|
+
assert @control.disappointed?, "Should be disappointed"
|
161
|
+
|
162
|
+
assert_same @unmock, be1.mock
|
163
|
+
assert_equal 'a func', be1.mname
|
164
|
+
assert_equal [:arg], be1.args
|
165
|
+
|
166
|
+
assert @control.happy?, "Happiness is an empty list of expectations"
|
167
|
+
@control.verify
|
168
|
+
assert !@control.disappointed?, "Disappointment should be gone"
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'hardmock'
|
3
|
+
|
4
|
+
class MockTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_build_with_control
|
7
|
+
mc1 = MockControl.new
|
8
|
+
mock = Mock.new('hi', mc1)
|
9
|
+
assert_equal 'hi', mock._name, "Wrong name"
|
10
|
+
assert_same mc1, mock._control, "Wrong contol"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basics
|
14
|
+
mock = Mock.new('a name')
|
15
|
+
assert_equal 'a name', mock._name, "Wrong name for mock"
|
16
|
+
assert_not_nil mock._control, "Nil control in mock"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_expects
|
20
|
+
mock = Mock.new('order')
|
21
|
+
control = mock._control
|
22
|
+
assert control.happy?, "Mock should start out satisfied"
|
23
|
+
|
24
|
+
mock.expects.absorb_something(:location, 'garbage')
|
25
|
+
assert !control.happy?, "mock control should be unhappy"
|
26
|
+
|
27
|
+
# Do the call
|
28
|
+
mock.absorb_something(:location, 'garbage')
|
29
|
+
assert control.happy?, "mock control should be happy again"
|
30
|
+
|
31
|
+
# Verify
|
32
|
+
assert_nothing_raised Exception do
|
33
|
+
mock._verify
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_expects_using_arguments_for_method_and_arguments
|
38
|
+
mock = Mock.new('order')
|
39
|
+
mock.expects(:absorb_something, :location, 'garbage')
|
40
|
+
mock.absorb_something(:location, 'garbage')
|
41
|
+
mock._verify
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_expects_using_arguments_for_method_and_arguments_with_block
|
45
|
+
mock = Mock.new('order')
|
46
|
+
mock.expects(:absorb_something, :location, 'garbage') { |a,b,block|
|
47
|
+
assert_equal :location, a, "Wrong 'a' argument"
|
48
|
+
assert_equal 'garbage', b, "Wrong 'b' argument"
|
49
|
+
assert_equal 'innards', block.call, "Wrong block"
|
50
|
+
}
|
51
|
+
mock.absorb_something(:location, 'garbage') do "innards" end
|
52
|
+
mock._verify
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_expects_using_string_method_name
|
56
|
+
mock = Mock.new('order')
|
57
|
+
mock.expects('absorb_something', :location, 'garbage')
|
58
|
+
mock.absorb_something(:location, 'garbage')
|
59
|
+
mock._verify
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def test_expects_assignment
|
64
|
+
mock = Mock.new('order')
|
65
|
+
mock.expects.account_number = 1234
|
66
|
+
|
67
|
+
mock.account_number = 1234
|
68
|
+
|
69
|
+
mock._verify
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_expects_assigment_using_arguments_for_method_and_arguments
|
73
|
+
mock = Mock.new('order')
|
74
|
+
mock.expects(:account_number=, 1234)
|
75
|
+
mock.account_number = 1234
|
76
|
+
mock._verify
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_expects_assigment_using_string_method_name
|
80
|
+
mock = Mock.new('order')
|
81
|
+
mock.expects('account_number=', 1234)
|
82
|
+
mock.account_number = 1234
|
83
|
+
mock._verify
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_expects_assignment_and_return_is_overruled_by_ruby_syntax
|
87
|
+
# Prove that we can set up a return but that it doesn't mean much,
|
88
|
+
# because ruby's parser will 'do the right thing' as regards semantic
|
89
|
+
# values for assignment. (That is, the rvalue of the assignment)
|
90
|
+
mock = Mock.new('order')
|
91
|
+
mock.expects(:account_number=, 1234).returns "gold"
|
92
|
+
got = mock.account_number = 1234
|
93
|
+
mock._verify
|
94
|
+
assert_equal 1234, got, "Expected rvalue"
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_expects_assignment_and_raise
|
98
|
+
mock = Mock.new('order')
|
99
|
+
mock.expects(:account_number=, 1234).raises StandardError.new("kaboom")
|
100
|
+
err = assert_raise StandardError do
|
101
|
+
mock.account_number = 1234
|
102
|
+
end
|
103
|
+
assert_match(/kaboom/i, err.message)
|
104
|
+
mock._verify
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def test_expects_multiple
|
109
|
+
mock = Mock.new('order')
|
110
|
+
control = mock._control
|
111
|
+
|
112
|
+
assert control.happy?
|
113
|
+
|
114
|
+
mock.expects.one_thing :hi, { :goose => 'neck' }
|
115
|
+
mock.expects.another 5,6,7
|
116
|
+
assert !control.happy?
|
117
|
+
|
118
|
+
mock.one_thing :hi, { :goose => 'neck' }
|
119
|
+
assert !control.happy?
|
120
|
+
|
121
|
+
mock.another 5,6,7
|
122
|
+
assert control.happy?
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_surprise_call
|
126
|
+
mock = Mock.new('order')
|
127
|
+
err = assert_raise ExpectationError do
|
128
|
+
mock.uh_oh
|
129
|
+
end
|
130
|
+
assert_match(/surprise/i, err.message)
|
131
|
+
assert_match(/uh_oh/i, err.message)
|
132
|
+
|
133
|
+
err = assert_raise ExpectationError do
|
134
|
+
mock.whoa :horse
|
135
|
+
end
|
136
|
+
assert_match(/surprise/i, err.message)
|
137
|
+
assert_match(/order\.whoa\(:horse\)/i, err.message)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_wrong_call
|
141
|
+
mock = Mock.new('order')
|
142
|
+
mock.expects.pig 'arse'
|
143
|
+
err = assert_raise ExpectationError do
|
144
|
+
mock.whoa :horse
|
145
|
+
end
|
146
|
+
assert_match(/wrong method/i, err.message)
|
147
|
+
assert_match(/order\.whoa\(:horse\)/i, err.message)
|
148
|
+
assert_match(/order\.pig\("arse"\)/i, err.message)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_wrong_arguments
|
152
|
+
mock = Mock.new('order')
|
153
|
+
mock.expects.go_fast(:a, 1, 'three')
|
154
|
+
|
155
|
+
err = assert_raise ExpectationError do
|
156
|
+
mock.go_fast :a, 1, 'not right'
|
157
|
+
end
|
158
|
+
assert_match(/wrong argument/i, err.message)
|
159
|
+
assert_match(/order\.go_fast\(:a, 1, "three"\)/i, err.message)
|
160
|
+
assert_match(/order\.go_fast\(:a, 1, "not right"\)/i, err.message)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_expects_and_return
|
164
|
+
mock = Mock.new('order')
|
165
|
+
mock.expects.delivery_date.returns Date.today
|
166
|
+
assert_equal Date.today, mock.delivery_date
|
167
|
+
mock._verify
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_expects_and_return_with_arguments
|
171
|
+
mock = Mock.new('order')
|
172
|
+
mock.expects.delivery_date(:arf,14).returns(Date.today)
|
173
|
+
assert_equal Date.today, mock.delivery_date(:arf,14)
|
174
|
+
mock._verify
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_expects_and_raise
|
178
|
+
mock = Mock.new('order')
|
179
|
+
mock.expects.delivery_date.raises StandardError.new("bloof")
|
180
|
+
|
181
|
+
err = assert_raise StandardError do
|
182
|
+
mock.delivery_date
|
183
|
+
end
|
184
|
+
assert_match(/bloof/i, err.message)
|
185
|
+
|
186
|
+
mock._verify
|
187
|
+
|
188
|
+
# Try convenience argument String
|
189
|
+
mock.expects.pow.raises "hell"
|
190
|
+
err = assert_raise RuntimeError do
|
191
|
+
mock.pow
|
192
|
+
end
|
193
|
+
assert_match(/hell/i, err.message)
|
194
|
+
|
195
|
+
mock._verify
|
196
|
+
|
197
|
+
# Try convenience argument nothing
|
198
|
+
mock.expects.pow.raises
|
199
|
+
err = assert_raise RuntimeError do
|
200
|
+
mock.pow
|
201
|
+
end
|
202
|
+
assert_match(/an error/i, err.message)
|
203
|
+
|
204
|
+
mock._verify
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_expects_a_runtime_block
|
208
|
+
mock = Mock.new('order')
|
209
|
+
got_val = nil
|
210
|
+
|
211
|
+
mock.expects.when(:something) { |e,block|
|
212
|
+
got_val = block.call
|
213
|
+
}
|
214
|
+
|
215
|
+
mock.when :something do "hi there" end
|
216
|
+
|
217
|
+
assert_equal "hi there", got_val, "Expectation block not invoked"
|
218
|
+
mock._verify
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_trap_block
|
222
|
+
mock = Mock.new('order')
|
223
|
+
exp = mock.trap.observe
|
224
|
+
|
225
|
+
# use it
|
226
|
+
mock.observe { "burp" }
|
227
|
+
|
228
|
+
assert_equal "burp", exp.block_value.call
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_trap_arguments_and_block
|
232
|
+
mock = Mock.new('order')
|
233
|
+
exp = mock.trap.subscribe(:data_changed)
|
234
|
+
|
235
|
+
# use it
|
236
|
+
mock.subscribe(:data_changed) { "burp" }
|
237
|
+
assert_equal "burp", exp.block_value.call
|
238
|
+
mock._verify
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_trap_arguments_and_block_wrong_num_args
|
242
|
+
mock = Mock.new('order')
|
243
|
+
exp = mock.trap.subscribe(:data_changed)
|
244
|
+
|
245
|
+
assert_raise ExpectationError do
|
246
|
+
mock.subscribe(:data_changed,1) { "burp" }
|
247
|
+
end
|
248
|
+
mock._verify
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_trap_arguments_and_block_wrong_args
|
252
|
+
mock = Mock.new('order')
|
253
|
+
exp = mock.trap.subscribe(:data_changed)
|
254
|
+
|
255
|
+
assert_raise ExpectationError do
|
256
|
+
mock.subscribe("no good") { "burp" }
|
257
|
+
end
|
258
|
+
|
259
|
+
mock._verify
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_trap_is_not_leniant_about_arguments
|
263
|
+
mock = Mock.new('order')
|
264
|
+
exp = mock.trap.subscribe
|
265
|
+
|
266
|
+
assert_raise ExpectationError do
|
267
|
+
mock.subscribe("no good") { "burp" }
|
268
|
+
end
|
269
|
+
|
270
|
+
mock._verify
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|