mocha 1.10.2 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.yardopts +1 -0
  4. data/RELEASE.md +18 -0
  5. data/Rakefile +1 -4
  6. data/docs/Mocha.html +2 -2
  7. data/docs/Mocha/API.html +2 -2
  8. data/docs/Mocha/ClassMethods.html +2 -2
  9. data/docs/Mocha/Configuration.html +2 -2
  10. data/docs/Mocha/Expectation.html +284 -76
  11. data/docs/Mocha/ExpectationError.html +2 -2
  12. data/docs/Mocha/ExpectationErrorFactory.html +2 -2
  13. data/docs/Mocha/Hooks.html +2 -2
  14. data/docs/Mocha/Integration.html +2 -2
  15. data/docs/Mocha/Integration/MiniTest.html +2 -2
  16. data/docs/Mocha/Integration/MiniTest/Adapter.html +2 -2
  17. data/docs/Mocha/Integration/TestUnit.html +2 -2
  18. data/docs/Mocha/Integration/TestUnit/Adapter.html +2 -2
  19. data/docs/Mocha/Mock.html +2 -2
  20. data/docs/Mocha/ObjectMethods.html +2 -2
  21. data/docs/Mocha/ParameterMatchers.html +2 -2
  22. data/docs/Mocha/ParameterMatchers/AllOf.html +2 -2
  23. data/docs/Mocha/ParameterMatchers/AnyOf.html +2 -2
  24. data/docs/Mocha/ParameterMatchers/AnyParameters.html +2 -2
  25. data/docs/Mocha/ParameterMatchers/Anything.html +2 -2
  26. data/docs/Mocha/ParameterMatchers/Base.html +2 -2
  27. data/docs/Mocha/ParameterMatchers/Equals.html +2 -2
  28. data/docs/Mocha/ParameterMatchers/EquivalentUri.html +2 -2
  29. data/docs/Mocha/ParameterMatchers/HasEntries.html +2 -2
  30. data/docs/Mocha/ParameterMatchers/HasEntry.html +2 -2
  31. data/docs/Mocha/ParameterMatchers/HasKey.html +2 -2
  32. data/docs/Mocha/ParameterMatchers/HasValue.html +2 -2
  33. data/docs/Mocha/ParameterMatchers/Includes.html +2 -2
  34. data/docs/Mocha/ParameterMatchers/InstanceOf.html +2 -2
  35. data/docs/Mocha/ParameterMatchers/IsA.html +2 -2
  36. data/docs/Mocha/ParameterMatchers/KindOf.html +2 -2
  37. data/docs/Mocha/ParameterMatchers/Not.html +2 -2
  38. data/docs/Mocha/ParameterMatchers/Optionally.html +2 -2
  39. data/docs/Mocha/ParameterMatchers/RegexpMatches.html +2 -2
  40. data/docs/Mocha/ParameterMatchers/RespondsWith.html +2 -2
  41. data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +2 -2
  42. data/docs/Mocha/Sequence.html +2 -2
  43. data/docs/Mocha/StateMachine.html +2 -2
  44. data/docs/Mocha/StateMachine/State.html +2 -2
  45. data/docs/Mocha/StateMachine/StatePredicate.html +2 -2
  46. data/docs/Mocha/StubbingError.html +2 -2
  47. data/docs/_index.html +3 -3
  48. data/docs/file.COPYING.html +2 -2
  49. data/docs/file.MIT-LICENSE.html +2 -2
  50. data/docs/file.README.html +2 -2
  51. data/docs/file.RELEASE.html +30 -2
  52. data/docs/frames.html +1 -1
  53. data/docs/index.html +2 -2
  54. data/docs/method_list.html +20 -4
  55. data/docs/top-level-namespace.html +2 -2
  56. data/lib/mocha/block_matcher.rb +31 -0
  57. data/lib/mocha/expectation.rb +47 -6
  58. data/lib/mocha/invocation.rb +9 -5
  59. data/lib/mocha/version.rb +1 -1
  60. data/lib/mocha/yield_parameters.rb +5 -11
  61. data/test/acceptance/acceptance_test_helper.rb +1 -0
  62. data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +5 -5
  63. data/test/acceptance/failure_messages_test.rb +16 -0
  64. data/test/acceptance/multiple_yielding_test.rb +56 -0
  65. data/test/acceptance/yielding_test.rb +78 -0
  66. data/test/unit/expectation_test.rb +15 -1
  67. data/test/unit/yield_parameters_test.rb +35 -53
  68. metadata +6 -8
  69. data/lib/mocha/multiple_yields.rb +0 -15
  70. data/lib/mocha/no_yields.rb +0 -5
  71. data/lib/mocha/single_yield.rb +0 -13
  72. data/test/unit/multiple_yields_test.rb +0 -16
  73. data/test/unit/no_yields_test.rb +0 -16
  74. data/test/unit/single_yield_test.rb +0 -16
@@ -10,6 +10,7 @@ require 'mocha/in_state_ordering_constraint'
10
10
  require 'mocha/change_state_side_effect'
11
11
  require 'mocha/cardinality'
12
12
  require 'mocha/configuration'
13
+ require 'mocha/block_matcher'
13
14
 
14
15
  module Mocha
15
16
  # Methods on expectations returned from {Mock#expects}, {Mock#stubs}, {ObjectMethods#expects} and {ObjectMethods#stubs}.
@@ -224,6 +225,44 @@ module Mocha
224
225
  self
225
226
  end
226
227
 
228
+ # Modifies expectation so that the expected method must be called with a block.
229
+ #
230
+ # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
231
+ #
232
+ # @example Expected method must be called with a block.
233
+ # object = mock()
234
+ # object.expects(:expected_method).with_block_given
235
+ # object.expected_method { 1 + 1 }
236
+ # # => verify succeeds
237
+ #
238
+ # object = mock()
239
+ # object.expects(:expected_method).with_block_given
240
+ # object.expected_method
241
+ # # => verify fails
242
+ def with_block_given
243
+ @block_matcher = BlockMatchers::BlockGiven.new
244
+ self
245
+ end
246
+
247
+ # Modifies expectation so that the expected method must be called without a block.
248
+ #
249
+ # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
250
+ #
251
+ # @example Expected method must be called without a block.
252
+ # object = mock()
253
+ # object.expects(:expected_method).with_no_block_given
254
+ # object.expected_method
255
+ # # => verify succeeds
256
+ #
257
+ # object = mock()
258
+ # object.expects(:expected_method).with_block_given
259
+ # object.expected_method { 1 + 1 }
260
+ # # => verify fails
261
+ def with_no_block_given
262
+ @block_matcher = BlockMatchers::NoBlockGiven.new
263
+ self
264
+ end
265
+
227
266
  # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+ (even if no block is provided, in which case yielding will result in a +LocalJumpError+).
228
267
  #
229
268
  # May be called multiple times on the same expectation for consecutive invocations.
@@ -256,13 +295,12 @@ module Mocha
256
295
  # fibonacci.next_pair { |first, second| sum = first + second }
257
296
  # sum # => 2
258
297
  def yields(*parameters)
259
- @yield_parameters.add(*parameters)
260
- self
298
+ multiple_yields(parameters)
261
299
  end
262
300
 
263
301
  # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+ (even if no block is provided, in which case yielding will result in a +LocalJumpError+).
264
302
  #
265
- # @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield.
303
+ # @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield. Any element of +parameter_groups+ that is not an +Array+ is wrapped in an +Array+.
266
304
  # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
267
305
  # @see #then
268
306
  #
@@ -283,7 +321,7 @@ module Mocha
283
321
  # rows_from_first_invocation # => [['old_row1_col1', 'old_row1_col2'], ['old_row2_col1', '']]
284
322
  # rows_from_second_invocation # => [['new_row1_col1', ''], ['new_row2_col1', 'new_row2_col2']]
285
323
  def multiple_yields(*parameter_groups)
286
- @yield_parameters.multiple_add(*parameter_groups)
324
+ @yield_parameters.add(*parameter_groups)
287
325
  self
288
326
  end
289
327
 
@@ -511,6 +549,7 @@ module Mocha
511
549
  @mock = mock
512
550
  @method_matcher = MethodMatcher.new(expected_method_name.to_sym)
513
551
  @parameters_matcher = ParametersMatcher.new
552
+ @block_matcher = BlockMatchers::OptionalBlock.new
514
553
  @ordering_constraints = []
515
554
  @side_effects = []
516
555
  @cardinality = Cardinality.exactly(1)
@@ -551,7 +590,7 @@ module Mocha
551
590
 
552
591
  # @private
553
592
  def match?(invocation)
554
- @method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && in_correct_order?
593
+ @method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && @block_matcher.match?(invocation.block) && in_correct_order?
555
594
  end
556
595
 
557
596
  # @private
@@ -601,7 +640,9 @@ module Mocha
601
640
 
602
641
  # @private
603
642
  def method_signature
604
- "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
643
+ signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
644
+ signature << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
645
+ signature
605
646
  end
606
647
  end
607
648
  end
@@ -8,7 +8,7 @@ require 'mocha/deprecation'
8
8
 
9
9
  module Mocha
10
10
  class Invocation
11
- attr_reader :method_name
11
+ attr_reader :method_name, :block
12
12
 
13
13
  def initialize(mock, method_name, *arguments, &block)
14
14
  @mock = mock
@@ -27,10 +27,12 @@ module Mocha
27
27
  else
28
28
  raise LocalJumpError unless Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
29
29
  yield_args_description = ParametersMatcher.new(yield_args).mocha_inspect
30
- Deprecation.warning([
30
+ Deprecation.warning(
31
31
  "Stubbed method was instructed to yield #{yield_args_description}, but no block was given by invocation: #{call_description}.",
32
- 'This will raise a LocalJumpError in the future.'
33
- ].join(' '))
32
+ ' This will raise a LocalJumpError in the future.',
33
+ ' Use Expectation#with_block_given to constrain this expectation to match invocations supplying a block.',
34
+ ' And, if necessary, add another expectation to match invocations not supplying a block.'
35
+ )
34
36
  end
35
37
  end
36
38
  return_values.next(self)
@@ -53,7 +55,9 @@ module Mocha
53
55
  end
54
56
 
55
57
  def call_description
56
- "#{@mock.mocha_inspect}.#{@method_name}#{ParametersMatcher.new(@arguments).mocha_inspect}"
58
+ description = "#{@mock.mocha_inspect}.#{@method_name}#{ParametersMatcher.new(@arguments).mocha_inspect}"
59
+ description << ' { ... }' unless @block.nil?
60
+ description
57
61
  end
58
62
 
59
63
  def short_call_description
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '1.10.2'.freeze
2
+ VERSION = '1.11.0'.freeze
3
3
  end
@@ -1,7 +1,3 @@
1
- require 'mocha/no_yields'
2
- require 'mocha/single_yield'
3
- require 'mocha/multiple_yields'
4
-
5
1
  module Mocha
6
2
  class YieldParameters
7
3
  def initialize
@@ -10,18 +6,16 @@ module Mocha
10
6
 
11
7
  def next_invocation
12
8
  case @parameter_groups.length
13
- when 0 then NoYields.new
9
+ when 0 then []
14
10
  when 1 then @parameter_groups.first
15
11
  else @parameter_groups.shift
16
12
  end
17
13
  end
18
14
 
19
- def add(*parameters)
20
- @parameter_groups << SingleYield.new(*parameters)
21
- end
22
-
23
- def multiple_add(*parameter_groups)
24
- @parameter_groups << MultipleYields.new(*parameter_groups)
15
+ def add(*parameter_groups)
16
+ @parameter_groups << parameter_groups.map do |pg|
17
+ pg.is_a?(Array) ? pg : [pg]
18
+ end
25
19
  end
26
20
  end
27
21
  end
@@ -1,6 +1,7 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'test_runner'
3
3
  require 'mocha/configuration'
4
+ require 'mocha/mockery'
4
5
  require 'introspection'
5
6
 
6
7
  if Mocha::Detection::MiniTest.testcase && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit')
@@ -31,7 +31,7 @@ class DisplayMatchingInvocationsAlongsideExpectationsTest < Mocha::TestCase
31
31
  test_result = run_as_test do
32
32
  foo = mock('foo')
33
33
  foo.expects(:bar).with(1).returns('a')
34
- foo.stubs(:bar).with(any_parameters).multiple_yields(%w[b c], %w[d e]).returns('f').raises(StandardError).throws(:tag, 'value')
34
+ foo.stubs(:bar).with(any_parameters).multiple_yields('bc', %w[d e]).returns('f').raises(StandardError).throws(:tag, 'value')
35
35
 
36
36
  foo.bar(1, 2) { |_ignored| }
37
37
  assert_raises(StandardError) { foo.bar(3, 4) { |_ignored| } }
@@ -40,9 +40,9 @@ class DisplayMatchingInvocationsAlongsideExpectationsTest < Mocha::TestCase
40
40
  assert_invocations(
41
41
  test_result,
42
42
  '- allowed any number of times, invoked 3 times: #<Mock:foo>.bar(any_parameters)',
43
- ' - #<Mock:foo>.bar(1, 2) # => "f" after yielding ("b", "c"), then ("d", "e")',
44
- ' - #<Mock:foo>.bar(3, 4) # => raised StandardError after yielding ("b", "c"), then ("d", "e")',
45
- ' - #<Mock:foo>.bar(5, 6) # => threw (:tag, "value") after yielding ("b", "c"), then ("d", "e")'
43
+ ' - #<Mock:foo>.bar(1, 2) { ... } # => "f" after yielding ("bc"), then ("d", "e")',
44
+ ' - #<Mock:foo>.bar(3, 4) { ... } # => raised StandardError after yielding ("bc"), then ("d", "e")',
45
+ ' - #<Mock:foo>.bar(5, 6) { ... } # => threw (:tag, "value") after yielding ("bc"), then ("d", "e")'
46
46
  )
47
47
  end
48
48
 
@@ -57,7 +57,7 @@ class DisplayMatchingInvocationsAlongsideExpectationsTest < Mocha::TestCase
57
57
  assert_invocations(
58
58
  test_result,
59
59
  '- allowed any number of times, invoked once: #<Mock:foo>.bar(any_parameters)',
60
- ' - #<Mock:foo>.bar(1, 2) # => nil after yielding ()'
60
+ ' - #<Mock:foo>.bar(1, 2) { ... } # => nil after yielding ()'
61
61
  )
62
62
  end
63
63
 
@@ -58,4 +58,20 @@ class FailureMessagesTest < Mocha::TestCase
58
58
  end
59
59
  assert_match Regexp.new(%("Foo")), test_result.failures[0].message
60
60
  end
61
+
62
+ def test_should_display_that_block_was_expected
63
+ test_result = run_as_test do
64
+ foo = mock
65
+ foo.expects(:bar).with_block_given
66
+ end
67
+ assert_match Regexp.new(' with block given$'), test_result.failures[0].message
68
+ end
69
+
70
+ def test_should_display_that_block_was_not_expected
71
+ test_result = run_as_test do
72
+ foo = mock
73
+ foo.expects(:bar).with_no_block_given
74
+ end
75
+ assert_match Regexp.new(' with no block given$'), test_result.failures[0].message
76
+ end
61
77
  end
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+
3
+ class MultipleYieldingTest < Mocha::TestCase
4
+ include AcceptanceTest
5
+
6
+ def setup
7
+ setup_acceptance_test
8
+ end
9
+
10
+ def teardown
11
+ teardown_acceptance_test
12
+ end
13
+
14
+ def test_yields_values_multiple_times_when_stubbed_method_is_invoked
15
+ test_result = run_as_test do
16
+ m = mock('m')
17
+ m.stubs(:foo).multiple_yields([1], [2, 3])
18
+ yielded = []
19
+ m.foo { |*args| yielded << args }
20
+ assert_equal [[1], [2, 3]], yielded
21
+ end
22
+ assert_passed(test_result)
23
+ end
24
+
25
+ def test_yields_values_multiple_times_when_multiple_yields_arguments_are_not_arrays
26
+ test_result = run_as_test do
27
+ m = mock('m')
28
+ m.stubs(:foo).multiple_yields(1, { :b => 2 }, '3')
29
+ yielded = []
30
+ m.foo { |*args| yielded << args }
31
+ assert_equal [[1], [{ :b => 2 }], ['3']], yielded
32
+ end
33
+ assert_passed(test_result)
34
+ end
35
+
36
+ def test_raises_local_jump_error_if_instructed_to_multiple_yield_but_no_block_given
37
+ test_result = run_as_test do
38
+ m = mock('m')
39
+ m.stubs(:foo).multiple_yields([])
40
+ assert_raises(LocalJumpError) { m.foo }
41
+ end
42
+ assert_passed(test_result)
43
+ end
44
+
45
+ def test_yields_different_values_on_consecutive_invocations
46
+ test_result = run_as_test do
47
+ m = mock('m')
48
+ m.stubs(:foo).multiple_yields([0], [1, 2]).then.multiple_yields([3], [4, 5])
49
+ yielded = []
50
+ m.foo { |*args| yielded << args }
51
+ m.foo { |*args| yielded << args }
52
+ assert_equal [[0], [1, 2], [3], [4, 5]], yielded
53
+ end
54
+ assert_passed(test_result)
55
+ end
56
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+
3
+ class YieldingTest < Mocha::TestCase
4
+ include AcceptanceTest
5
+
6
+ def setup
7
+ setup_acceptance_test
8
+ end
9
+
10
+ def teardown
11
+ teardown_acceptance_test
12
+ end
13
+
14
+ def test_yields_when_stubbed_method_is_invoked
15
+ test_result = run_as_test do
16
+ m = mock('m')
17
+ m.stubs(:foo).yields
18
+ yielded = false
19
+ m.foo { yielded = true }
20
+ assert yielded
21
+ end
22
+ assert_passed(test_result)
23
+ end
24
+
25
+ def test_raises_local_jump_error_if_instructed_to_yield_but_no_block_given
26
+ test_result = run_as_test do
27
+ m = mock('m')
28
+ m.stubs(:foo).yields
29
+ assert_raises(LocalJumpError) { m.foo }
30
+ end
31
+ assert_passed(test_result)
32
+ end
33
+
34
+ def test_yields_when_block_expected_and_block_given
35
+ test_result = run_as_test do
36
+ m = mock('m')
37
+ m.stubs(:foo).with_block_given.yields
38
+ m.stubs(:foo).with_no_block_given.returns(:bar)
39
+ yielded = false
40
+ m.foo { yielded = true }
41
+ assert yielded
42
+ end
43
+ assert_passed(test_result)
44
+ end
45
+
46
+ def test_returns_when_no_block_expected_and_no_block_given
47
+ test_result = run_as_test do
48
+ m = mock('m')
49
+ m.stubs(:foo).with_block_given.yields
50
+ m.stubs(:foo).with_no_block_given.returns(:bar)
51
+ assert_equal :bar, m.foo
52
+ end
53
+ assert_passed(test_result)
54
+ end
55
+
56
+ def test_yields_values_when_stubbed_method_is_invoked
57
+ test_result = run_as_test do
58
+ m = mock('m')
59
+ m.stubs(:foo).yields(0, 1)
60
+ yielded = []
61
+ m.foo { |*args| yielded << args }
62
+ assert_equal [[0, 1]], yielded
63
+ end
64
+ assert_passed(test_result)
65
+ end
66
+
67
+ def test_yields_different_values_on_consecutive_invocations
68
+ test_result = run_as_test do
69
+ m = mock('m')
70
+ m.stubs(:foo).yields(0, 1).then.yields(2, 3)
71
+ yielded = []
72
+ m.foo { |*args| yielded << args }
73
+ m.foo { |*args| yielded << args }
74
+ assert_equal [[0, 1], [2, 3]], yielded
75
+ end
76
+ assert_passed(test_result)
77
+ end
78
+ end
@@ -8,6 +8,7 @@ require 'execution_point'
8
8
  require 'simple_counter'
9
9
  require 'deprecation_disabler'
10
10
 
11
+ # rubocop:disable Metrics/ClassLength
11
12
  class ExpectationTest < Mocha::TestCase
12
13
  include Mocha
13
14
 
@@ -119,7 +120,7 @@ class ExpectationTest < Mocha::TestCase
119
120
  assert_raises(LocalJumpError) { invoke(new_expectation.yields(:foo)) }
120
121
  end
121
122
 
122
- def test_yield_should_display_warning_when_caller_does_not_provide_block_and_behaviour_from_v1_9_retained
123
+ def test_yields_should_display_warning_when_caller_does_not_provide_block_and_behaviour_from_v1_9_retained
123
124
  Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => true) do
124
125
  DeprecationDisabler.disable_deprecations do
125
126
  invoke(new_expectation.yields(:foo, 1, [2, 3]))
@@ -131,6 +132,18 @@ class ExpectationTest < Mocha::TestCase
131
132
  assert message.include?('This will raise a LocalJumpError in the future.')
132
133
  end
133
134
 
135
+ def test_multiple_yields_should_display_warning_when_caller_does_not_provide_block_and_behaviour_from_v1_9_retained
136
+ Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => true) do
137
+ DeprecationDisabler.disable_deprecations do
138
+ invoke(new_expectation.multiple_yields(:foo, 1, [2, 3]))
139
+ end
140
+ end
141
+ assert message = Deprecation.messages.last
142
+ assert message.include?('Stubbed method was instructed to yield (2, 3)')
143
+ assert message.include?('but no block was given by invocation: :irrelevant.expected_method()')
144
+ assert message.include?('This will raise a LocalJumpError in the future.')
145
+ end
146
+
134
147
  def test_should_yield_with_specified_parameters
135
148
  yielded_parameters = nil
136
149
  invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }
@@ -490,3 +503,4 @@ class ExpectationTest < Mocha::TestCase
490
503
  assert expectation.inspect.include?(expectation.mocha_inspect)
491
504
  end
492
505
  end
506
+ # rubocop:enable Metrics/ClassLength
@@ -1,91 +1,73 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  require 'mocha/yield_parameters'
4
- require 'mocha/no_yields'
5
- require 'mocha/single_yield'
6
- require 'mocha/multiple_yields'
7
4
 
8
5
  class YieldParametersTest < Mocha::TestCase
9
6
  include Mocha
10
7
 
11
8
  def test_should_return_null_yield_parameter_group_by_default
12
- yield_parameters = YieldParameters.new
13
- assert yield_parameters.next_invocation.is_a?(NoYields)
9
+ assert_next_invocation_yields(YieldParameters.new, [])
14
10
  end
15
11
 
16
12
  def test_should_return_single_yield_parameter_group
17
13
  yield_parameters = YieldParameters.new
18
- yield_parameters.add(1, 2, 3)
19
- parameter_group = yield_parameters.next_invocation
20
- assert parameter_group.is_a?(SingleYield)
21
- assert_equal [1, 2, 3], parameter_group.parameters
14
+ yield_parameters.add([1, 2, 3])
15
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
22
16
  end
23
17
 
24
18
  def test_should_keep_returning_single_yield_parameter_group
25
19
  yield_parameters = YieldParameters.new
26
- yield_parameters.add(1, 2, 3)
27
- yield_parameters.next_invocation
28
- parameter_group = yield_parameters.next_invocation
29
- assert parameter_group.is_a?(SingleYield)
30
- assert_equal [1, 2, 3], parameter_group.parameters
31
- parameter_group = yield_parameters.next_invocation
32
- assert parameter_group.is_a?(SingleYield)
33
- assert_equal [1, 2, 3], parameter_group.parameters
20
+ yield_parameters.add([1, 2, 3])
21
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
22
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
34
23
  end
35
24
 
36
25
  def test_should_return_consecutive_single_yield_parameter_groups
37
26
  yield_parameters = YieldParameters.new
38
- yield_parameters.add(1, 2, 3)
39
- yield_parameters.add(4, 5)
40
- parameter_group = yield_parameters.next_invocation
41
- assert parameter_group.is_a?(SingleYield)
42
- assert_equal [1, 2, 3], parameter_group.parameters
43
- parameter_group = yield_parameters.next_invocation
44
- assert parameter_group.is_a?(SingleYield)
45
- assert_equal [4, 5], parameter_group.parameters
27
+ yield_parameters.add([1, 2, 3])
28
+ yield_parameters.add([4, 5])
29
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
30
+ assert_next_invocation_yields(yield_parameters, [[4, 5]])
46
31
  end
47
32
 
48
33
  def test_should_return_multiple_yield_parameter_group
49
34
  yield_parameters = YieldParameters.new
50
- yield_parameters.multiple_add([1, 2, 3], [4, 5])
51
- parameter_group = yield_parameters.next_invocation
52
- assert parameter_group.is_a?(MultipleYields)
53
- assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
35
+ yield_parameters.add([1, 2, 3], [4, 5])
36
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
37
+ end
38
+
39
+ def test_should_return_multiple_yield_parameter_group_when_arguments_are_not_arrays
40
+ yield_parameters = YieldParameters.new
41
+ yield_parameters.add(1, { :b => 2 }, 3)
42
+ assert_next_invocation_yields(yield_parameters, [[1], [{ :b => 2 }], [3]])
54
43
  end
55
44
 
56
45
  def test_should_keep_returning_multiple_yield_parameter_group
57
46
  yield_parameters = YieldParameters.new
58
- yield_parameters.multiple_add([1, 2, 3], [4, 5])
59
- yield_parameters.next_invocation
60
- parameter_group = yield_parameters.next_invocation
61
- assert parameter_group.is_a?(MultipleYields)
62
- assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
63
- parameter_group = yield_parameters.next_invocation
64
- assert parameter_group.is_a?(MultipleYields)
65
- assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
47
+ yield_parameters.add([1, 2, 3], [4, 5])
48
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
49
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
66
50
  end
67
51
 
68
52
  def test_should_return_consecutive_multiple_yield_parameter_groups
69
53
  yield_parameters = YieldParameters.new
70
- yield_parameters.multiple_add([1, 2, 3], [4, 5])
71
- yield_parameters.multiple_add([6, 7], [8, 9, 0])
72
- parameter_group = yield_parameters.next_invocation
73
- assert parameter_group.is_a?(MultipleYields)
74
- assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
75
- parameter_group = yield_parameters.next_invocation
76
- assert parameter_group.is_a?(MultipleYields)
77
- assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups
54
+ yield_parameters.add([1, 2, 3], [4, 5])
55
+ yield_parameters.add([6, 7], [8, 9, 0])
56
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
57
+ assert_next_invocation_yields(yield_parameters, [[6, 7], [8, 9, 0]])
78
58
  end
79
59
 
80
60
  def test_should_return_consecutive_single_and_multiple_yield_parameter_groups
81
61
  yield_parameters = YieldParameters.new
82
- yield_parameters.add(1, 2, 3)
83
- yield_parameters.multiple_add([4, 5, 6], [7, 8])
84
- parameter_group = yield_parameters.next_invocation
85
- assert parameter_group.is_a?(SingleYield)
86
- assert_equal [1, 2, 3], parameter_group.parameters
87
- parameter_group = yield_parameters.next_invocation
88
- assert parameter_group.is_a?(MultipleYields)
89
- assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups
62
+ yield_parameters.add([1, 2, 3])
63
+ yield_parameters.add([4, 5, 6], [7, 8])
64
+ assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
65
+ assert_next_invocation_yields(yield_parameters, [[4, 5, 6], [7, 8]])
66
+ end
67
+
68
+ private
69
+
70
+ def assert_next_invocation_yields(yield_parameters, expected)
71
+ assert_equal expected, yield_parameters.next_invocation
90
72
  end
91
73
  end