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,69 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnClassAndAliasedTest < Test::Unit::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 do
|
18
|
-
def my_instance_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
public :my_instance_method
|
22
|
-
alias_method :my_aliased_method, :my_instance_method
|
23
|
-
end.new
|
24
|
-
assert_snapshot_unchanged(instance) do
|
25
|
-
test_result = run_as_test do
|
26
|
-
instance.stubs(:my_aliased_method).returns(:new_return_value)
|
27
|
-
assert_equal :new_return_value, instance.my_aliased_method
|
28
|
-
end
|
29
|
-
assert_passed(test_result)
|
30
|
-
end
|
31
|
-
assert_equal :original_return_value, instance.my_aliased_method
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
35
|
-
instance = Class.new do
|
36
|
-
def my_instance_method
|
37
|
-
:original_return_value
|
38
|
-
end
|
39
|
-
protected :my_instance_method
|
40
|
-
alias_method :my_aliased_method, :my_instance_method
|
41
|
-
end.new
|
42
|
-
assert_snapshot_unchanged(instance) do
|
43
|
-
test_result = run_as_test do
|
44
|
-
instance.stubs(:my_aliased_method).returns(:new_return_value)
|
45
|
-
assert_equal :new_return_value, instance.send(:my_aliased_method)
|
46
|
-
end
|
47
|
-
assert_passed(test_result)
|
48
|
-
end
|
49
|
-
assert_equal :original_return_value, instance.send(:my_aliased_method)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
53
|
-
instance = Class.new do
|
54
|
-
def my_instance_method
|
55
|
-
:original_return_value
|
56
|
-
end
|
57
|
-
private :my_instance_method
|
58
|
-
alias_method :my_aliased_method, :my_instance_method
|
59
|
-
end.new
|
60
|
-
assert_snapshot_unchanged(instance) do
|
61
|
-
test_result = run_as_test do
|
62
|
-
instance.stubs(:my_aliased_method).returns(:new_return_value)
|
63
|
-
assert_equal :new_return_value, instance.send(:my_aliased_method)
|
64
|
-
end
|
65
|
-
assert_passed(test_result)
|
66
|
-
end
|
67
|
-
assert_equal :original_return_value, instance.send(:my_aliased_method)
|
68
|
-
end
|
69
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnClassTest < Test::Unit::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 do
|
18
|
-
def my_instance_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
public :my_instance_method
|
22
|
-
end.new
|
23
|
-
assert_snapshot_unchanged(instance) do
|
24
|
-
test_result = run_as_test do
|
25
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
26
|
-
assert_equal :new_return_value, instance.my_instance_method
|
27
|
-
end
|
28
|
-
assert_passed(test_result)
|
29
|
-
end
|
30
|
-
assert_equal :original_return_value, instance.my_instance_method
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
34
|
-
instance = Class.new do
|
35
|
-
def my_instance_method
|
36
|
-
:original_return_value
|
37
|
-
end
|
38
|
-
protected :my_instance_method
|
39
|
-
end.new
|
40
|
-
assert_snapshot_unchanged(instance) do
|
41
|
-
test_result = run_as_test do
|
42
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
43
|
-
assert_equal :new_return_value, instance.send(:my_instance_method)
|
44
|
-
end
|
45
|
-
assert_passed(test_result)
|
46
|
-
end
|
47
|
-
assert_equal :original_return_value, instance.send(:my_instance_method)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
51
|
-
instance = Class.new do
|
52
|
-
def my_instance_method
|
53
|
-
:original_return_value
|
54
|
-
end
|
55
|
-
private :my_instance_method
|
56
|
-
end.new
|
57
|
-
assert_snapshot_unchanged(instance) do
|
58
|
-
test_result = run_as_test do
|
59
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
60
|
-
assert_equal :new_return_value, instance.send(:my_instance_method)
|
61
|
-
end
|
62
|
-
assert_passed(test_result)
|
63
|
-
end
|
64
|
-
assert_equal :original_return_value, instance.send(:my_instance_method)
|
65
|
-
end
|
66
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnKernelModuleTest < Test::Unit::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
|
-
Kernel.module_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
|
-
Kernel.module_eval { remove_method :my_instance_method }
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
37
|
-
Kernel.module_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
|
-
Kernel.module_eval { remove_method :my_instance_method }
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
57
|
-
Kernel.module_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
|
-
Kernel.module_eval { remove_method :my_instance_method }
|
74
|
-
end
|
75
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnModuleTest < Test::Unit::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_equal :new_return_value, instance.my_module_method
|
30
|
-
end
|
31
|
-
assert_passed(test_result)
|
32
|
-
end
|
33
|
-
assert_equal :original_return_value, instance.my_module_method
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_stub_protected_method_and_leave_it_unchanged_after_test
|
37
|
-
mod = Module.new do
|
38
|
-
def my_module_method
|
39
|
-
:original_return_value
|
40
|
-
end
|
41
|
-
protected :my_module_method
|
42
|
-
end
|
43
|
-
instance = Class.new do
|
44
|
-
include mod
|
45
|
-
end.new
|
46
|
-
assert_snapshot_unchanged(instance) do
|
47
|
-
test_result = run_as_test do
|
48
|
-
instance.stubs(:my_module_method).returns(:new_return_value)
|
49
|
-
assert_equal :new_return_value, instance.send(:my_module_method)
|
50
|
-
end
|
51
|
-
assert_passed(test_result)
|
52
|
-
end
|
53
|
-
assert_equal :original_return_value, instance.send(:my_module_method)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_stub_private_method_and_leave_it_unchanged_after_test
|
57
|
-
mod = Module.new do
|
58
|
-
def my_module_method
|
59
|
-
:original_return_value
|
60
|
-
end
|
61
|
-
private :my_module_method
|
62
|
-
end
|
63
|
-
instance = Class.new do
|
64
|
-
include mod
|
65
|
-
end.new
|
66
|
-
assert_snapshot_unchanged(instance) do
|
67
|
-
test_result = run_as_test do
|
68
|
-
instance.stubs(:my_module_method).returns(:new_return_value)
|
69
|
-
assert_equal :new_return_value, instance.send(:my_module_method)
|
70
|
-
end
|
71
|
-
assert_passed(test_result)
|
72
|
-
end
|
73
|
-
assert_equal :original_return_value, instance.send(:my_module_method)
|
74
|
-
end
|
75
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnObjectClassTest < Test::Unit::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'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnSingletonClassTest < Test::Unit::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'
|
3
|
-
|
4
|
-
class StubInstanceMethodDefinedOnSuperclassTest < Test::Unit::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,163 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubModuleMethodTest < Test::Unit::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
|