mocha 0.10.5 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +24 -0
- data/CONTRIBUTING.md +7 -0
- data/COPYING.md +3 -0
- data/Gemfile +2 -2
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +1 -1
- data/README.md +363 -0
- data/{RELEASE.rdoc → RELEASE.md} +436 -35
- data/Rakefile +87 -87
- data/gemfiles/Gemfile.minitest.latest +2 -2
- data/gemfiles/Gemfile.test-unit.latest +6 -2
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +12 -45
- data/lib/mocha/api.rb +199 -131
- data/lib/mocha/argument_iterator.rb +6 -10
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +77 -66
- data/lib/mocha/central.rb +27 -18
- data/lib/mocha/change_state_side_effect.rb +3 -7
- data/lib/mocha/class_methods.rb +62 -0
- data/lib/mocha/configuration.rb +399 -46
- data/lib/mocha/debug.rb +12 -0
- data/lib/mocha/deprecation.rb +11 -12
- data/lib/mocha/detection/mini_test.rb +23 -0
- data/lib/mocha/detection/test_unit.rb +27 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +8 -10
- data/lib/mocha/expectation.rb +290 -151
- data/lib/mocha/expectation_error.rb +6 -13
- data/lib/mocha/expectation_error_factory.rb +35 -0
- data/lib/mocha/expectation_list.rb +22 -22
- data/lib/mocha/hooks.rb +42 -0
- data/lib/mocha/in_state_ordering_constraint.rb +3 -7
- data/lib/mocha/inspect.rb +35 -43
- data/lib/mocha/instance_method.rb +12 -21
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test/adapter.rb +52 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -7
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +35 -25
- data/lib/mocha/integration/mini_test/version_140.rb +35 -26
- data/lib/mocha/integration/mini_test/version_141.rb +43 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +44 -35
- data/lib/mocha/integration/mini_test/version_200.rb +45 -36
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +44 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +70 -0
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +73 -0
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +68 -0
- data/lib/mocha/integration/mini_test.rb +51 -49
- data/lib/mocha/integration/monkey_patcher.rb +24 -0
- data/lib/mocha/integration/test_unit/adapter.rb +50 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +68 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +39 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +40 -30
- data/lib/mocha/integration/test_unit.rb +45 -51
- data/lib/mocha/integration.rb +6 -33
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +2 -6
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +6 -10
- data/lib/mocha/minitest.rb +8 -0
- data/lib/mocha/mock.rb +266 -79
- data/lib/mocha/mockery.rb +104 -106
- data/lib/mocha/names.rb +10 -20
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +169 -0
- data/lib/mocha/parameter_matchers/all_of.rb +18 -14
- data/lib/mocha/parameter_matchers/any_of.rb +19 -14
- data/lib/mocha/parameter_matchers/any_parameters.rb +14 -13
- data/lib/mocha/parameter_matchers/anything.rb +17 -14
- data/lib/mocha/parameter_matchers/base.rb +33 -31
- data/lib/mocha/parameter_matchers/equals.rb +18 -13
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +58 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +19 -14
- data/lib/mocha/parameter_matchers/has_entry.rb +58 -26
- data/lib/mocha/parameter_matchers/has_key.rb +18 -13
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +18 -13
- data/lib/mocha/parameter_matchers/includes.rb +80 -19
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +18 -13
- data/lib/mocha/parameter_matchers/is_a.rb +20 -14
- data/lib/mocha/parameter_matchers/kind_of.rb +20 -13
- data/lib/mocha/parameter_matchers/not.rb +19 -14
- data/lib/mocha/parameter_matchers/optionally.rb +23 -17
- data/lib/mocha/parameter_matchers/regexp_matches.rb +16 -12
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -11
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +15 -9
- data/lib/mocha/parameter_matchers.rb +4 -5
- data/lib/mocha/parameters_matcher.rb +11 -14
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +45 -0
- data/lib/mocha/return_values.rb +11 -15
- data/lib/mocha/ruby_version.rb +4 -0
- data/lib/mocha/sequence.rb +21 -17
- data/lib/mocha/setup.rb +14 -0
- data/lib/mocha/single_return_value.rb +5 -8
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +69 -67
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/stubbing_error.rb +6 -14
- data/lib/mocha/test_unit.rb +8 -0
- data/lib/mocha/thrower.rb +6 -8
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +12 -22
- data/lib/mocha.rb +8 -3
- data/mocha.gemspec +43 -34
- data/yard-templates/default/layout/html/google_analytics.erb +8 -0
- data/yard-templates/default/layout/html/setup.rb +5 -0
- metadata +123 -268
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -54
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -8
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -98
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_230_to_262.rb +0 -59
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_240.rb +0 -58
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/object.rb +0 -223
- data/lib/mocha/options.rb +0 -1
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/parameter_matchers/query_string.rb +0 -47
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -1
- data/lib/mocha/unexpected_invocation.rb +0 -18
- data/lib/mocha_standalone.rb +0 -2
- data/lib/stubba.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/bug_18914_test.rb +0 -43
- data/test/acceptance/bug_21465_test.rb +0 -34
- data/test/acceptance/bug_21563_test.rb +0 -25
- data/test/acceptance/exception_rescue_test.rb +0 -55
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -232
- data/test/acceptance/failure_messages_test.rb +0 -64
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/acceptance/mocha_example_test.rb +0 -98
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -100
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
- data/test/acceptance/optional_parameters_test.rb +0 -70
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/raise_exception_test.rb +0 -39
- data/test/acceptance/return_value_test.rb +0 -52
- data/test/acceptance/sequence_test.rb +0 -192
- data/test/acceptance/states_test.rb +0 -70
- data/test/acceptance/stub_any_instance_method_test.rb +0 -198
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -72
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -75
- data/test/acceptance/stub_everything_test.rb +0 -56
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -66
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
- data/test/acceptance/stub_module_method_test.rb +0 -163
- data/test/acceptance/stub_test.rb +0 -52
- data/test/acceptance/stubba_example_test.rb +0 -102
- data/test/acceptance/stubba_test.rb +0 -15
- data/test/acceptance/stubba_test_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unstubbing_test.rb +0 -151
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -83
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -11
- data/test/test_runner.rb +0 -50
- data/test/unit/any_instance_method_test.rb +0 -136
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/backtrace_filter_test.rb +0 -19
- data/test/unit/cardinality_test.rb +0 -56
- data/test/unit/central_test.rb +0 -100
- data/test/unit/change_state_side_effect_test.rb +0 -41
- data/test/unit/class_method_test.rb +0 -260
- data/test/unit/configuration_test.rb +0 -38
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/exception_raiser_test.rb +0 -42
- data/test/unit/expectation_list_test.rb +0 -71
- data/test/unit/expectation_test.rb +0 -480
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -23
- data/test/unit/mock_test.rb +0 -312
- data/test/unit/mockery_test.rb +0 -150
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yields_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -38
- data/test/unit/object_test.rb +0 -87
- data/test/unit/parameter_matchers/all_of_test.rb +0 -26
- data/test/unit/parameter_matchers/any_of_test.rb +0 -26
- data/test/unit/parameter_matchers/anything_test.rb +0 -21
- data/test/unit/parameter_matchers/equals_test.rb +0 -25
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -96
- data/test/unit/parameter_matchers/has_key_test.rb +0 -55
- data/test/unit/parameter_matchers/has_value_test.rb +0 -57
- data/test/unit/parameter_matchers/includes_test.rb +0 -44
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
- data/test/unit/parameter_matchers/is_a_test.rb +0 -25
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
- data/test/unit/parameter_matchers/not_test.rb +0 -26
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -46
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -25
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
- data/test/unit/parameters_matcher_test.rb +0 -121
- data/test/unit/return_values_test.rb +0 -63
- data/test/unit/sequence_test.rb +0 -104
- data/test/unit/single_return_value_test.rb +0 -14
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/state_machine_test.rb +0 -98
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/thrower_test.rb +0 -20
- data/test/unit/yield_parameters_test.rb +0 -93
@@ -1,63 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/return_values'
|
4
|
-
|
5
|
-
class ReturnValuesTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
def test_should_return_nil
|
10
|
-
values = ReturnValues.new
|
11
|
-
assert_nil values.next
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_keep_returning_nil
|
15
|
-
values = ReturnValues.new
|
16
|
-
values.next
|
17
|
-
assert_nil values.next
|
18
|
-
assert_nil values.next
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_return_evaluated_single_return_value
|
22
|
-
values = ReturnValues.new(SingleReturnValue.new('value'))
|
23
|
-
assert_equal 'value', values.next
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_keep_returning_evaluated_single_return_value
|
27
|
-
values = ReturnValues.new(SingleReturnValue.new('value'))
|
28
|
-
values.next
|
29
|
-
assert_equal 'value', values.next
|
30
|
-
assert_equal 'value', values.next
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_return_consecutive_evaluated_single_return_values
|
34
|
-
values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2'))
|
35
|
-
assert_equal 'value_1', values.next
|
36
|
-
assert_equal 'value_2', values.next
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_keep_returning_last_of_consecutive_evaluated_single_return_values
|
40
|
-
values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2'))
|
41
|
-
values.next
|
42
|
-
values.next
|
43
|
-
assert_equal 'value_2', values.next
|
44
|
-
assert_equal 'value_2', values.next
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_build_single_return_values_for_each_values
|
48
|
-
values = ReturnValues.build('value_1', 'value_2', 'value_3').values
|
49
|
-
assert_equal 'value_1', values[0].evaluate
|
50
|
-
assert_equal 'value_2', values[1].evaluate
|
51
|
-
assert_equal 'value_3', values[2].evaluate
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_combine_two_sets_of_return_values
|
55
|
-
values_1 = ReturnValues.build('value_1')
|
56
|
-
values_2 = ReturnValues.build('value_2a', 'value_2b')
|
57
|
-
values = (values_1 + values_2).values
|
58
|
-
assert_equal 'value_1', values[0].evaluate
|
59
|
-
assert_equal 'value_2a', values[1].evaluate
|
60
|
-
assert_equal 'value_2b', values[2].evaluate
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
data/test/unit/sequence_test.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/sequence'
|
3
|
-
require 'mocha/expectation'
|
4
|
-
|
5
|
-
class SequenceTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
class FakeExpectation
|
10
|
-
|
11
|
-
attr_reader :ordering_constraints
|
12
|
-
|
13
|
-
def initialize(satisfied = false)
|
14
|
-
@satisfied = satisfied
|
15
|
-
@ordering_constraints = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_ordering_constraint(ordering_constraint)
|
19
|
-
@ordering_constraints << ordering_constraint
|
20
|
-
end
|
21
|
-
|
22
|
-
def satisfied?
|
23
|
-
@satisfied
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_be_satisfied_if_no_expectations_added
|
29
|
-
sequence = Sequence.new('name')
|
30
|
-
assert sequence.satisfied_to_index?(0)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index
|
34
|
-
sequence = Sequence.new('name')
|
35
|
-
expectation = FakeExpectation.new(false)
|
36
|
-
sequence.constrain_as_next_in_sequence(expectation)
|
37
|
-
assert sequence.satisfied_to_index?(0)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index
|
41
|
-
sequence = Sequence.new('name')
|
42
|
-
expectation = FakeExpectation.new(false)
|
43
|
-
sequence.constrain_as_next_in_sequence(expectation)
|
44
|
-
assert !sequence.satisfied_to_index?(1)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index
|
48
|
-
sequence = Sequence.new('name')
|
49
|
-
expectation = FakeExpectation.new(true)
|
50
|
-
sequence.constrain_as_next_in_sequence(expectation)
|
51
|
-
assert sequence.satisfied_to_index?(1)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index
|
55
|
-
sequence = Sequence.new('name')
|
56
|
-
expectation_one = FakeExpectation.new(true)
|
57
|
-
expectation_two = FakeExpectation.new(false)
|
58
|
-
sequence.constrain_as_next_in_sequence(expectation_one)
|
59
|
-
sequence.constrain_as_next_in_sequence(expectation_two)
|
60
|
-
assert !sequence.satisfied_to_index?(2)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index
|
64
|
-
sequence = Sequence.new('name')
|
65
|
-
expectation_one = FakeExpectation.new(true)
|
66
|
-
expectation_two = FakeExpectation.new(true)
|
67
|
-
sequence.constrain_as_next_in_sequence(expectation_one)
|
68
|
-
sequence.constrain_as_next_in_sequence(expectation_two)
|
69
|
-
assert sequence.satisfied_to_index?(2)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_should_add_ordering_constraint_to_expectation
|
73
|
-
sequence = Sequence.new('name')
|
74
|
-
expectation = FakeExpectation.new
|
75
|
-
sequence.constrain_as_next_in_sequence(expectation)
|
76
|
-
assert_equal 1, expectation.ordering_constraints.length
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked
|
80
|
-
sequence = Sequence.new('name')
|
81
|
-
expectation_one = FakeExpectation.new(false)
|
82
|
-
expectation_two = FakeExpectation.new(false)
|
83
|
-
sequence.constrain_as_next_in_sequence(expectation_one)
|
84
|
-
sequence.constrain_as_next_in_sequence(expectation_two)
|
85
|
-
assert !expectation_two.ordering_constraints[0].allows_invocation_now?
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked
|
89
|
-
sequence = Sequence.new('name')
|
90
|
-
expectation_one = FakeExpectation.new(true)
|
91
|
-
expectation_two = FakeExpectation.new(false)
|
92
|
-
sequence.constrain_as_next_in_sequence(expectation_one)
|
93
|
-
sequence.constrain_as_next_in_sequence(expectation_two)
|
94
|
-
assert expectation_two.ordering_constraints[0].allows_invocation_now?
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_should_describe_ordering_constraint_as_being_part_of_named_sequence
|
98
|
-
sequence = Sequence.new('wibble')
|
99
|
-
expectation = FakeExpectation.new
|
100
|
-
sequence.constrain_as_next_in_sequence(expectation)
|
101
|
-
assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/single_return_value'
|
4
|
-
|
5
|
-
class SingleReturnValueTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
def test_should_return_value
|
10
|
-
value = SingleReturnValue.new('value')
|
11
|
-
assert_equal 'value', value.evaluate
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/single_yield'
|
4
|
-
|
5
|
-
class SingleYieldTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
def test_should_provide_parameters_for_single_yield_in_single_invocation
|
10
|
-
parameter_group = SingleYield.new(1, 2, 3)
|
11
|
-
parameter_groups = []
|
12
|
-
parameter_group.each do |parameters|
|
13
|
-
parameter_groups << parameters
|
14
|
-
end
|
15
|
-
assert_equal [[1, 2, 3]], parameter_groups
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/state_machine'
|
4
|
-
|
5
|
-
class StateMachineTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
def test_should_initially_be_in_no_state
|
10
|
-
state_machine = StateMachine.new('name')
|
11
|
-
any_state.each do |state|
|
12
|
-
assert !state_machine.is(state).active?
|
13
|
-
assert state_machine.is_not(state).active?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_be_able_to_enter_a_state
|
18
|
-
state_machine = StateMachine.new('name')
|
19
|
-
state = 'A'
|
20
|
-
other_states = any_state.reject { |s| s == state }
|
21
|
-
|
22
|
-
state_machine.is(state).activate
|
23
|
-
|
24
|
-
assert state_machine.is(state).active?
|
25
|
-
assert !state_machine.is_not(state).active?
|
26
|
-
other_states.each do |s|
|
27
|
-
assert !state_machine.is(s).active?
|
28
|
-
assert state_machine.is_not(s).active?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_be_able_to_change_state
|
33
|
-
state_machine = StateMachine.new('name')
|
34
|
-
state = 'B'
|
35
|
-
other_states = any_state.reject { |s| s == state }
|
36
|
-
|
37
|
-
state_machine.is('A').activate
|
38
|
-
state_machine.is(state).activate
|
39
|
-
|
40
|
-
assert state_machine.is(state).active?
|
41
|
-
assert !state_machine.is_not(state).active?
|
42
|
-
other_states.each do |s|
|
43
|
-
assert !state_machine.is(s).active?
|
44
|
-
assert state_machine.is_not(s).active?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_be_put_into_an_initial_state
|
49
|
-
state_machine = StateMachine.new('name')
|
50
|
-
initial_state = 'A'
|
51
|
-
other_states = any_state.reject { |s| s == initial_state }
|
52
|
-
|
53
|
-
state_machine.starts_as(initial_state)
|
54
|
-
|
55
|
-
assert state_machine.is(initial_state).active?
|
56
|
-
assert !state_machine.is_not(initial_state).active?
|
57
|
-
other_states.each do |state|
|
58
|
-
assert !state_machine.is(state).active?
|
59
|
-
assert state_machine.is_not(state).active?
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_be_put_into_a_new_state
|
64
|
-
next_state = 'B'
|
65
|
-
|
66
|
-
other_states = any_state.reject { |s| s == next_state }
|
67
|
-
state_machine = StateMachine.new('name').starts_as('A')
|
68
|
-
|
69
|
-
state_machine.become(next_state)
|
70
|
-
|
71
|
-
assert state_machine.is(next_state).active?
|
72
|
-
assert !state_machine.is_not(next_state).active?
|
73
|
-
other_states.each do |state|
|
74
|
-
assert !state_machine.is(state).active?
|
75
|
-
assert state_machine.is_not(state).active?
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_should_describe_itself_as_name_and_current_state
|
80
|
-
state_machine = StateMachine.new('state_machine_name')
|
81
|
-
assert_equal 'state_machine_name has no current state', state_machine.mocha_inspect
|
82
|
-
inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new
|
83
|
-
state_machine.is(inspectable_state).activate
|
84
|
-
assert_equal "state_machine_name is 'inspectable_state'", state_machine.mocha_inspect
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_have_self_describing_states
|
88
|
-
state_machine = StateMachine.new('state_machine_name')
|
89
|
-
inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new
|
90
|
-
assert_equal "state_machine_name is 'inspectable_state'", state_machine.is(inspectable_state).mocha_inspect
|
91
|
-
assert_equal "state_machine_name is not 'inspectable_state'", state_machine.is_not(inspectable_state).mocha_inspect
|
92
|
-
end
|
93
|
-
|
94
|
-
def any_state
|
95
|
-
%w(A B C D)
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/inspect'
|
3
|
-
|
4
|
-
class StringInspectTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_should_replace_escaped_quotes_with_single_quote
|
7
|
-
string = "my_string"
|
8
|
-
assert_equal "'my_string'", string.mocha_inspect
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
data/test/unit/thrower_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/thrower'
|
4
|
-
|
5
|
-
class ThrowerTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
def test_should_throw_tag
|
10
|
-
thrower = Thrower.new(:tag)
|
11
|
-
assert_throws(:tag) { thrower.evaluate }
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_throw_tag_with_return_value
|
15
|
-
thrower = Thrower.new(:tag, 'return-value')
|
16
|
-
return_value = catch(:tag) { thrower.evaluate }
|
17
|
-
assert_equal 'return-value', return_value
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/yield_parameters'
|
4
|
-
require 'mocha/no_yields'
|
5
|
-
require 'mocha/single_yield'
|
6
|
-
require 'mocha/multiple_yields'
|
7
|
-
|
8
|
-
class YieldParametersTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
include Mocha
|
11
|
-
|
12
|
-
def test_should_return_null_yield_parameter_group_by_default
|
13
|
-
yield_parameters = YieldParameters.new
|
14
|
-
assert yield_parameters.next_invocation.is_a?(NoYields)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_return_single_yield_parameter_group
|
18
|
-
yield_parameters = YieldParameters.new
|
19
|
-
yield_parameters.add(1, 2, 3)
|
20
|
-
parameter_group = yield_parameters.next_invocation
|
21
|
-
assert parameter_group.is_a?(SingleYield)
|
22
|
-
assert_equal [1, 2, 3], parameter_group.parameters
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_keep_returning_single_yield_parameter_group
|
26
|
-
yield_parameters = YieldParameters.new
|
27
|
-
yield_parameters.add(1, 2, 3)
|
28
|
-
yield_parameters.next_invocation
|
29
|
-
parameter_group = yield_parameters.next_invocation
|
30
|
-
assert parameter_group.is_a?(SingleYield)
|
31
|
-
assert_equal [1, 2, 3], parameter_group.parameters
|
32
|
-
parameter_group = yield_parameters.next_invocation
|
33
|
-
assert parameter_group.is_a?(SingleYield)
|
34
|
-
assert_equal [1, 2, 3], parameter_group.parameters
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_should_return_consecutive_single_yield_parameter_groups
|
38
|
-
yield_parameters = YieldParameters.new
|
39
|
-
yield_parameters.add(1, 2, 3)
|
40
|
-
yield_parameters.add(4, 5)
|
41
|
-
parameter_group = yield_parameters.next_invocation
|
42
|
-
assert parameter_group.is_a?(SingleYield)
|
43
|
-
assert_equal [1, 2, 3], parameter_group.parameters
|
44
|
-
parameter_group = yield_parameters.next_invocation
|
45
|
-
assert parameter_group.is_a?(SingleYield)
|
46
|
-
assert_equal [4, 5], parameter_group.parameters
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_return_multiple_yield_parameter_group
|
50
|
-
yield_parameters = YieldParameters.new
|
51
|
-
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
52
|
-
parameter_group = yield_parameters.next_invocation
|
53
|
-
assert parameter_group.is_a?(MultipleYields)
|
54
|
-
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_keep_returning_multiple_yield_parameter_group
|
58
|
-
yield_parameters = YieldParameters.new
|
59
|
-
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
60
|
-
yield_parameters.next_invocation
|
61
|
-
parameter_group = yield_parameters.next_invocation
|
62
|
-
assert parameter_group.is_a?(MultipleYields)
|
63
|
-
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
64
|
-
parameter_group = yield_parameters.next_invocation
|
65
|
-
assert parameter_group.is_a?(MultipleYields)
|
66
|
-
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_should_return_consecutive_multiple_yield_parameter_groups
|
70
|
-
yield_parameters = YieldParameters.new
|
71
|
-
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
72
|
-
yield_parameters.multiple_add([6, 7], [8, 9, 0])
|
73
|
-
parameter_group = yield_parameters.next_invocation
|
74
|
-
assert parameter_group.is_a?(MultipleYields)
|
75
|
-
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
76
|
-
parameter_group = yield_parameters.next_invocation
|
77
|
-
assert parameter_group.is_a?(MultipleYields)
|
78
|
-
assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_should_return_consecutive_single_and_multiple_yield_parameter_groups
|
82
|
-
yield_parameters = YieldParameters.new
|
83
|
-
yield_parameters.add(1, 2, 3)
|
84
|
-
yield_parameters.multiple_add([4, 5, 6], [7, 8])
|
85
|
-
parameter_group = yield_parameters.next_invocation
|
86
|
-
assert parameter_group.is_a?(SingleYield)
|
87
|
-
assert_equal [1, 2, 3], parameter_group.parameters
|
88
|
-
parameter_group = yield_parameters.next_invocation
|
89
|
-
assert parameter_group.is_a?(MultipleYields)
|
90
|
-
assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|