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,78 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnModuleTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_public_method_and_leave_it_unchanged_after_test
|
17
|
-
mod = Module.new do
|
18
|
-
def my_module_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
public :my_module_method
|
22
|
-
end
|
23
|
-
instance = Class.new do
|
24
|
-
include mod
|
25
|
-
end.new
|
26
|
-
assert_snapshot_unchanged(instance) do
|
27
|
-
test_result = run_as_test do
|
28
|
-
instance.stubs(:my_module_method).returns(:new_return_value)
|
29
|
-
assert_method_visibility instance, :my_module_method, :public
|
30
|
-
assert_equal :new_return_value, instance.my_module_method
|
31
|
-
end
|
32
|
-
assert_passed(test_result)
|
33
|
-
end
|
34
|
-
assert_equal :original_return_value, instance.my_module_method
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
38
|
-
mod = Module.new do
|
39
|
-
def my_module_method
|
40
|
-
:original_return_value
|
41
|
-
end
|
42
|
-
protected :my_module_method
|
43
|
-
end
|
44
|
-
instance = Class.new do
|
45
|
-
include mod
|
46
|
-
end.new
|
47
|
-
assert_snapshot_unchanged(instance) do
|
48
|
-
test_result = run_as_test do
|
49
|
-
instance.stubs(:my_module_method).returns(:new_return_value)
|
50
|
-
assert_method_visibility instance, :my_module_method, :protected
|
51
|
-
assert_equal :new_return_value, instance.send(:my_module_method)
|
52
|
-
end
|
53
|
-
assert_passed(test_result)
|
54
|
-
end
|
55
|
-
assert_equal :original_return_value, instance.send(:my_module_method)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
59
|
-
mod = Module.new do
|
60
|
-
def my_module_method
|
61
|
-
:original_return_value
|
62
|
-
end
|
63
|
-
private :my_module_method
|
64
|
-
end
|
65
|
-
instance = Class.new do
|
66
|
-
include mod
|
67
|
-
end.new
|
68
|
-
assert_snapshot_unchanged(instance) do
|
69
|
-
test_result = run_as_test do
|
70
|
-
instance.stubs(:my_module_method).returns(:new_return_value)
|
71
|
-
assert_method_visibility instance, :my_module_method, :private
|
72
|
-
assert_equal :new_return_value, instance.send(:my_module_method)
|
73
|
-
end
|
74
|
-
assert_passed(test_result)
|
75
|
-
end
|
76
|
-
assert_equal :original_return_value, instance.send(:my_module_method)
|
77
|
-
end
|
78
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_public_method_and_leave_it_unchanged_after_test
|
17
|
-
Object.class_eval do
|
18
|
-
def my_instance_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
public :my_instance_method
|
22
|
-
end
|
23
|
-
instance = Class.new.new
|
24
|
-
assert_snapshot_unchanged(instance) do
|
25
|
-
test_result = run_as_test do
|
26
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
27
|
-
assert_equal :new_return_value, instance.my_instance_method
|
28
|
-
end
|
29
|
-
assert_passed(test_result)
|
30
|
-
end
|
31
|
-
assert_equal :original_return_value, instance.my_instance_method
|
32
|
-
ensure
|
33
|
-
Object.class_eval { remove_method :my_instance_method }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
37
|
-
Object.class_eval do
|
38
|
-
def my_instance_method
|
39
|
-
:original_return_value
|
40
|
-
end
|
41
|
-
protected :my_instance_method
|
42
|
-
end
|
43
|
-
instance = Class.new.new
|
44
|
-
assert_snapshot_unchanged(instance) do
|
45
|
-
test_result = run_as_test do
|
46
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
47
|
-
assert_equal :new_return_value, instance.send(:my_instance_method)
|
48
|
-
end
|
49
|
-
assert_passed(test_result)
|
50
|
-
end
|
51
|
-
assert_equal :original_return_value, instance.send(:my_instance_method)
|
52
|
-
ensure
|
53
|
-
Object.class_eval { remove_method :my_instance_method }
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
57
|
-
Object.class_eval do
|
58
|
-
def my_instance_method
|
59
|
-
:original_return_value
|
60
|
-
end
|
61
|
-
private :my_instance_method
|
62
|
-
end
|
63
|
-
instance = Class.new.new
|
64
|
-
assert_snapshot_unchanged(instance) do
|
65
|
-
test_result = run_as_test do
|
66
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
67
|
-
assert_equal :new_return_value, instance.send(:my_instance_method)
|
68
|
-
end
|
69
|
-
assert_passed(test_result)
|
70
|
-
end
|
71
|
-
assert_equal :original_return_value, instance.send(:my_instance_method)
|
72
|
-
ensure
|
73
|
-
Object.class_eval { remove_method :my_instance_method }
|
74
|
-
end
|
75
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_public_method_and_leave_it_unchanged_after_test
|
17
|
-
instance = Class.new.new
|
18
|
-
class << instance
|
19
|
-
def my_singleton_method
|
20
|
-
:original_return_value
|
21
|
-
end
|
22
|
-
public :my_singleton_method
|
23
|
-
end
|
24
|
-
assert_snapshot_unchanged(instance) do
|
25
|
-
test_result = run_as_test do
|
26
|
-
instance.stubs(:my_singleton_method).returns(:stubbed_return_value)
|
27
|
-
assert_equal :stubbed_return_value, instance.my_singleton_method
|
28
|
-
end
|
29
|
-
assert_passed(test_result)
|
30
|
-
end
|
31
|
-
assert_equal :original_return_value, instance.my_singleton_method
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
35
|
-
instance = Class.new.new
|
36
|
-
class << instance
|
37
|
-
def my_singleton_method
|
38
|
-
:original_return_value
|
39
|
-
end
|
40
|
-
protected :my_singleton_method
|
41
|
-
end
|
42
|
-
assert_snapshot_unchanged(instance) do
|
43
|
-
test_result = run_as_test do
|
44
|
-
instance.stubs(:my_singleton_method).returns(:stubbed_return_value)
|
45
|
-
assert_equal :stubbed_return_value, instance.send(:my_singleton_method)
|
46
|
-
end
|
47
|
-
assert_passed(test_result)
|
48
|
-
end
|
49
|
-
assert_equal :original_return_value, instance.send(:my_singleton_method)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
53
|
-
instance = Class.new.new
|
54
|
-
class << instance
|
55
|
-
def my_singleton_method
|
56
|
-
:original_return_value
|
57
|
-
end
|
58
|
-
private :my_singleton_method
|
59
|
-
end
|
60
|
-
assert_snapshot_unchanged(instance) do
|
61
|
-
test_result = run_as_test do
|
62
|
-
instance.stubs(:my_singleton_method).returns(:stubbed_return_value)
|
63
|
-
assert_equal :stubbed_return_value, instance.send(:my_singleton_method)
|
64
|
-
end
|
65
|
-
assert_passed(test_result)
|
66
|
-
end
|
67
|
-
assert_equal :original_return_value, instance.send(:my_singleton_method)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_public_method_and_leave_it_unchanged_after_test
|
17
|
-
superklass = Class.new do
|
18
|
-
def my_superclass_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
public :my_superclass_method
|
22
|
-
end
|
23
|
-
klass = Class.new(superklass)
|
24
|
-
instance = klass.new
|
25
|
-
assert_snapshot_unchanged(instance) do
|
26
|
-
test_result = run_as_test do
|
27
|
-
instance.stubs(:my_superclass_method).returns(:new_return_value)
|
28
|
-
assert_equal :new_return_value, instance.my_superclass_method
|
29
|
-
end
|
30
|
-
assert_passed(test_result)
|
31
|
-
end
|
32
|
-
assert_equal :original_return_value, instance.my_superclass_method
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
36
|
-
superklass = Class.new do
|
37
|
-
def my_superclass_method
|
38
|
-
:original_return_value
|
39
|
-
end
|
40
|
-
protected :my_superclass_method
|
41
|
-
end
|
42
|
-
klass = Class.new(superklass)
|
43
|
-
instance = klass.new
|
44
|
-
assert_snapshot_unchanged(instance) do
|
45
|
-
test_result = run_as_test do
|
46
|
-
instance.stubs(:my_superclass_method).returns(:new_return_value)
|
47
|
-
assert_equal :new_return_value, instance.send(:my_superclass_method)
|
48
|
-
end
|
49
|
-
assert_passed(test_result)
|
50
|
-
end
|
51
|
-
assert_equal :original_return_value, instance.send(:my_superclass_method)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
55
|
-
superklass = Class.new do
|
56
|
-
def my_superclass_method
|
57
|
-
:original_return_value
|
58
|
-
end
|
59
|
-
private :my_superclass_method
|
60
|
-
end
|
61
|
-
klass = Class.new(superklass)
|
62
|
-
instance = klass.new
|
63
|
-
assert_snapshot_unchanged(instance) do
|
64
|
-
test_result = run_as_test do
|
65
|
-
instance.stubs(:my_superclass_method).returns(:new_return_value)
|
66
|
-
assert_equal :new_return_value, instance.send(:my_superclass_method)
|
67
|
-
end
|
68
|
-
assert_passed(test_result)
|
69
|
-
end
|
70
|
-
assert_equal :original_return_value, instance.send(:my_superclass_method)
|
71
|
-
end
|
72
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
unless Mocha::PRE_RUBY_V19
|
5
|
-
class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_stubbing_class_method_defined_by_aliasing_module_instance_method
|
17
|
-
mod = Module.new do
|
18
|
-
def module_instance_method
|
19
|
-
'module-instance-method'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
klass = Class.new do
|
24
|
-
extend mod
|
25
|
-
class << self
|
26
|
-
alias_method :aliased_module_instance_method, :module_instance_method
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
assert_snapshot_unchanged(klass) do
|
31
|
-
test_result = run_as_test do
|
32
|
-
klass.stubs(:aliased_module_instance_method).returns('stubbed-aliased-module-instance-method')
|
33
|
-
assert_equal 'stubbed-aliased-module-instance-method', klass.aliased_module_instance_method
|
34
|
-
end
|
35
|
-
assert_passed(test_result)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubModuleMethodTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_method_within_test
|
17
|
-
mod = Module.new { def self.my_module_method; :original_return_value; end }
|
18
|
-
test_result = run_as_test do
|
19
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
20
|
-
assert_equal :new_return_value, mod.my_module_method
|
21
|
-
end
|
22
|
-
assert_passed(test_result)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_leave_stubbed_public_method_unchanged_after_test
|
26
|
-
mod = Module.new { class << self; def my_module_method; :original_return_value; end; public :my_module_method; end }
|
27
|
-
run_as_test do
|
28
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
29
|
-
end
|
30
|
-
assert mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' }
|
31
|
-
assert_equal :original_return_value, mod.my_module_method
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_leave_stubbed_protected_method_unchanged_after_test
|
35
|
-
mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; def my_unprotected_module_method; my_module_method; end; end }
|
36
|
-
run_as_test do
|
37
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
38
|
-
end
|
39
|
-
assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' }
|
40
|
-
assert_equal :original_return_value, mod.my_unprotected_module_method
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_leave_stubbed_private_method_unchanged_after_test
|
44
|
-
mod = Module.new { class << self; def my_module_method; :original_return_value; end; private :my_module_method; end }
|
45
|
-
run_as_test do
|
46
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
47
|
-
end
|
48
|
-
assert mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' }
|
49
|
-
assert_equal :original_return_value, mod.send(:my_module_method)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_reset_expectations_after_test
|
53
|
-
mod = Module.new { def self.my_module_method; :original_return_value; end }
|
54
|
-
run_as_test do
|
55
|
-
mod.stubs(:my_module_method)
|
56
|
-
end
|
57
|
-
assert_equal 0, mod.mocha.__expectations__.length
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_be_able_to_stub_a_superclass_method
|
61
|
-
supermod = Module.new { def self.my_superclass_method; :original_return_value; end }
|
62
|
-
mod = Module.new { include supermod }
|
63
|
-
test_result = run_as_test do
|
64
|
-
mod.stubs(:my_superclass_method).returns(:new_return_value)
|
65
|
-
assert_equal :new_return_value, mod.my_superclass_method
|
66
|
-
end
|
67
|
-
assert_passed(test_result)
|
68
|
-
assert supermod.public_methods.any? { |m| m.to_s == 'my_superclass_method' }
|
69
|
-
assert !mod.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' }
|
70
|
-
assert_equal :original_return_value, supermod.my_superclass_method
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
74
|
-
ruby18_mod = Module.new do
|
75
|
-
class << self
|
76
|
-
def public_methods(include_superclass = true)
|
77
|
-
['my_module_method']
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
test_result = run_as_test do
|
82
|
-
ruby18_mod.stubs(:my_module_method).returns(:new_return_value)
|
83
|
-
assert_equal :new_return_value, ruby18_mod.my_module_method
|
84
|
-
end
|
85
|
-
assert_passed(test_result)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
89
|
-
ruby19_mod = Module.new do
|
90
|
-
class << self
|
91
|
-
def public_methods(include_superclass = true)
|
92
|
-
[:my_module_method]
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
test_result = run_as_test do
|
97
|
-
ruby19_mod.stubs(:my_module_method).returns(:new_return_value)
|
98
|
-
assert_equal :new_return_value, ruby19_mod.my_module_method
|
99
|
-
end
|
100
|
-
assert_passed(test_result)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
104
|
-
ruby18_mod = Module.new do
|
105
|
-
class << self
|
106
|
-
def protected_methods(include_superclass = true)
|
107
|
-
['my_module_method']
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
test_result = run_as_test do
|
112
|
-
ruby18_mod.stubs(:my_module_method).returns(:new_return_value)
|
113
|
-
assert_equal :new_return_value, ruby18_mod.my_module_method
|
114
|
-
end
|
115
|
-
assert_passed(test_result)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
119
|
-
ruby19_mod = Module.new do
|
120
|
-
class << self
|
121
|
-
def protected_methods(include_superclass = true)
|
122
|
-
[:my_module_method]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
test_result = run_as_test do
|
127
|
-
ruby19_mod.stubs(:my_module_method).returns(:new_return_value)
|
128
|
-
assert_equal :new_return_value, ruby19_mod.my_module_method
|
129
|
-
end
|
130
|
-
assert_passed(test_result)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
134
|
-
ruby18_mod = Module.new do
|
135
|
-
class << self
|
136
|
-
def private_methods(include_superclass = true)
|
137
|
-
['my_module_method']
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
test_result = run_as_test do
|
142
|
-
ruby18_mod.stubs(:my_module_method).returns(:new_return_value)
|
143
|
-
assert_equal :new_return_value, ruby18_mod.my_module_method
|
144
|
-
end
|
145
|
-
assert_passed(test_result)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
|
149
|
-
ruby19_mod = Module.new do
|
150
|
-
class << self
|
151
|
-
def private_methods(include_superclass = true)
|
152
|
-
[:my_module_method]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
test_result = run_as_test do
|
157
|
-
ruby19_mod.stubs(:my_module_method).returns(:new_return_value)
|
158
|
-
assert_equal :new_return_value, ruby19_mod.my_module_method
|
159
|
-
end
|
160
|
-
assert_passed(test_result)
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class StubTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_build_stub_and_explicitly_add_an_expectation
|
17
|
-
test_result = run_as_test do
|
18
|
-
foo = stub()
|
19
|
-
foo.stubs(:bar)
|
20
|
-
foo.bar
|
21
|
-
end
|
22
|
-
assert_passed(test_result)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_build_named_stub_and_explicitly_add_an_expectation
|
26
|
-
test_result = run_as_test do
|
27
|
-
foo = stub('foo')
|
28
|
-
foo.stubs(:bar)
|
29
|
-
foo.bar
|
30
|
-
end
|
31
|
-
assert_passed(test_result)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_build_stub_incorporating_two_expectations
|
35
|
-
test_result = run_as_test do
|
36
|
-
foo = stub(:bar => 'bar', :baz => 'baz')
|
37
|
-
foo.bar
|
38
|
-
foo.baz
|
39
|
-
end
|
40
|
-
assert_passed(test_result)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_build_named_stub_incorporating_two_expectations
|
44
|
-
test_result = run_as_test do
|
45
|
-
foo = stub('foo', :bar => 'bar', :baz => 'baz')
|
46
|
-
foo.bar
|
47
|
-
foo.baz
|
48
|
-
end
|
49
|
-
assert_passed(test_result)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class Widget
|
5
|
-
|
6
|
-
def model
|
7
|
-
'original_model'
|
8
|
-
end
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
def find(options)
|
13
|
-
[]
|
14
|
-
end
|
15
|
-
|
16
|
-
def create(attributes)
|
17
|
-
Widget.new
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
module Thingy
|
25
|
-
|
26
|
-
def self.wotsit
|
27
|
-
:hoojamaflip
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class StubbaExampleTest < Mocha::TestCase
|
33
|
-
|
34
|
-
def test_should_stub_instance_method
|
35
|
-
widget = Widget.new
|
36
|
-
widget.expects(:model).returns('different_model')
|
37
|
-
assert_equal 'different_model', widget.model
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_stub_module_method
|
41
|
-
should_stub_module_method
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_stub_module_method_again
|
45
|
-
should_stub_module_method
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_stub_class_method
|
49
|
-
should_stub_class_method
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_stub_class_method_again
|
53
|
-
should_stub_class_method
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_stub_instance_method_on_any_instance_of_a_class
|
57
|
-
should_stub_instance_method_on_any_instance_of_a_class
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_stub_instance_method_on_any_instance_of_a_class_again
|
61
|
-
should_stub_instance_method_on_any_instance_of_a_class
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_should_stub_two_different_class_methods
|
65
|
-
should_stub_two_different_class_methods
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_should_stub_two_different_class_methods_again
|
69
|
-
should_stub_two_different_class_methods
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def should_stub_module_method
|
75
|
-
Thingy.expects(:wotsit).returns(:dooda)
|
76
|
-
assert_equal :dooda, Thingy.wotsit
|
77
|
-
end
|
78
|
-
|
79
|
-
def should_stub_class_method
|
80
|
-
widgets = [Widget.new]
|
81
|
-
Widget.expects(:find).with(:all).returns(widgets)
|
82
|
-
assert_equal widgets, Widget.find(:all)
|
83
|
-
end
|
84
|
-
|
85
|
-
def should_stub_two_different_class_methods
|
86
|
-
found_widgets = [Widget.new]
|
87
|
-
created_widget = Widget.new
|
88
|
-
Widget.expects(:find).with(:all).returns(found_widgets)
|
89
|
-
Widget.expects(:create).with(:model => 'wombat').returns(created_widget)
|
90
|
-
assert_equal found_widgets, Widget.find(:all)
|
91
|
-
assert_equal created_widget, Widget.create(:model => 'wombat')
|
92
|
-
end
|
93
|
-
|
94
|
-
def should_stub_instance_method_on_any_instance_of_a_class
|
95
|
-
Widget.any_instance.expects(:model).at_least_once.returns('another_model')
|
96
|
-
widget_1 = Widget.new
|
97
|
-
widget_2 = Widget.new
|
98
|
-
assert_equal 'another_model', widget_1.model
|
99
|
-
assert_equal 'another_model', widget_2.model
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|