mocha 1.2.1 → 2.0.0
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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +65 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +4 -9
- data/Gemfile +29 -0
- data/README.md +110 -106
- data/RELEASE.md +306 -1
- data/Rakefile +52 -45
- data/gemfiles/Gemfile.minitest.latest +1 -0
- data/gemfiles/Gemfile.test-unit.latest +2 -5
- data/lib/mocha/any_instance_method.rb +9 -62
- data/lib/mocha/api.rb +84 -68
- data/lib/mocha/argument_iterator.rb +4 -8
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +60 -49
- data/lib/mocha/central.rb +21 -12
- data/lib/mocha/change_state_side_effect.rb +0 -4
- data/lib/mocha/class_methods.rb +19 -21
- data/lib/mocha/configuration.rb +312 -47
- data/lib/mocha/debug.rb +3 -2
- data/lib/mocha/deprecation.rb +8 -11
- data/lib/mocha/detection/mini_test.rb +0 -2
- data/lib/mocha/detection/test_unit.rb +3 -5
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +4 -6
- data/lib/mocha/expectation.rb +186 -95
- data/lib/mocha/expectation_error.rb +1 -1
- data/lib/mocha/expectation_error_factory.rb +0 -1
- data/lib/mocha/expectation_list.rb +7 -11
- data/lib/mocha/hooks.rb +1 -3
- data/lib/mocha/in_state_ordering_constraint.rb +0 -4
- data/lib/mocha/inspect.rb +30 -38
- data/lib/mocha/instance_method.rb +11 -8
- data/lib/mocha/integration/mini_test/adapter.rb +2 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
- data/lib/mocha/integration/mini_test.rb +10 -31
- data/lib/mocha/integration/monkey_patcher.rb +5 -7
- data/lib/mocha/integration/test_unit/adapter.rb +5 -6
- data/lib/mocha/integration/test_unit.rb +10 -26
- data/lib/mocha/invocation.rb +73 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +0 -4
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +1 -5
- data/lib/mocha/minitest.rb +6 -0
- data/lib/mocha/mock.rb +99 -51
- data/lib/mocha/mockery.rb +70 -99
- data/lib/mocha/names.rb +2 -12
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +25 -31
- data/lib/mocha/parameter_matchers/all_of.rb +2 -8
- data/lib/mocha/parameter_matchers/any_of.rb +2 -8
- data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
- data/lib/mocha/parameter_matchers/anything.rb +2 -8
- data/lib/mocha/parameter_matchers/base.rb +7 -13
- data/lib/mocha/parameter_matchers/equals.rb +0 -6
- data/lib/mocha/parameter_matchers/{query_string.rb → equivalent_uri.rb} +14 -15
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -7
- data/lib/mocha/parameter_matchers/has_entry.rb +26 -21
- data/lib/mocha/parameter_matchers/has_key.rb +2 -7
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -7
- data/lib/mocha/parameter_matchers/includes.rb +6 -7
- data/lib/mocha/parameter_matchers/instance_methods.rb +27 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
- data/lib/mocha/parameter_matchers/is_a.rb +2 -7
- data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
- data/lib/mocha/parameter_matchers/not.rb +2 -7
- data/lib/mocha/parameter_matchers/optionally.rb +4 -10
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +64 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
- data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
- data/lib/mocha/parameter_matchers.rb +3 -4
- data/lib/mocha/parameters_matcher.rb +8 -11
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +10 -14
- data/lib/mocha/return_values.rb +4 -8
- data/lib/mocha/ruby_version.rb +1 -2
- data/lib/mocha/sequence.rb +4 -9
- data/lib/mocha/single_return_value.rb +2 -5
- data/lib/mocha/state_machine.rb +33 -46
- data/lib/mocha/stubbed_method.rb +88 -0
- data/lib/mocha/stubbing_error.rb +2 -13
- data/lib/mocha/test_unit.rb +5 -2
- data/lib/mocha/thrower.rb +4 -6
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +7 -17
- data/mocha.gemspec +14 -65
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +26 -266
- data/bin/build-matrix +0 -70
- 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.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/init.rb +0 -3
- data/lib/mocha/class_method.rb +0 -119
- data/lib/mocha/integration/mini_test/nothing.rb +0 -19
- data/lib/mocha/integration/mini_test/version_13.rb +0 -51
- data/lib/mocha/integration/mini_test/version_140.rb +0 -51
- data/lib/mocha/integration/mini_test/version_141.rb +0 -62
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +0 -62
- data/lib/mocha/integration/mini_test/version_200.rb +0 -63
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +0 -63
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +0 -67
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +0 -70
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +0 -65
- data/lib/mocha/integration/test_unit/gem_version_200.rb +0 -59
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +0 -59
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +0 -59
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +0 -65
- data/lib/mocha/integration/test_unit/nothing.rb +0 -19
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -58
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +0 -60
- data/lib/mocha/integration.rb +0 -14
- data/lib/mocha/mini_test.rb +0 -3
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/module_methods.rb +0 -14
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/parameter_matchers/object.rb +0 -17
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/setup.rb +0 -9
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -26
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- 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_272_test.rb +0 -52
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- 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 -337
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/prepend_test.rb +0 -89
- 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_defined_on_superclass_test.rb +0 -34
- data/test/acceptance/stub_any_instance_method_test.rb +0 -280
- 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 -78
- 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 -112
- 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 -69
- 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 -78
- 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_method_defined_on_module_and_aliased_test.rb +0 -39
- 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_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -48
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_nil_test.rb +0 -61
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -143
- 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/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -35
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unexpected_invocation_test.rb +0 -25
- data/test/acceptance/unstubbing_test.rb +0 -168
- data/test/assertions.rb +0 -8
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -174
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -90
- data/test/minitest_result.rb +0 -49
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -50
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -20
- data/test/unit/any_instance_method_test.rb +0 -134
- 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 -225
- data/test/unit/class_methods_test.rb +0 -40
- 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 -82
- data/test/unit/expectation_test.rb +0 -497
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/hooks_test.rb +0 -29
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -28
- data/test/unit/mock_test.rb +0 -342
- data/test/unit/mockery_test.rb +0 -151
- data/test/unit/module_methods_test.rb +0 -19
- 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 -39
- data/test/unit/object_methods_test.rb +0 -46
- 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 -129
- 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 -102
- 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 -32
- 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/receivers_test.rb +0 -66
- 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,225 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'method_definer'
|
3
|
-
require 'mocha/mock'
|
4
|
-
|
5
|
-
require 'mocha/class_method'
|
6
|
-
|
7
|
-
class ClassMethodTest < Mocha::TestCase
|
8
|
-
|
9
|
-
include Mocha
|
10
|
-
|
11
|
-
unless RUBY_V2_PLUS
|
12
|
-
def test_should_hide_original_method
|
13
|
-
klass = Class.new { def self.method_x; end }
|
14
|
-
method = ClassMethod.new(klass, :method_x)
|
15
|
-
|
16
|
-
method.hide_original_method
|
17
|
-
|
18
|
-
assert_equal false, klass.respond_to?(:method_x)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_should_not_raise_error_hiding_method_that_isnt_defined
|
23
|
-
klass = Class.new
|
24
|
-
method = ClassMethod.new(klass, :method_x)
|
25
|
-
|
26
|
-
assert_nothing_raised { method.hide_original_method }
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_not_raise_error_hiding_method_in_class_that_implements_method_called_method
|
30
|
-
klass = Class.new { def self.method; end }
|
31
|
-
method = ClassMethod.new(klass, :method)
|
32
|
-
|
33
|
-
assert_nothing_raised { method.hide_original_method }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_define_a_new_method_which_should_call_mocha_method_missing
|
37
|
-
klass = Class.new { def self.method_x; end }
|
38
|
-
mocha = build_mock
|
39
|
-
klass.define_instance_method(:mocha) { mocha }
|
40
|
-
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
41
|
-
method = ClassMethod.new(klass, :method_x)
|
42
|
-
|
43
|
-
method.hide_original_method
|
44
|
-
method.define_new_method
|
45
|
-
result = klass.method_x(:param1, :param2)
|
46
|
-
|
47
|
-
assert_equal :result, result
|
48
|
-
assert mocha.__verified__?
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_remove_new_method
|
52
|
-
klass = Class.new { def self.method_x; end }
|
53
|
-
method = ClassMethod.new(klass, :method_x)
|
54
|
-
|
55
|
-
method.remove_new_method
|
56
|
-
|
57
|
-
assert_equal false, klass.respond_to?(:method_x)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_restore_original_method
|
61
|
-
klass = Class.new { def self.method_x; :original_result; end }
|
62
|
-
method = ClassMethod.new(klass, :method_x)
|
63
|
-
|
64
|
-
method.hide_original_method
|
65
|
-
method.define_new_method
|
66
|
-
method.remove_new_method
|
67
|
-
method.restore_original_method
|
68
|
-
|
69
|
-
assert klass.respond_to?(:method_x)
|
70
|
-
assert_equal :original_result, klass.method_x
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_should_restore_original_method_accepting_a_block_parameter
|
74
|
-
klass = Class.new { def self.method_x(&block); block.call if block_given? ; end }
|
75
|
-
method = ClassMethod.new(klass, :method_x)
|
76
|
-
|
77
|
-
method.hide_original_method
|
78
|
-
method.define_new_method
|
79
|
-
method.remove_new_method
|
80
|
-
method.restore_original_method
|
81
|
-
|
82
|
-
block_called = false
|
83
|
-
klass.method_x { block_called = true }
|
84
|
-
assert block_called
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_not_restore_original_method_if_none_was_defined_in_first_place
|
88
|
-
klass = Class.new { def self.method_x; :new_result; end }
|
89
|
-
method = ClassMethod.new(klass, :method_x)
|
90
|
-
|
91
|
-
method.restore_original_method
|
92
|
-
|
93
|
-
assert_equal :new_result, klass.method_x
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_should_call_hide_original_method
|
97
|
-
klass = Class.new { def self.method_x; end }
|
98
|
-
method = ClassMethod.new(klass, :method_x)
|
99
|
-
method.hide_original_method
|
100
|
-
method.define_instance_accessor(:hide_called)
|
101
|
-
method.replace_instance_method(:hide_original_method) { self.hide_called = true }
|
102
|
-
|
103
|
-
method.stub
|
104
|
-
|
105
|
-
assert method.hide_called
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_should_call_define_new_method
|
109
|
-
klass = Class.new { def self.method_x; end }
|
110
|
-
method = ClassMethod.new(klass, :method_x)
|
111
|
-
method.define_instance_accessor(:define_called)
|
112
|
-
method.replace_instance_method(:define_new_method) { self.define_called = true }
|
113
|
-
|
114
|
-
method.stub
|
115
|
-
|
116
|
-
assert method.define_called
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_should_call_remove_new_method
|
120
|
-
klass = Class.new { def self.method_x; end }
|
121
|
-
method = ClassMethod.new(klass, :method_x)
|
122
|
-
mocha = build_mock
|
123
|
-
klass.define_instance_method(:mocha) { mocha }
|
124
|
-
method.define_instance_accessor(:remove_called)
|
125
|
-
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
126
|
-
|
127
|
-
method.unstub
|
128
|
-
|
129
|
-
assert method.remove_called
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_should_call_restore_original_method
|
133
|
-
klass = Class.new { def self.method_x; end }
|
134
|
-
mocha = build_mock
|
135
|
-
klass.define_instance_method(:mocha) { mocha }
|
136
|
-
method = ClassMethod.new(klass, :method_x)
|
137
|
-
method.define_instance_accessor(:restore_called)
|
138
|
-
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
139
|
-
|
140
|
-
method.unstub
|
141
|
-
|
142
|
-
assert method.restore_called
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_should_call_mocha_unstub
|
146
|
-
klass = Class.new { def self.method_x; end }
|
147
|
-
method = ClassMethod.new(klass, :method_x)
|
148
|
-
method.replace_instance_method(:restore_original_method) { }
|
149
|
-
mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
|
150
|
-
mocha.define_instance_method(:any_expectations?) { true }
|
151
|
-
method.replace_instance_method(:mock) { mocha }
|
152
|
-
|
153
|
-
method.unstub
|
154
|
-
assert_equal mocha.unstub_method, :method_x
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_should_call_stubbee_reset_mocha_if_no_expectations_remaining
|
158
|
-
klass = Class.new { def self.method_x; end }
|
159
|
-
method = ClassMethod.new(klass, :method_x)
|
160
|
-
method.replace_instance_method(:remove_new_method) { }
|
161
|
-
method.replace_instance_method(:restore_original_method) { }
|
162
|
-
mocha = Class.new
|
163
|
-
mocha.define_instance_method(:unstub) { |method_name| }
|
164
|
-
mocha.define_instance_method(:any_expectations?) { false }
|
165
|
-
method.replace_instance_method(:mock) { mocha }
|
166
|
-
stubbee = Class.new { attr_accessor :reset_mocha_called; def reset_mocha; self.reset_mocha_called = true; end; }.new
|
167
|
-
method.replace_instance_method(:stubbee) { stubbee }
|
168
|
-
|
169
|
-
method.unstub
|
170
|
-
|
171
|
-
assert stubbee.reset_mocha_called
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_should_return_mock_for_stubbee
|
175
|
-
mocha = Object.new
|
176
|
-
stubbee = Object.new
|
177
|
-
stubbee.define_instance_accessor(:mocha) { mocha }
|
178
|
-
stubbee.mocha = nil
|
179
|
-
method = ClassMethod.new(stubbee, :method_name)
|
180
|
-
assert_equal stubbee.mocha, method.mock
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_should_not_match_if_other_object_has_a_different_class
|
184
|
-
class_method = ClassMethod.new(Object.new, :method)
|
185
|
-
other_object = Object.new
|
186
|
-
assert !class_method.matches?(other_object)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_should_not_match_if_other_class_method_has_different_stubbee
|
190
|
-
stubbee_1 = Object.new
|
191
|
-
stubbee_2 = Object.new
|
192
|
-
class_method_1 = ClassMethod.new(stubbee_1, :method)
|
193
|
-
class_method_2 = ClassMethod.new(stubbee_2, :method)
|
194
|
-
assert !class_method_1.matches?(class_method_2)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_should_not_match_if_other_class_method_has_different_method
|
198
|
-
stubbee = Object.new
|
199
|
-
class_method_1 = ClassMethod.new(stubbee, :method_1)
|
200
|
-
class_method_2 = ClassMethod.new(stubbee, :method_2)
|
201
|
-
assert !class_method_1.matches?(class_method_2)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice
|
205
|
-
stubbee = Object.new
|
206
|
-
class_method_1 = ClassMethod.new(stubbee, :method)
|
207
|
-
class_method_2 = ClassMethod.new(stubbee, :method)
|
208
|
-
assert class_method_1.matches?(class_method_2)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy
|
212
|
-
stubbee = Class.new do
|
213
|
-
def equal?(other); false; end
|
214
|
-
end.new
|
215
|
-
class_method_1 = ClassMethod.new(stubbee, :method)
|
216
|
-
class_method_2 = ClassMethod.new(stubbee, :method)
|
217
|
-
assert class_method_1.matches?(class_method_2)
|
218
|
-
end
|
219
|
-
|
220
|
-
private
|
221
|
-
|
222
|
-
def build_mock
|
223
|
-
Mock.new(nil)
|
224
|
-
end
|
225
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/class_methods'
|
3
|
-
require 'mocha/object_methods'
|
4
|
-
|
5
|
-
class ClassMethodsTest < Mocha::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_build_any_instance_object
|
12
|
-
any_instance = @klass.any_instance
|
13
|
-
assert_not_nil any_instance
|
14
|
-
assert any_instance.is_a?(Mocha::ClassMethods::AnyInstance)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_return_same_any_instance_object
|
18
|
-
any_instance_1 = @klass.any_instance
|
19
|
-
any_instance_2 = @klass.any_instance
|
20
|
-
assert_equal any_instance_1, any_instance_2
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_use_stubba_class_method_for_class
|
24
|
-
assert_equal Mocha::ClassMethod, @klass.stubba_method
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_use_stubba_class_method_for_any_instance
|
28
|
-
assert_equal Mocha::AnyInstanceMethod, @klass.any_instance.stubba_method
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_stub_self_for_class
|
32
|
-
assert_equal @klass, @klass.stubba_object
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_stub_relevant_class_for_any_instance
|
36
|
-
any_instance = @klass.any_instance
|
37
|
-
assert_equal @klass, any_instance.stubba_object
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require "mocha/configuration"
|
3
|
-
|
4
|
-
class ConfigurationTest < Mocha::TestCase
|
5
|
-
def test_allow_temporarily_changes_config_when_given_block
|
6
|
-
Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
|
7
|
-
yielded = false
|
8
|
-
Mocha::Configuration.allow(:stubbing_method_unnecessarily) do
|
9
|
-
yielded = true
|
10
|
-
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
11
|
-
end
|
12
|
-
assert yielded
|
13
|
-
assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_prevent_temporarily_changes_config_when_given_block
|
17
|
-
Mocha::Configuration.allow(:stubbing_method_unnecessarily)
|
18
|
-
yielded = false
|
19
|
-
Mocha::Configuration.prevent(:stubbing_method_unnecessarily) do
|
20
|
-
yielded = true
|
21
|
-
assert Mocha::Configuration.prevent?(:stubbing_method_unnecessarily)
|
22
|
-
end
|
23
|
-
assert yielded
|
24
|
-
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_warn_when_temporarily_changes_config_when_given_block
|
28
|
-
Mocha::Configuration.allow(:stubbing_method_unnecessarily)
|
29
|
-
yielded = false
|
30
|
-
Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) do
|
31
|
-
yielded = true
|
32
|
-
assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
|
33
|
-
end
|
34
|
-
assert yielded
|
35
|
-
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/inspect'
|
3
|
-
|
4
|
-
class DateTimeInspectTest < Mocha::TestCase
|
5
|
-
|
6
|
-
def test_should_use_include_date_in_seconds
|
7
|
-
time = Time.now
|
8
|
-
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_use_to_s_for_date
|
12
|
-
date = Date.new(2006, 1, 1)
|
13
|
-
assert_equal date.to_s, date.mocha_inspect
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_use_to_s_for_datetime
|
17
|
-
datetime = DateTime.new(2006, 1, 1)
|
18
|
-
assert_equal datetime.to_s, datetime.mocha_inspect
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/exception_raiser'
|
4
|
-
require 'timeout'
|
5
|
-
|
6
|
-
class ExceptionRaiserTest < Mocha::TestCase
|
7
|
-
|
8
|
-
include Mocha
|
9
|
-
|
10
|
-
def test_should_raise_exception_with_specified_class_and_default_message
|
11
|
-
exception_class = Class.new(StandardError)
|
12
|
-
raiser = ExceptionRaiser.new(exception_class, nil)
|
13
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
14
|
-
assert_equal exception_class.to_s, exception.message
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_raise_exception_with_specified_class_and_message
|
18
|
-
exception_class = Class.new(StandardError)
|
19
|
-
raiser = ExceptionRaiser.new(exception_class, 'message')
|
20
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
21
|
-
assert_equal 'message', exception.message
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_raise_exception_instance
|
25
|
-
exception_class = Class.new(StandardError)
|
26
|
-
raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
|
27
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
28
|
-
assert_equal 'message', exception.message
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
32
|
-
raiser = ExceptionRaiser.new(Interrupt, nil)
|
33
|
-
assert_raises(Interrupt) { raiser.evaluate }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
37
|
-
exception_class = Class.new(Interrupt)
|
38
|
-
raiser = ExceptionRaiser.new(exception_class, nil)
|
39
|
-
assert_raises(exception_class) { raiser.evaluate }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/expectation_list'
|
3
|
-
require 'mocha/expectation'
|
4
|
-
require 'set'
|
5
|
-
require 'method_definer'
|
6
|
-
|
7
|
-
class ExpectationListTest < Mocha::TestCase
|
8
|
-
|
9
|
-
include Mocha
|
10
|
-
|
11
|
-
def test_should_return_added_expectation
|
12
|
-
expectation_list = ExpectationList.new
|
13
|
-
expectation = Expectation.new(nil, :my_method)
|
14
|
-
assert_same expectation, expectation_list.add(expectation)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_find_matching_expectation
|
18
|
-
expectation_list = ExpectationList.new
|
19
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
20
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
21
|
-
expectation_list.add(expectation1)
|
22
|
-
expectation_list.add(expectation2)
|
23
|
-
assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_remove_all_expectations_matching_method_name
|
27
|
-
expectation_list = ExpectationList.new
|
28
|
-
expectation1 = Expectation.new(nil, :method_one).with(:argument1, :argument2)
|
29
|
-
expectation2 = Expectation.new(nil, :method_one).with(:argument3, :argument4)
|
30
|
-
expectation3 = Expectation.new(nil, :method_two)
|
31
|
-
expectation_list.add(expectation1)
|
32
|
-
expectation_list.add(expectation2)
|
33
|
-
expectation_list.add(expectation3)
|
34
|
-
expectation_list.remove_all_matching_method(:method_one)
|
35
|
-
assert_nil expectation_list.match(:method_one, :argument1, :argument2)
|
36
|
-
assert_nil expectation_list.match(:method_one, :argument3, :argument4)
|
37
|
-
assert_same expectation3, expectation_list.match(:method_two)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_find_most_recent_matching_expectation
|
41
|
-
expectation_list = ExpectationList.new
|
42
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
43
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
44
|
-
expectation_list.add(expectation1)
|
45
|
-
expectation_list.add(expectation2)
|
46
|
-
assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_find_matching_expectation_allowing_invocation
|
50
|
-
expectation_list = ExpectationList.new
|
51
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
52
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
53
|
-
expectation1.define_instance_method(:invocations_allowed?) { true }
|
54
|
-
expectation2.define_instance_method(:invocations_allowed?) { true }
|
55
|
-
expectation_list.add(expectation1)
|
56
|
-
expectation_list.add(expectation2)
|
57
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_find_most_recent_matching_expectation_allowing_invocation
|
61
|
-
expectation_list = ExpectationList.new
|
62
|
-
expectation1 = Expectation.new(nil, :my_method)
|
63
|
-
expectation2 = Expectation.new(nil, :my_method)
|
64
|
-
expectation1.define_instance_method(:invocations_allowed?) { true }
|
65
|
-
expectation2.define_instance_method(:invocations_allowed?) { false }
|
66
|
-
expectation_list.add(expectation1)
|
67
|
-
expectation_list.add(expectation2)
|
68
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_should_combine_two_expectation_lists_into_one
|
72
|
-
expectation_list1 = ExpectationList.new
|
73
|
-
expectation_list2 = ExpectationList.new
|
74
|
-
expectation1 = Expectation.new(nil, :my_method)
|
75
|
-
expectation2 = Expectation.new(nil, :my_method)
|
76
|
-
expectation_list1.add(expectation1)
|
77
|
-
expectation_list2.add(expectation2)
|
78
|
-
expectation_list = expectation_list1 + expectation_list2
|
79
|
-
assert_equal [expectation1, expectation2], expectation_list.to_a
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|