bourne 1.1.1 → 1.1.2

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.
@@ -1,13 +1,13 @@
1
1
  class SimpleCounter
2
-
2
+
3
3
  attr_reader :count
4
-
4
+
5
5
  def initialize
6
6
  @count = 0
7
7
  end
8
-
8
+
9
9
  def increment
10
10
  @count += 1
11
11
  end
12
-
13
- end
12
+
13
+ end
@@ -13,7 +13,7 @@ module TestRunner
13
13
  define_method(:test_me, &block)
14
14
  end
15
15
  test = test_class.new(:test_me)
16
-
16
+
17
17
  if defined?(Test::Unit::TestResult)
18
18
  test_result ||= Test::Unit::TestResult.new
19
19
  test.run(test_result) {}
@@ -34,10 +34,10 @@ module TestRunner
34
34
  test.run(runner)
35
35
  test_result = MiniTestResult.new(runner, test)
36
36
  end
37
-
37
+
38
38
  test_result
39
39
  end
40
-
40
+
41
41
  def assert_passed(test_result)
42
42
  flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
43
43
  flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
@@ -7,7 +7,7 @@ require 'execution_point'
7
7
  require 'simple_counter'
8
8
 
9
9
  class ExpectationTest < Test::Unit::TestCase
10
-
10
+
11
11
  include Mocha
12
12
 
13
13
  class FakeMockery
@@ -36,67 +36,67 @@ class ExpectationTest < Test::Unit::TestCase
36
36
  def new_expectation
37
37
  Expectation.new(nil, :expected_method)
38
38
  end
39
-
39
+
40
40
  def test_should_match_calls_to_same_method_with_any_parameters
41
41
  assert new_expectation.match?(:expected_method, 1, 2, 3)
42
42
  end
43
-
43
+
44
44
  def test_should_match_calls_to_same_method_with_exactly_zero_parameters
45
45
  expectation = new_expectation.with()
46
46
  assert expectation.match?(:expected_method)
47
47
  end
48
-
48
+
49
49
  def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
50
50
  expectation = new_expectation.with()
51
51
  assert !expectation.match?(:expected_method, 1, 2, 3)
52
52
  end
53
-
53
+
54
54
  def test_should_match_calls_to_same_method_with_expected_parameter_values
55
55
  expectation = new_expectation.with(1, 2, 3)
56
56
  assert expectation.match?(:expected_method, 1, 2, 3)
57
57
  end
58
-
58
+
59
59
  def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
60
60
  expectation = new_expectation.with() {|x, y, z| x + y == z}
61
61
  assert expectation.match?(:expected_method, 1, 2, 3)
62
62
  end
63
-
63
+
64
64
  def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
65
65
  expectation = new_expectation.with() {|x, y, z| x + y == z}
66
66
  assert !expectation.match?(:different_method, 1, 2, 3)
67
67
  end
68
-
68
+
69
69
  def test_should_not_match_calls_to_different_methods_with_no_parameters
70
70
  assert !new_expectation.match?(:unexpected_method)
71
71
  end
72
-
72
+
73
73
  def test_should_not_match_calls_to_same_method_with_too_few_parameters
74
74
  expectation = new_expectation.with(1, 2, 3)
75
75
  assert !expectation.match?(:unexpected_method, 1, 2)
76
76
  end
77
-
77
+
78
78
  def test_should_not_match_calls_to_same_method_with_too_many_parameters
79
79
  expectation = new_expectation.with(1, 2)
80
80
  assert !expectation.match?(:unexpected_method, 1, 2, 3)
81
81
  end
82
-
82
+
83
83
  def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
84
84
  expectation = new_expectation.with(1, 2, 3)
85
85
  assert !expectation.match?(:unexpected_method, 1, 0, 3)
86
86
  end
87
-
87
+
88
88
  def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
89
89
  expectation = new_expectation.with() {|x, y, z| x + y == z}
90
90
  assert !expectation.match?(:expected_method, 1, 0, 3)
91
91
  end
92
-
92
+
93
93
  def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
94
94
  expectation = new_expectation.times(1)
95
95
  assert expectation.invocations_allowed?
96
96
  expectation.invoke([])
97
97
  assert !expectation.invocations_allowed?
98
98
  end
99
-
99
+
100
100
  def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
101
101
  expectation = new_expectation.times(2)
102
102
  assert expectation.invocations_allowed?
@@ -116,18 +116,18 @@ class ExpectationTest < Test::Unit::TestCase
116
116
  expectation.invoke([])
117
117
  assert !expectation.invocations_allowed?
118
118
  end
119
-
119
+
120
120
  def test_should_store_provided_backtrace
121
121
  backtrace = Object.new
122
122
  expectation = Expectation.new(nil, :expected_method, backtrace)
123
123
  assert_equal backtrace, expectation.backtrace
124
124
  end
125
-
125
+
126
126
  def test_should_default_backtrace_to_caller
127
127
  execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
128
128
  assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
129
129
  end
130
-
130
+
131
131
  def test_should_not_yield
132
132
  yielded = false
133
133
  new_expectation.invoke([]) { yielded = true }
@@ -155,7 +155,7 @@ class ExpectationTest < Test::Unit::TestCase
155
155
  expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
156
156
  assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
157
157
  end
158
-
158
+
159
159
  def test_should_yield_multiple_times_for_single_invocation
160
160
  expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5])
161
161
  yielded_parameters = []
@@ -175,20 +175,20 @@ class ExpectationTest < Test::Unit::TestCase
175
175
  expectation = new_expectation.returns(99)
176
176
  assert_equal 99, expectation.invoke([])
177
177
  end
178
-
178
+
179
179
  def test_should_return_same_specified_value_multiple_times
180
180
  expectation = new_expectation.returns(99)
181
181
  assert_equal 99, expectation.invoke([])
182
182
  assert_equal 99, expectation.invoke([])
183
183
  end
184
-
184
+
185
185
  def test_should_return_specified_values_on_consecutive_calls
186
186
  expectation = new_expectation.returns(99, 100, 101)
187
187
  assert_equal 99, expectation.invoke([])
188
188
  assert_equal 100, expectation.invoke([])
189
189
  assert_equal 101, expectation.invoke([])
190
190
  end
191
-
191
+
192
192
  def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
193
193
  values = [99, 100, 101]
194
194
  expectation = new_expectation.returns(*values)
@@ -197,27 +197,27 @@ class ExpectationTest < Test::Unit::TestCase
197
197
  assert_equal 100, expectation.invoke([])
198
198
  assert_equal 101, expectation.invoke([])
199
199
  end
200
-
200
+
201
201
  def test_should_return_nil_by_default
202
202
  assert_nil new_expectation.invoke([])
203
203
  end
204
-
204
+
205
205
  def test_should_return_nil_if_no_value_specified
206
206
  expectation = new_expectation.returns()
207
207
  assert_nil expectation.invoke([])
208
208
  end
209
-
209
+
210
210
  def test_should_raise_runtime_exception
211
211
  expectation = new_expectation.raises
212
212
  assert_raise(RuntimeError) { expectation.invoke([]) }
213
213
  end
214
-
214
+
215
215
  def test_should_raise_custom_exception
216
216
  exception = Class.new(Exception)
217
217
  expectation = new_expectation.raises(exception)
218
218
  assert_raise(exception) { expectation.invoke([]) }
219
219
  end
220
-
220
+
221
221
  def test_should_raise_same_instance_of_custom_exception
222
222
  exception_klass = Class.new(StandardError)
223
223
  expected_exception = exception_klass.new
@@ -225,40 +225,40 @@ class ExpectationTest < Test::Unit::TestCase
225
225
  actual_exception = assert_raise(exception_klass) { expectation.invoke([]) }
226
226
  assert_same expected_exception, actual_exception
227
227
  end
228
-
228
+
229
229
  def test_should_use_the_default_exception_message
230
230
  expectation = new_expectation.raises(Exception)
231
231
  exception = assert_raise(Exception) { expectation.invoke([]) }
232
232
  assert_equal Exception.new.message, exception.message
233
233
  end
234
-
234
+
235
235
  def test_should_raise_custom_exception_with_message
236
236
  exception_msg = "exception message"
237
237
  expectation = new_expectation.raises(Exception, exception_msg)
238
238
  exception = assert_raise(Exception) { expectation.invoke([]) }
239
239
  assert_equal exception_msg, exception.message
240
240
  end
241
-
241
+
242
242
  def test_should_return_values_then_raise_exception
243
243
  expectation = new_expectation.returns(1, 2).then.raises()
244
244
  assert_equal 1, expectation.invoke([])
245
245
  assert_equal 2, expectation.invoke([])
246
246
  assert_raise(RuntimeError) { expectation.invoke([]) }
247
247
  end
248
-
248
+
249
249
  def test_should_raise_exception_then_return_values
250
250
  expectation = new_expectation.raises().then.returns(1, 2)
251
251
  assert_raise(RuntimeError) { expectation.invoke([]) }
252
252
  assert_equal 1, expectation.invoke([])
253
253
  assert_equal 2, expectation.invoke([])
254
254
  end
255
-
255
+
256
256
  def test_should_verify_successfully_if_expected_call_was_made
257
257
  expectation = new_expectation
258
258
  expectation.invoke([])
259
259
  assert expectation.verified?
260
260
  end
261
-
261
+
262
262
  def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
263
263
  expectation = new_expectation.once
264
264
  expectation.invoke([])
@@ -303,19 +303,19 @@ class ExpectationTest < Test::Unit::TestCase
303
303
  3.times {expectation.invoke([])}
304
304
  assert expectation.verified?
305
305
  end
306
-
306
+
307
307
  def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
308
308
  expectation = new_expectation.with(1, 2, 3).at_least_once
309
309
  assert !expectation.verified?
310
310
  assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
311
311
  end
312
-
312
+
313
313
  def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
314
314
  expectation = new_expectation.times(2)
315
315
  2.times {expectation.invoke([])}
316
316
  assert expectation.verified?
317
317
  end
318
-
318
+
319
319
  def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
320
320
  expectation = new_expectation.times(2)
321
321
  1.times {expectation.invoke([])}
@@ -323,13 +323,13 @@ class ExpectationTest < Test::Unit::TestCase
323
323
  assert_match(/expected exactly twice/i, expectation.mocha_inspect)
324
324
  assert_match(/invoked once/i, expectation.mocha_inspect)
325
325
  end
326
-
326
+
327
327
  def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
328
328
  expectation = new_expectation.times(2)
329
329
  3.times {expectation.invoke([])}
330
330
  assert !expectation.verified?
331
331
  end
332
-
332
+
333
333
  def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
334
334
  expectation = new_expectation
335
335
  expectation.invoke([])
@@ -337,21 +337,21 @@ class ExpectationTest < Test::Unit::TestCase
337
337
  expectation.verified?(assertion_counter)
338
338
  assert_equal 1, assertion_counter.count
339
339
  end
340
-
340
+
341
341
  def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
342
342
  stub = Expectation.new(nil, :expected_method).at_least(0)
343
343
  assertion_counter = SimpleCounter.new
344
344
  stub.verified?(assertion_counter)
345
345
  assert_equal 0, assertion_counter.count
346
346
  end
347
-
347
+
348
348
  def test_should_store_backtrace_from_point_where_expectation_was_created
349
349
  execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
350
350
  assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
351
351
  end
352
-
352
+
353
353
  class FakeMock
354
-
354
+
355
355
  def initialize(name)
356
356
  @name = name
357
357
  end
@@ -359,9 +359,9 @@ class ExpectationTest < Test::Unit::TestCase
359
359
  def mocha_inspect
360
360
  @name
361
361
  end
362
-
362
+
363
363
  end
364
-
364
+
365
365
  def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
366
366
  mock = FakeMock.new('mock')
367
367
  sequence_one = Sequence.new('one')
@@ -370,19 +370,19 @@ class ExpectationTest < Test::Unit::TestCase
370
370
  assert !expectation.verified?
371
371
  assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect
372
372
  end
373
-
373
+
374
374
  class FakeConstraint
375
-
375
+
376
376
  def initialize(allows_invocation_now)
377
377
  @allows_invocation_now = allows_invocation_now
378
378
  end
379
-
379
+
380
380
  def allows_invocation_now?
381
381
  @allows_invocation_now
382
382
  end
383
-
383
+
384
384
  end
385
-
385
+
386
386
  def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
387
387
  constraint_one = FakeConstraint.new(allows_invocation_now = true)
388
388
  constraint_two = FakeConstraint.new(allows_invocation_now = true)
@@ -391,7 +391,7 @@ class ExpectationTest < Test::Unit::TestCase
391
391
  expectation.add_ordering_constraint(constraint_two)
392
392
  assert expectation.in_correct_order?
393
393
  end
394
-
394
+
395
395
  def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
396
396
  constraint_one = FakeConstraint.new(allows_invocation_now = true)
397
397
  constraint_two = FakeConstraint.new(allows_invocation_now = false)
@@ -400,7 +400,7 @@ class ExpectationTest < Test::Unit::TestCase
400
400
  expectation.add_ordering_constraint(constraint_two)
401
401
  assert !expectation.in_correct_order?
402
402
  end
403
-
403
+
404
404
  def test_should_match_if_all_ordering_constraints_allow_invocation_now
405
405
  constraint_one = FakeConstraint.new(allows_invocation_now = true)
406
406
  constraint_two = FakeConstraint.new(allows_invocation_now = true)
@@ -441,21 +441,21 @@ class ExpectationTest < Test::Unit::TestCase
441
441
  2.times { expectation.invoke([]) }
442
442
  assert expectation.satisfied?
443
443
  end
444
-
444
+
445
445
  class FakeSequence
446
-
446
+
447
447
  attr_reader :expectations
448
-
448
+
449
449
  def initialize
450
450
  @expectations = []
451
451
  end
452
-
452
+
453
453
  def constrain_as_next_in_sequence(expectation)
454
454
  @expectations << expectation
455
455
  end
456
-
456
+
457
457
  end
458
-
458
+
459
459
  def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
460
460
  sequence_one = FakeSequence.new
461
461
  sequence_two = FakeSequence.new
@@ -464,23 +464,23 @@ class ExpectationTest < Test::Unit::TestCase
464
464
  assert_equal [expectation], sequence_one.expectations
465
465
  assert_equal [expectation], sequence_two.expectations
466
466
  end
467
-
467
+
468
468
  class FakeState
469
-
469
+
470
470
  def initialize
471
471
  @active = false
472
472
  end
473
-
473
+
474
474
  def activate
475
475
  @active = true
476
476
  end
477
-
477
+
478
478
  def active?
479
479
  @active
480
480
  end
481
-
481
+
482
482
  end
483
-
483
+
484
484
  def test_should_change_state_when_expectation_is_invoked
485
485
  state = FakeState.new
486
486
  expectation = Expectation.new(nil, :method_one)
@@ -490,14 +490,14 @@ class ExpectationTest < Test::Unit::TestCase
490
490
  expectation.invoke([])
491
491
  assert state.active?
492
492
  end
493
-
493
+
494
494
  def test_should_match_when_state_is_active
495
495
  state = FakeState.new
496
496
  expectation = Expectation.new(nil, :method_one)
497
497
 
498
498
  expectation.when(state)
499
499
  assert !expectation.match?(:method_one)
500
-
500
+
501
501
  state.activate
502
502
  assert expectation.match?(:method_one)
503
503
  end
@@ -526,5 +526,5 @@ class ExpectationTest < Test::Unit::TestCase
526
526
  expectation.invocation_count = 3
527
527
  assert_equal 3, expectation.invocation_count
528
528
  end
529
-
529
+
530
530
  end