minilab 1.0.0-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. data/.document +2 -0
  2. data/CHANGES +2 -0
  3. data/LICENSE +19 -0
  4. data/README +107 -0
  5. data/Rakefile +145 -0
  6. data/config/environment.rb +15 -0
  7. data/config/objects.yml +22 -0
  8. data/lib/analog_io.rb +30 -0
  9. data/lib/digital_auxport_io.rb +49 -0
  10. data/lib/digital_configuration.rb +66 -0
  11. data/lib/digital_port_io.rb +68 -0
  12. data/lib/extension/extconf.rb +4 -0
  13. data/lib/extension/minilab_hardware.c +235 -0
  14. data/lib/extension/minilab_hardware.so +0 -0
  15. data/lib/library_translator.rb +48 -0
  16. data/lib/minilab.rb +149 -0
  17. data/lib/minilab_context.rb +39 -0
  18. data/lib/result_verifier.rb +14 -0
  19. data/test/integration/analog_input_output_test.rb +43 -0
  20. data/test/integration/connect_to_hardware_test.rb +13 -0
  21. data/test/integration/digital_input_output_test.rb +114 -0
  22. data/test/integration/integration_test.rb +53 -0
  23. data/test/integration/require_minilab_test.rb +9 -0
  24. data/test/system/analog_input.test +3 -0
  25. data/test/system/analog_output.test +37 -0
  26. data/test/system/digital_port_input.test +5 -0
  27. data/test/system/digital_port_output.test +39 -0
  28. data/test/system/digital_port_read_byte.test +26 -0
  29. data/test/system/digital_screw_terminals_input.test +2 -0
  30. data/test/system/digital_screw_terminals_output.test +11 -0
  31. data/test/system/minilab_driver.rb +85 -0
  32. data/test/test_helper.rb +11 -0
  33. data/test/unit/analog_io_test.rb +87 -0
  34. data/test/unit/digital_auxport_io_test.rb +114 -0
  35. data/test/unit/digital_configuration_test.rb +136 -0
  36. data/test/unit/digital_port_io_test.rb +117 -0
  37. data/test/unit/library_translator_test.rb +100 -0
  38. data/test/unit/minilab_context_test.rb +82 -0
  39. data/test/unit/minilab_hardware_test.rb +83 -0
  40. data/test/unit/minilab_test.rb +131 -0
  41. data/test/unit/result_verifier_test.rb +33 -0
  42. data/vendor/behaviors/lib/behaviors.rb +50 -0
  43. data/vendor/behaviors/tasks/behaviors_tasks.rake +140 -0
  44. data/vendor/behaviors/test/behaviors_tasks_test.rb +71 -0
  45. data/vendor/behaviors/test/behaviors_test.rb +50 -0
  46. data/vendor/behaviors/test/tasks_test/Rakefile +16 -0
  47. data/vendor/behaviors/test/tasks_test/doc/behaviors.html +55 -0
  48. data/vendor/behaviors/test/tasks_test/lib/user.rb +2 -0
  49. data/vendor/behaviors/test/tasks_test/test/user_test.rb +17 -0
  50. data/vendor/constructor/Rakefile +44 -0
  51. data/vendor/constructor/config/environment.rb +12 -0
  52. data/vendor/constructor/lib/constructor.rb +132 -0
  53. data/vendor/constructor/test/constructor_test.rb +366 -0
  54. data/vendor/constructor/test/helper.rb +3 -0
  55. data/vendor/diy/README +26 -0
  56. data/vendor/diy/Rakefile +18 -0
  57. data/vendor/diy/lib/constructor.rb +114 -0
  58. data/vendor/diy/lib/diy.rb +329 -0
  59. data/vendor/diy/proto/context.rb +117 -0
  60. data/vendor/diy/proto/context.yml +20 -0
  61. data/vendor/diy/test/diy_test.rb +370 -0
  62. data/vendor/diy/test/files/broken_construction.yml +7 -0
  63. data/vendor/diy/test/files/cat/cat.rb +4 -0
  64. data/vendor/diy/test/files/cat/extra_conflict.yml +5 -0
  65. data/vendor/diy/test/files/cat/heritage.rb +2 -0
  66. data/vendor/diy/test/files/cat/needs_input.yml +3 -0
  67. data/vendor/diy/test/files/cat/the_cat_lineage.rb +1 -0
  68. data/vendor/diy/test/files/dog/dog_model.rb +4 -0
  69. data/vendor/diy/test/files/dog/dog_presenter.rb +4 -0
  70. data/vendor/diy/test/files/dog/dog_view.rb +2 -0
  71. data/vendor/diy/test/files/dog/file_resolver.rb +2 -0
  72. data/vendor/diy/test/files/dog/other_thing.rb +2 -0
  73. data/vendor/diy/test/files/dog/simple.yml +11 -0
  74. data/vendor/diy/test/files/donkey/foo.rb +8 -0
  75. data/vendor/diy/test/files/donkey/foo/bar/qux.rb +7 -0
  76. data/vendor/diy/test/files/fud/objects.yml +13 -0
  77. data/vendor/diy/test/files/fud/toy.rb +15 -0
  78. data/vendor/diy/test/files/gnu/objects.yml +14 -0
  79. data/vendor/diy/test/files/gnu/thinger.rb +8 -0
  80. data/vendor/diy/test/files/goat/base.rb +8 -0
  81. data/vendor/diy/test/files/goat/can.rb +6 -0
  82. data/vendor/diy/test/files/goat/goat.rb +6 -0
  83. data/vendor/diy/test/files/goat/objects.yml +12 -0
  84. data/vendor/diy/test/files/goat/paper.rb +6 -0
  85. data/vendor/diy/test/files/goat/plane.rb +8 -0
  86. data/vendor/diy/test/files/goat/shirt.rb +6 -0
  87. data/vendor/diy/test/files/goat/wings.rb +8 -0
  88. data/vendor/diy/test/files/horse/holder_thing.rb +4 -0
  89. data/vendor/diy/test/files/horse/objects.yml +7 -0
  90. data/vendor/diy/test/files/yak/core_model.rb +4 -0
  91. data/vendor/diy/test/files/yak/core_presenter.rb +4 -0
  92. data/vendor/diy/test/files/yak/core_view.rb +1 -0
  93. data/vendor/diy/test/files/yak/data_source.rb +1 -0
  94. data/vendor/diy/test/files/yak/fringe_model.rb +4 -0
  95. data/vendor/diy/test/files/yak/fringe_presenter.rb +4 -0
  96. data/vendor/diy/test/files/yak/fringe_view.rb +1 -0
  97. data/vendor/diy/test/files/yak/my_objects.yml +21 -0
  98. data/vendor/diy/test/test_helper.rb +40 -0
  99. data/vendor/hardmock/CHANGES +8 -0
  100. data/vendor/hardmock/LICENSE +7 -0
  101. data/vendor/hardmock/README +48 -0
  102. data/vendor/hardmock/Rakefile +100 -0
  103. data/vendor/hardmock/TODO +7 -0
  104. data/vendor/hardmock/config/environment.rb +12 -0
  105. data/vendor/hardmock/homepage/demo.rb +21 -0
  106. data/vendor/hardmock/homepage/hardmock_sample.png +0 -0
  107. data/vendor/hardmock/homepage/index.html +65 -0
  108. data/vendor/hardmock/init.rb +3 -0
  109. data/vendor/hardmock/lib/hardmock.rb +634 -0
  110. data/vendor/hardmock/lib/method_cleanout.rb +14 -0
  111. data/vendor/hardmock/rcov.rake +18 -0
  112. data/vendor/hardmock/test/functional/assert_error_test.rb +52 -0
  113. data/vendor/hardmock/test/functional/auto_verify_test.rb +192 -0
  114. data/vendor/hardmock/test/functional/direct_mock_usage_test.rb +396 -0
  115. data/vendor/hardmock/test/functional/hardmock_test.rb +380 -0
  116. data/vendor/hardmock/test/test_helper.rb +23 -0
  117. data/vendor/hardmock/test/unit/expectation_builder_test.rb +18 -0
  118. data/vendor/hardmock/test/unit/expector_test.rb +56 -0
  119. data/vendor/hardmock/test/unit/method_cleanout_test.rb +35 -0
  120. data/vendor/hardmock/test/unit/mock_control_test.rb +172 -0
  121. data/vendor/hardmock/test/unit/mock_test.rb +273 -0
  122. data/vendor/hardmock/test/unit/simple_expectation_test.rb +345 -0
  123. data/vendor/hardmock/test/unit/trapper_test.rb +60 -0
  124. data/vendor/hardmock/test/unit/verify_error_test.rb +34 -0
  125. data/vendor/systir/systir.rb +403 -0
  126. data/vendor/systir/test/unit/ui/xml/testrunner.rb +192 -0
  127. data/vendor/systir/test/unit/ui/xml/xmltestrunner.xslt +109 -0
  128. metadata +235 -0
@@ -0,0 +1,14 @@
1
+
2
+ module Hardmock #:nodoc:
3
+ module MethodCleanout #:nodoc:
4
+ SACRED_METHODS = %w|__id__ __send__ equal? object_id send nil? class kind_of? respond_to? inspect method to_s instance_variables instance_eval|
5
+
6
+ def self.included(base) #:nodoc:
7
+ base.class_eval do
8
+ instance_methods.each { |m|
9
+ undef_method m unless SACRED_METHODS.include?(m.to_s)
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+
2
+ begin
3
+ require 'rcov/rcovtask'
4
+
5
+ namespace :rcov do
6
+
7
+ desc "Generate code coverage HTML report in pkg/coverage"
8
+ Rcov::RcovTask.new(:coverage) do |t|
9
+ t.test_files = FileList['test/unit/**/*.rb'] + FileList['test/functional/**/*.rb']
10
+ t.verbose = true
11
+ t.output_dir = "coverage"
12
+ end
13
+
14
+ end
15
+
16
+ rescue
17
+ puts "RCOV TASK DISABLED"
18
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'hardmock'
3
+
4
+ class AssertErrorTest < Test::Unit::TestCase
5
+
6
+ def test_assert_error
7
+ assert_error RuntimeError, "Too funky" do
8
+ raise RuntimeError.new("Too funky")
9
+ end
10
+ end
11
+
12
+ def test_assert_error_message_doesnt_match
13
+ err = assert_raise Test::Unit::AssertionFailedError do
14
+ assert_error RuntimeError, "not good" do
15
+ raise RuntimeError.new("Too funky")
16
+ end
17
+ end
18
+ assert_match(/not good/i, err.message)
19
+ assert_match(/too funky/i, err.message)
20
+ end
21
+
22
+ def test_assert_error_type_doesnt_match
23
+ err = assert_raise Test::Unit::AssertionFailedError do
24
+ assert_error StandardError, "Too funky" do
25
+ raise RuntimeError.new("Too funky")
26
+ end
27
+ end
28
+ assert_match(/StandardError/i, err.message)
29
+ assert_match(/RuntimeError/i, err.message)
30
+ end
31
+
32
+ def test_assert_error_regexp_matching
33
+ assert_error StandardError, /too/i, /funky/i do
34
+ raise StandardError.new("Too funky")
35
+ end
36
+ end
37
+
38
+ def test_assert_error_regexp_matching_fails
39
+ err = assert_raise Test::Unit::AssertionFailedError do
40
+ assert_error StandardError, /way/i, /too/i, /funky/i do
41
+ raise StandardError.new("Too funky")
42
+ end
43
+ end
44
+ assert_match(/way/i, err.message)
45
+ end
46
+
47
+ def test_assert_error_no_matchine
48
+ assert_error StandardError do
49
+ raise StandardError.new("ooof")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,192 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'fileutils'
3
+
4
+ class AutoVerifyTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @expect_unmet_expectations = true
8
+ end
9
+
10
+ def teardown
11
+ remove_temp_test_file
12
+ end
13
+
14
+ #
15
+ # HELPERS
16
+ #
17
+
18
+ def temp_test_file
19
+ File.expand_path(File.dirname(__FILE__) + "/tear_down_verification_test.rb")
20
+ end
21
+
22
+ def run_test(tbody)
23
+ File.open(temp_test_file,"w") { |f| f.print(tbody) }
24
+ @test_output = `ruby #{temp_test_file} 2>&1`
25
+ # puts "------------------------"
26
+ # puts @test_output
27
+ # puts "------------------------"
28
+ end
29
+
30
+ def remove_temp_test_file
31
+ FileUtils::rm_f temp_test_file
32
+ end
33
+
34
+ def assert_results(h)
35
+ assert_match(/#{h[:tests]} tests, [0-9]+ assertions, #{h[:failures]} failures, #{h[:errors]} errors/,
36
+ @test_output)
37
+ end
38
+
39
+ def assert_output_contains(*patterns)
40
+ patterns.each do |pattern|
41
+ assert_match(pattern,@test_output)
42
+ end
43
+ end
44
+
45
+ def assert_output_doesnt_contain(*patterns)
46
+ patterns.each do |pattern|
47
+ assert @test_output !~ pattern, "Output shouldn't match #{pattern.inspect} but it does."
48
+ end
49
+ end
50
+
51
+ def write_and_execute_test
52
+ @test_code ||=<<-EOM
53
+ def test_setup_doomed_expectation
54
+ create_mock :automobile
55
+ @automobile.expects.start
56
+ end
57
+ EOM
58
+ @full_code ||=<<-EOTEST
59
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
60
+ require 'hardmock'
61
+ class DummyTest < Test::Unit::TestCase
62
+ #{@teardown_code}
63
+ #{@test_code}
64
+ end
65
+ EOTEST
66
+ run_test @full_code
67
+
68
+ if @expect_unmet_expectations
69
+ assert_output_contains(/unmet expectations/i, /automobile/, /start/)
70
+ else
71
+ assert_output_doesnt_contain(/unmet expectations/i, /automobile/, /start/)
72
+ end
73
+
74
+ @expect_tests ||= 1
75
+ @expect_failures ||= 0
76
+ @expect_errors ||= 1
77
+ assert_results :tests => @expect_tests, :failures => @expect_failures, :errors => @expect_errors
78
+ end
79
+
80
+ #
81
+ # TESTS
82
+ #
83
+
84
+ def test_should_auto_verify_mocks_in_teardown
85
+ write_and_execute_test
86
+ end
87
+
88
+ def test_should_auto_verify_mocks_even_if_user_has_own_teardown
89
+ @teardown_code =<<-EOM
90
+ def teardown
91
+ # just in the way
92
+ end
93
+ EOM
94
+ write_and_execute_test
95
+ end
96
+
97
+ def test_should_auto_verify_mocks_but_not_obscure_natural_failures
98
+ @test_code =<<-EOM
99
+ def test_setup_doomed_expectation
100
+ create_mock :automobile
101
+ @automobile.expects.start
102
+ flunk "natural failure"
103
+ end
104
+ EOM
105
+ @expect_failures = 1
106
+ write_and_execute_test
107
+ end
108
+
109
+ def test_should_not_prevent_user_teardown_even_if_verification_fails
110
+ @teardown_code =<<-EOM
111
+ def teardown
112
+ puts "User teardown"
113
+ end
114
+ EOM
115
+ write_and_execute_test
116
+ assert_output_contains(/User teardown/)
117
+ end
118
+
119
+ def test_should_not_raise_error_if_verification_goes_according_to_plan
120
+ @test_code =<<-EOM
121
+ def test_ok
122
+ create_mock :automobile
123
+ @automobile.expects.start
124
+ @automobile.start
125
+ end
126
+ EOM
127
+ @teardown_code =<<-EOM
128
+ def teardown
129
+ puts "User teardown"
130
+ end
131
+ EOM
132
+ @expect_unmet_expectations = false
133
+ @expect_failures = 0
134
+ @expect_errors = 0
135
+ write_and_execute_test
136
+ assert_output_contains(/User teardown/)
137
+ end
138
+
139
+ def test_should_not_do_verification_if_user_teardown_explodes
140
+ @teardown_code =<<-EOM
141
+ def teardown
142
+ raise "self destruct"
143
+ end
144
+ EOM
145
+ @expect_unmet_expectations = false
146
+ write_and_execute_test
147
+ assert_output_contains(/self destruct/)
148
+ end
149
+
150
+ def test_should_not_obscure_inherited_teardown
151
+ @full_code ||=<<-EOTEST
152
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
153
+ require 'hardmock'
154
+ class Test::Unit::TestCase
155
+ def teardown
156
+ puts "Test helper teardown"
157
+ end
158
+ end
159
+ class DummyTest < Test::Unit::TestCase
160
+ def test_prepare_to_die
161
+ create_mock :automobile
162
+ @automobile.expects.start
163
+ end
164
+ end
165
+ EOTEST
166
+ write_and_execute_test
167
+ assert_output_contains(/Test helper teardown/)
168
+ end
169
+
170
+ def test_should_simultaneously_support_inherited_and_user_and_hardmock_teardown
171
+ @full_code ||=<<-EOTEST
172
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
173
+ class Test::Unit::TestCase
174
+ def teardown
175
+ puts "Test helper teardown"
176
+ end
177
+ end
178
+ require 'hardmock' # IMPORTANT TO DO THIS HERE, between the old and new teardown defs
179
+ class DummyTest < Test::Unit::TestCase
180
+ def teardown
181
+ puts "User teardown"
182
+ end
183
+ def test_prepare_to_die
184
+ create_mock :automobile
185
+ @automobile.expects.start
186
+ end
187
+ end
188
+ EOTEST
189
+ write_and_execute_test
190
+ assert_output_contains(/Test helper teardown/, /User teardown/)
191
+ end
192
+ end
@@ -0,0 +1,396 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'hardmock'
3
+
4
+ class DirectMockUsageTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @bird = Mock.new('bird')
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ #
14
+ # TESTS
15
+ #
16
+
17
+ def test_verify_should_raise_verify_error_if_expected_method_not_called
18
+ @bird.expects.flap_flap
19
+
20
+ err = assert_raise VerifyError do
21
+ @bird._verify
22
+ end
23
+ assert_match(/unmet expectations/i, err.message)
24
+ end
25
+
26
+ def test_verify_should_not_raise_when_expected_calls_made_in_order
27
+ @bird.expects.flap_flap
28
+ @bird.expects.bang
29
+ @bird.expects.plop
30
+
31
+ @bird.flap_flap
32
+ @bird.bang
33
+ @bird.plop
34
+
35
+ @bird._verify
36
+ end
37
+
38
+ def test_should_raise_expectation_error_when_unexpected_method_called
39
+ @bird.expects.flap_flap
40
+
41
+ err = assert_raise ExpectationError do
42
+ @bird.shoot
43
+ end
44
+ assert_match(/wrong method/i, err.message)
45
+ end
46
+
47
+ def test_bad_argument_call
48
+ @bird.expects.flap_flap(:swoosh)
49
+
50
+ err = assert_raise ExpectationError do
51
+ @bird.flap_flap(:rip)
52
+ end
53
+ assert_match(/wrong arguments/i, err.message)
54
+ end
55
+
56
+ def test_verify_should_raise_verify_error_when_not_all_expected_methods_called
57
+ @bird.expects.flap_flap
58
+ @bird.expects.bang
59
+ @bird.expects.plop
60
+
61
+ @bird.flap_flap
62
+
63
+ err = assert_raise VerifyError do
64
+ @bird._verify
65
+ end
66
+ assert_match(/unmet expectations/i, err.message)
67
+ end
68
+
69
+ def test_should_raise_expectation_error_when_calls_made_out_of_order
70
+ @bird.expects.flap_flap
71
+ @bird.expects.bang
72
+ @bird.expects.plop
73
+
74
+ @bird.flap_flap
75
+ err = assert_raise ExpectationError do
76
+ @bird.plop
77
+ end
78
+ assert_match(/wrong method/i, err.message)
79
+ end
80
+
81
+ def test_should_return_given_value_when_specified
82
+ @bird.expects.plop.returns(':P')
83
+ assert_equal ':P', @bird.plop
84
+ @bird._verify
85
+
86
+ @bird.expects.plop.returns(':x')
87
+ assert_equal ':x', @bird.plop
88
+ @bird._verify
89
+ end
90
+
91
+ def test_should_return_nil_value_when_none_specified
92
+ @bird.expects.plop
93
+ assert_nil @bird.plop
94
+ @bird._verify
95
+ end
96
+
97
+ def test_raise_should_raise_given_exception_when_specified
98
+ err = RuntimeError.new('shaq')
99
+ @bird.expects.plop.raises(err)
100
+ actual_err = assert_raise RuntimeError do
101
+ @bird.plop
102
+ end
103
+ assert_same err, actual_err, 'should be the same error'
104
+ @bird._verify
105
+ end
106
+
107
+ def test_raise_should_raise_given_string_wrapped_in_runtime_error
108
+ @bird.expects.plop.raises('shaq')
109
+ err = assert_raise RuntimeError do
110
+ @bird.plop
111
+ end
112
+ assert_match(/shaq/i, err.message)
113
+ @bird._verify
114
+ end
115
+
116
+ def test_raise_should_raise_a_canned_runtime_error_if_nothing_given
117
+ @bird.expects.plop.raises
118
+ err = assert_raise RuntimeError do
119
+ @bird.plop
120
+ end
121
+ assert_match(/error/i, err.message)
122
+ @bird._verify
123
+ end
124
+
125
+ def test_should_be_happy_with_correct_expected_arguments
126
+ thing = Object.new
127
+ @bird.expects.plop(:big,'one',thing)
128
+ @bird.plop(:big,'one',thing)
129
+ @bird._verify
130
+ end
131
+
132
+ def test_should_raise_expectation_error_when_wrong_number_of_arguemnts_specified
133
+ thing = Object.new
134
+ @bird.expects.plop(:big,'one',thing)
135
+ err = assert_raise ExpectationError do
136
+ # more
137
+ @bird.plop(:big,'one',thing,:other)
138
+ end
139
+ assert_match(/wrong arguments/i, err.message)
140
+ @bird._verify
141
+
142
+ @bird.expects.plop(:big,'one',thing)
143
+ err = assert_raise ExpectationError do
144
+ # less
145
+ @bird.plop(:big,'one')
146
+ end
147
+ assert_match(/wrong arguments/i, err.message)
148
+ @bird._verify
149
+
150
+ @bird.expects.plop
151
+ err = assert_raise ExpectationError do
152
+ # less
153
+ @bird.plop(:big)
154
+ end
155
+ assert_match(/wrong arguments/i, err.message)
156
+ @bird._verify
157
+ end
158
+
159
+ def test_should_raise_expectation_error_when_arguemnts_dont_match
160
+ thing = Object.new
161
+ @bird.expects.plop(:big,'one',thing)
162
+ err = assert_raise ExpectationError do
163
+ @bird.plop(:big,'two',thing,:other)
164
+ end
165
+ assert_match(/wrong arguments/i, err.message)
166
+ @bird._verify
167
+ end
168
+
169
+ def test_should_yield_to_block_given
170
+ mitt = nil
171
+ @bird.expects.plop { mitt = :ball }
172
+ assert_nil mitt
173
+ @bird.plop
174
+ assert_equal :ball, mitt, 'didnt catch the ball'
175
+ @bird._verify
176
+
177
+ @bird.expects.plop { raise 'ball' }
178
+ err = assert_raise RuntimeError do
179
+ @bird.plop
180
+ end
181
+ assert_match(/ball/i, err.message)
182
+ @bird._verify
183
+ end
184
+
185
+ def test_shouldnt_care_about_arguments_if_block_given
186
+ ball = nil
187
+ mitt = nil
188
+ @bird.expects.plop {|arg1,arg2|
189
+ ball = arg1
190
+ mitt = arg2
191
+ }
192
+ assert_nil ball
193
+ assert_nil mitt
194
+ @bird.plop(:ball,:mitt)
195
+ assert_equal :ball, ball
196
+ assert_equal :mitt, mitt
197
+ @bird._verify
198
+ end
199
+
200
+ def test_should_check_arguments_if_specified_when_block_given
201
+ ball = nil
202
+ mitt = nil
203
+ @bird.expects.plop(:ball,:mitt) {|arg1,arg2|
204
+ ball = arg1
205
+ mitt = arg2
206
+ }
207
+ assert_nil ball
208
+ assert_nil mitt
209
+ @bird.plop(:ball,:mitt)
210
+ assert_equal :ball, ball
211
+ assert_equal :mitt, mitt
212
+ @bird._verify
213
+
214
+ ball = nil
215
+ mitt = nil
216
+ @bird.expects.plop(:bad,:stupid) {|arg1,arg2|
217
+ ball = arg1
218
+ mitt = arg2
219
+ }
220
+ assert_nil ball
221
+ assert_nil mitt
222
+ err = assert_raise ExpectationError do
223
+ @bird.plop(:ball,:mitt)
224
+ end
225
+ assert_match(/wrong arguments/i, err.message)
226
+ assert_nil ball
227
+ assert_nil mitt
228
+ @bird._verify
229
+
230
+ ball = nil
231
+ mitt = nil
232
+ @bird.expects.plop(:ball,:mitt) {|arg1,arg2|
233
+ ball = arg1
234
+ mitt = arg2
235
+ }
236
+ assert_nil ball
237
+ assert_nil mitt
238
+ err = assert_raise ExpectationError do
239
+ @bird.plop(:ball)
240
+ end
241
+ assert_match(/wrong arguments/i, err.message)
242
+ assert_nil ball
243
+ assert_nil mitt
244
+ @bird._verify
245
+ end
246
+
247
+ def test_runtime_blocks_get_passed_to_expectation_blocks
248
+ runtime_block_called = false
249
+ got_arg = nil
250
+
251
+ # Eg, bird expects someone to subscribe to :tweet using the 'when' method
252
+ @bird.expects.when(:tweet) { |arg1, block|
253
+ got_arg = arg1
254
+ block.call
255
+ }
256
+
257
+ @bird.when(:tweet) do
258
+ runtime_block_called = true
259
+ end
260
+
261
+ assert_equal :tweet, got_arg, "Wrong arg"
262
+ assert runtime_block_called, "The runtime block should have been invoked by the user block"
263
+
264
+ @bird.expects.when(:warnk) { |e,blk| }
265
+
266
+ err = assert_raise ExpectationError do
267
+ @bird.when(:honk) { }
268
+ end
269
+ assert_match(/wrong arguments/i, err.message)
270
+
271
+ @bird._verify
272
+ end
273
+
274
+ def test_runtime_blocks_get_passed_to_expectation_blocks__no_arguments
275
+ runtime_block_called = false
276
+ @bird.expects.subscribe { |block| block.call }
277
+ @bird.subscribe do
278
+ runtime_block_called = true
279
+ end
280
+ assert runtime_block_called, "The runtime block should have been invoked by the user block"
281
+ end
282
+
283
+ def test_expect_runtime_block_but_none_sent
284
+ invoked = false
285
+ @bird.expects.kablam(:scatter) { |shot,block|
286
+ assert_equal :scatter, shot, "Wrong shot"
287
+ assert_nil block, "The expectation block should get a nil block when user neglects to pass one"
288
+ invoked = true
289
+ }
290
+ @bird.kablam :scatter
291
+ assert invoked, "Expectation block not invoked"
292
+
293
+ @bird._verify
294
+ end
295
+
296
+ def test_can_set_return_after_blocks
297
+ got = nil
298
+ @bird.expects.kablam(:scatter) { |shot|
299
+ got = shot
300
+ }.returns(:death)
301
+
302
+ val = @bird.kablam :scatter
303
+ assert_equal :death, val, "Wrong return value"
304
+ assert_equal :scatter, got, "Wrong argument"
305
+ @bird._verify
306
+ end
307
+
308
+ def test_can_set_raises_after_blocks
309
+ got = nil
310
+ @bird.expects.kablam(:scatter) do |shot|
311
+ got = shot
312
+ end.raises "hell"
313
+
314
+ err = assert_raise RuntimeError do
315
+ @bird.kablam :scatter
316
+ end
317
+ assert_match(/hell/i, err.message)
318
+
319
+ @bird._verify
320
+ end
321
+
322
+ def test_expectation_block_value_is_captured
323
+ expectation = @bird.expects.kablam(:slug) { |shot|
324
+ "The shot was #{shot}"
325
+ }
326
+
327
+ assert_not_nil expectation, "Expectation nil"
328
+ assert_nil expectation.block_value, "Block value should start out nil"
329
+
330
+ ret_val = @bird.kablam :slug
331
+
332
+ assert_equal "The shot was slug", expectation.block_value
333
+ assert_equal "The shot was slug", ret_val, "Block value should also be used for return"
334
+
335
+ @bird._verify
336
+ end
337
+
338
+
339
+ def test_expectation_block_value_is_used_for_return_value
340
+ @bird.expects.kablam(:scatter) { |shot|
341
+ "The shot was #{shot}"
342
+ }
343
+ val = @bird.kablam :scatter
344
+ assert_equal "The shot was scatter", val, "Wrong return value"
345
+ @bird._verify
346
+ end
347
+
348
+ def test_expectation_is_still_returned_when_using_returns
349
+ expectation = @bird.expects.kablam(:slug) { |shot|
350
+ "The shot was #{shot}"
351
+ }.returns :hosed
352
+
353
+ assert_not_nil expectation, "Expectation nil"
354
+ assert_nil expectation.block_value, "Block value should start out nil"
355
+
356
+ ret_val = @bird.kablam :slug
357
+
358
+ assert_equal "The shot was slug", expectation.block_value
359
+ assert_equal :hosed, ret_val, "Block value should also be used for return"
360
+
361
+ @bird._verify
362
+ end
363
+
364
+ def test_expectation_is_still_returned_when_using_raises
365
+ expectation = @bird.expects.kablam(:slug) { |shot|
366
+ "The shot was #{shot}"
367
+ }.raises "aiee!"
368
+
369
+ assert_not_nil expectation, "Expectation nil"
370
+ assert_nil expectation.block_value, "Block value should start out nil"
371
+
372
+ err = assert_raise RuntimeError do
373
+ @bird.kablam :slug
374
+ end
375
+ assert_match(/aiee!/i, err.message)
376
+ assert_equal "The shot was slug", expectation.block_value
377
+ @bird._verify
378
+ end
379
+
380
+
381
+ def test_expect_assignment
382
+ @bird.expects.size = "large"
383
+ @bird.size = "large"
384
+ @bird._verify
385
+ end
386
+
387
+ def test_expect_assignment_with_raise
388
+ @bird.expects('size=','large').raises "boom"
389
+
390
+ err = assert_raise RuntimeError do
391
+ @bird.size = "large"
392
+ end
393
+ assert_match(/boom/i, err.message)
394
+ end
395
+
396
+ end