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
data/test/unit/central_test.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/central'
|
4
|
-
require 'mocha/mock'
|
5
|
-
require 'method_definer'
|
6
|
-
|
7
|
-
class CentralTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
include Mocha
|
10
|
-
|
11
|
-
def test_should_start_with_empty_stubba_methods
|
12
|
-
stubba = Central.new
|
13
|
-
|
14
|
-
assert_equal [], stubba.stubba_methods
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_stub_method_if_not_already_stubbed
|
18
|
-
method = build_mock
|
19
|
-
method.expects(:stub)
|
20
|
-
stubba = Central.new
|
21
|
-
|
22
|
-
stubba.stub(method)
|
23
|
-
|
24
|
-
assert method.__verified__?
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_not_stub_method_if_already_stubbed
|
28
|
-
method = build_mock
|
29
|
-
method.stubs(:matches?).returns(true)
|
30
|
-
method.expects(:stub).times(0)
|
31
|
-
stubba = Central.new
|
32
|
-
stubba.stubba_methods = [method]
|
33
|
-
|
34
|
-
stubba.stub(method)
|
35
|
-
|
36
|
-
assert method.__verified__?
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_record_method
|
40
|
-
method = build_mock
|
41
|
-
method.expects(:stub)
|
42
|
-
stubba = Central.new
|
43
|
-
|
44
|
-
stubba.stub(method)
|
45
|
-
|
46
|
-
assert_equal [method], stubba.stubba_methods
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_unstub_specified_method
|
50
|
-
stubba = Central.new
|
51
|
-
method_1 = build_mock
|
52
|
-
method_1.stubs(:matches?).returns(false)
|
53
|
-
method_2 = build_mock
|
54
|
-
method_2.stubs(:matches?).returns(true)
|
55
|
-
method_2.expects(:unstub)
|
56
|
-
stubba.stubba_methods = [method_1, method_2]
|
57
|
-
|
58
|
-
stubba.unstub(method_2)
|
59
|
-
|
60
|
-
assert_equal [method_1], stubba.stubba_methods
|
61
|
-
assert method_2.__verified__?
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_should_not_unstub_specified_method_if_not_already_stubbed
|
65
|
-
stubba = Central.new
|
66
|
-
method_1 = build_mock
|
67
|
-
method_1.stubs(:matches?).returns(false)
|
68
|
-
method_2 = build_mock
|
69
|
-
method_2.expects(:unstub).never
|
70
|
-
stubba.stubba_methods = [method_1]
|
71
|
-
|
72
|
-
stubba.unstub(method_2)
|
73
|
-
|
74
|
-
assert_equal [method_1], stubba.stubba_methods
|
75
|
-
assert method_2.__verified__?
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_should_unstub_all_methods
|
79
|
-
stubba = Central.new
|
80
|
-
method_1 = build_mock
|
81
|
-
method_1.stubs(:matches?).returns(true)
|
82
|
-
method_1.expects(:unstub)
|
83
|
-
method_2 = build_mock
|
84
|
-
method_2.stubs(:matches?).returns(true)
|
85
|
-
method_2.expects(:unstub)
|
86
|
-
stubba.stubba_methods = [method_1, method_2]
|
87
|
-
|
88
|
-
stubba.unstub_all
|
89
|
-
|
90
|
-
assert_equal [], stubba.stubba_methods
|
91
|
-
assert method_1.__verified__?
|
92
|
-
assert method_2.__verified__?
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def build_mock
|
98
|
-
Mock.new(nil)
|
99
|
-
end
|
100
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/change_state_side_effect'
|
4
|
-
|
5
|
-
class ChangeStateSideEffectTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Mocha
|
8
|
-
|
9
|
-
class FakeState
|
10
|
-
|
11
|
-
attr_reader :active
|
12
|
-
attr_writer :description
|
13
|
-
|
14
|
-
def activate
|
15
|
-
@active = true
|
16
|
-
end
|
17
|
-
|
18
|
-
def mocha_inspect
|
19
|
-
@description
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_activate_the_given_state
|
25
|
-
state = FakeState.new
|
26
|
-
side_effect = ChangeStateSideEffect.new(state)
|
27
|
-
|
28
|
-
side_effect.perform
|
29
|
-
|
30
|
-
assert state.active
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_describe_itself_in_terms_of_the_activated_state
|
34
|
-
state = FakeState.new
|
35
|
-
state.description = 'the-new-state'
|
36
|
-
side_effect = ChangeStateSideEffect.new(state)
|
37
|
-
|
38
|
-
assert_equal 'then the-new-state', side_effect.mocha_inspect
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,260 +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 < Test::Unit::TestCase
|
8
|
-
|
9
|
-
include Mocha
|
10
|
-
|
11
|
-
def test_should_provide_hidden_version_of_method_name_starting_with_prefix
|
12
|
-
method = ClassMethod.new(nil, :original_method_name)
|
13
|
-
assert_match(/^__stubba__/, method.hidden_method.to_s)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_provide_hidden_version_of_method_name_ending_with_suffix
|
17
|
-
method = ClassMethod.new(nil, :original_method_name)
|
18
|
-
assert_match(/__stubba__$/, method.hidden_method.to_s)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_provide_hidden_version_of_method_name_including_original_method_name
|
22
|
-
method = ClassMethod.new(nil, :original_method_name)
|
23
|
-
assert_match(/original_method_name/, method.hidden_method.to_s)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_provide_hidden_version_of_method_name_substituting_question_mark
|
27
|
-
method = ClassMethod.new(nil, :question_mark?)
|
28
|
-
assert_no_match(/\?/, method.hidden_method.to_s)
|
29
|
-
assert_match(/question_mark_substituted_character_63/, method.hidden_method.to_s)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_provide_hidden_version_of_method_name_substituting_exclamation_mark
|
33
|
-
method = ClassMethod.new(nil, :exclamation_mark!)
|
34
|
-
assert_no_match(/!/, method.hidden_method.to_s)
|
35
|
-
assert_match(/exclamation_mark_substituted_character_33/, method.hidden_method.to_s)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_provide_hidden_version_of_method_name_substituting_equals_sign
|
39
|
-
method = ClassMethod.new(nil, :equals_sign=)
|
40
|
-
assert_no_match(/\=/, method.hidden_method.to_s)
|
41
|
-
assert_match(/equals_sign_substituted_character_61/, method.hidden_method.to_s)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_provide_hidden_version_of_method_name_substituting_brackets
|
45
|
-
method = ClassMethod.new(nil, :[])
|
46
|
-
assert_no_match(/\[\]/, method.hidden_method.to_s)
|
47
|
-
assert_match(/substituted_character_91__substituted_character_93/, method.hidden_method.to_s)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_provide_hidden_version_of_method_name_substituting_plus_sign
|
51
|
-
method = ClassMethod.new(nil, :+)
|
52
|
-
assert_no_match(/\+/, method.hidden_method.to_s)
|
53
|
-
assert_match(/substituted_character_43/, method.hidden_method.to_s)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_hide_original_method
|
57
|
-
klass = Class.new { def self.method_x; end }
|
58
|
-
method = ClassMethod.new(klass, :method_x)
|
59
|
-
hidden_method_x = method.hidden_method
|
60
|
-
|
61
|
-
method.hide_original_method
|
62
|
-
|
63
|
-
assert klass.respond_to?(hidden_method_x)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_respond_to_original_method_name_after_original_method_has_been_hidden
|
67
|
-
klass = Class.new { def self.original_method_name; end }
|
68
|
-
method = ClassMethod.new(klass, :original_method_name)
|
69
|
-
|
70
|
-
method.hide_original_method
|
71
|
-
|
72
|
-
assert klass.respond_to?(:original_method_name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_should_not_hide_original_method_if_method_not_defined
|
76
|
-
klass = Class.new
|
77
|
-
method = ClassMethod.new(klass, :method_x)
|
78
|
-
hidden_method_x = method.hidden_method
|
79
|
-
|
80
|
-
method.hide_original_method
|
81
|
-
|
82
|
-
assert_equal false, klass.respond_to?(hidden_method_x)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_define_a_new_method_which_should_call_mocha_method_missing
|
86
|
-
klass = Class.new { def self.method_x; end }
|
87
|
-
mocha = build_mock
|
88
|
-
klass.define_instance_method(:mocha) { mocha }
|
89
|
-
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
90
|
-
method = ClassMethod.new(klass, :method_x)
|
91
|
-
|
92
|
-
method.hide_original_method
|
93
|
-
method.define_new_method
|
94
|
-
result = klass.method_x(:param1, :param2)
|
95
|
-
|
96
|
-
assert_equal :result, result
|
97
|
-
assert mocha.__verified__?
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_should_remove_new_method
|
101
|
-
klass = Class.new { def self.method_x; end }
|
102
|
-
method = ClassMethod.new(klass, :method_x)
|
103
|
-
|
104
|
-
method.remove_new_method
|
105
|
-
|
106
|
-
assert_equal false, klass.respond_to?(:method_x)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_should_restore_original_method
|
110
|
-
klass = Class.new { def self.method_x; end }
|
111
|
-
method = ClassMethod.new(klass, :method_x)
|
112
|
-
hidden_method_x = method.hidden_method.to_sym
|
113
|
-
klass.define_instance_method(hidden_method_x) { :original_result }
|
114
|
-
|
115
|
-
method.remove_new_method
|
116
|
-
method.restore_original_method
|
117
|
-
|
118
|
-
assert_equal :original_result, klass.method_x
|
119
|
-
assert_equal false, klass.respond_to?(hidden_method_x)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_should_not_restore_original_method_if_hidden_method_is_not_defined
|
123
|
-
klass = Class.new { def self.method_x; :new_result; end }
|
124
|
-
method = ClassMethod.new(klass, :method_x)
|
125
|
-
|
126
|
-
method.restore_original_method
|
127
|
-
|
128
|
-
assert_equal :new_result, klass.method_x
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_call_hide_original_method
|
132
|
-
klass = Class.new { def self.method_x; end }
|
133
|
-
method = ClassMethod.new(klass, :method_x)
|
134
|
-
method.hide_original_method
|
135
|
-
method.define_instance_accessor(:hide_called)
|
136
|
-
method.replace_instance_method(:hide_original_method) { self.hide_called = true }
|
137
|
-
|
138
|
-
method.stub
|
139
|
-
|
140
|
-
assert method.hide_called
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_should_call_define_new_method
|
144
|
-
klass = Class.new { def self.method_x; end }
|
145
|
-
method = ClassMethod.new(klass, :method_x)
|
146
|
-
method.define_instance_accessor(:define_called)
|
147
|
-
method.replace_instance_method(:define_new_method) { self.define_called = true }
|
148
|
-
|
149
|
-
method.stub
|
150
|
-
|
151
|
-
assert method.define_called
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_call_remove_new_method
|
155
|
-
klass = Class.new { def self.method_x; end }
|
156
|
-
method = ClassMethod.new(klass, :method_x)
|
157
|
-
mocha = build_mock
|
158
|
-
klass.define_instance_method(:mocha) { mocha }
|
159
|
-
method.define_instance_accessor(:remove_called)
|
160
|
-
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
161
|
-
|
162
|
-
method.unstub
|
163
|
-
|
164
|
-
assert method.remove_called
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_should_call_restore_original_method
|
168
|
-
klass = Class.new { def self.method_x; end }
|
169
|
-
mocha = build_mock
|
170
|
-
klass.define_instance_method(:mocha) { mocha }
|
171
|
-
method = ClassMethod.new(klass, :method_x)
|
172
|
-
method.define_instance_accessor(:restore_called)
|
173
|
-
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
174
|
-
|
175
|
-
method.unstub
|
176
|
-
|
177
|
-
assert method.restore_called
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_should_call_mocha_unstub
|
181
|
-
klass = Class.new { def self.method_x; end }
|
182
|
-
method = ClassMethod.new(klass, :method_x)
|
183
|
-
method.replace_instance_method(:restore_original_method) { }
|
184
|
-
mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
|
185
|
-
mocha.define_instance_method(:any_expectations?) { true }
|
186
|
-
method.replace_instance_method(:mock) { mocha }
|
187
|
-
|
188
|
-
method.unstub
|
189
|
-
assert_equal mocha.unstub_method, :method_x
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_should_call_stubbee_reset_mocha_if_no_expectations_remaining
|
193
|
-
klass = Class.new { def self.method_x; end }
|
194
|
-
method = ClassMethod.new(klass, :method_x)
|
195
|
-
method.replace_instance_method(:remove_new_method) { }
|
196
|
-
method.replace_instance_method(:restore_original_method) { }
|
197
|
-
mocha = Class.new
|
198
|
-
mocha.define_instance_method(:unstub) { |method_name| }
|
199
|
-
mocha.define_instance_method(:any_expectations?) { false }
|
200
|
-
method.replace_instance_method(:mock) { mocha }
|
201
|
-
stubbee = Class.new { attr_accessor :reset_mocha_called; def reset_mocha; self.reset_mocha_called = true; end; }.new
|
202
|
-
method.replace_instance_method(:stubbee) { stubbee }
|
203
|
-
|
204
|
-
method.unstub
|
205
|
-
|
206
|
-
assert stubbee.reset_mocha_called
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_should_return_mock_for_stubbee
|
210
|
-
mocha = Object.new
|
211
|
-
stubbee = Object.new
|
212
|
-
stubbee.define_instance_accessor(:mocha) { mocha }
|
213
|
-
stubbee.mocha = nil
|
214
|
-
method = ClassMethod.new(stubbee, :method_name)
|
215
|
-
assert_equal stubbee.mocha, method.mock
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_should_not_match_if_other_object_has_a_different_class
|
219
|
-
class_method = ClassMethod.new(Object.new, :method)
|
220
|
-
other_object = Object.new
|
221
|
-
assert !class_method.matches?(other_object)
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_should_not_match_if_other_class_method_has_different_stubbee
|
225
|
-
stubbee_1 = Object.new
|
226
|
-
stubbee_2 = Object.new
|
227
|
-
class_method_1 = ClassMethod.new(stubbee_1, :method)
|
228
|
-
class_method_2 = ClassMethod.new(stubbee_2, :method)
|
229
|
-
assert !class_method_1.matches?(class_method_2)
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_should_not_match_if_other_class_method_has_different_method
|
233
|
-
stubbee = Object.new
|
234
|
-
class_method_1 = ClassMethod.new(stubbee, :method_1)
|
235
|
-
class_method_2 = ClassMethod.new(stubbee, :method_2)
|
236
|
-
assert !class_method_1.matches?(class_method_2)
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice
|
240
|
-
stubbee = Object.new
|
241
|
-
class_method_1 = ClassMethod.new(stubbee, :method)
|
242
|
-
class_method_2 = ClassMethod.new(stubbee, :method)
|
243
|
-
assert class_method_1.matches?(class_method_2)
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy
|
247
|
-
stubbee = Class.new do
|
248
|
-
def equal?(other); false; end
|
249
|
-
end.new
|
250
|
-
class_method_1 = ClassMethod.new(stubbee, :method)
|
251
|
-
class_method_2 = ClassMethod.new(stubbee, :method)
|
252
|
-
assert class_method_1.matches?(class_method_2)
|
253
|
-
end
|
254
|
-
|
255
|
-
private
|
256
|
-
|
257
|
-
def build_mock
|
258
|
-
Mock.new(nil)
|
259
|
-
end
|
260
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require "mocha/configuration"
|
3
|
-
|
4
|
-
class ConfigurationTest < Test::Unit::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 < Test::Unit::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 < Test::Unit::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,71 +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 < Test::Unit::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
|
-
end
|