File: yield_parameters_test.rb

package info (click to toggle)
ruby-mocha 2.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,540 kB
  • sloc: ruby: 11,899; javascript: 477; makefile: 14
file content (73 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require File.expand_path('../../test_helper', __FILE__)

require 'mocha/yield_parameters'

class YieldParametersTest < Mocha::TestCase
  include Mocha

  def test_should_return_null_yield_parameter_group_by_default
    assert_next_invocation_yields(YieldParameters.new, [])
  end

  def test_should_return_single_yield_parameter_group
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
  end

  def test_should_keep_returning_single_yield_parameter_group
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
  end

  def test_should_return_consecutive_single_yield_parameter_groups
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3])
    yield_parameters.add([4, 5])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
    assert_next_invocation_yields(yield_parameters, [[4, 5]])
  end

  def test_should_return_multiple_yield_parameter_group
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3], [4, 5])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
  end

  def test_should_return_multiple_yield_parameter_group_when_arguments_are_not_arrays
    yield_parameters = YieldParameters.new
    yield_parameters.add(1, { b: 2 }, 3)
    assert_next_invocation_yields(yield_parameters, [[1], [{ b: 2 }], [3]])
  end

  def test_should_keep_returning_multiple_yield_parameter_group
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3], [4, 5])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
  end

  def test_should_return_consecutive_multiple_yield_parameter_groups
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3], [4, 5])
    yield_parameters.add([6, 7], [8, 9, 0])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3], [4, 5]])
    assert_next_invocation_yields(yield_parameters, [[6, 7], [8, 9, 0]])
  end

  def test_should_return_consecutive_single_and_multiple_yield_parameter_groups
    yield_parameters = YieldParameters.new
    yield_parameters.add([1, 2, 3])
    yield_parameters.add([4, 5, 6], [7, 8])
    assert_next_invocation_yields(yield_parameters, [[1, 2, 3]])
    assert_next_invocation_yields(yield_parameters, [[4, 5, 6], [7, 8]])
  end

  private

  def assert_next_invocation_yields(yield_parameters, expected)
    assert_equal expected, yield_parameters.next_invocation
  end
end