mocha 0.10.5 → 0.11.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.
- data/COPYING.rdoc +1 -1
- data/README.rdoc +6 -4
- data/RELEASE.rdoc +12 -0
- data/Rakefile +29 -60
- data/doc/Mocha.html +112 -0
- data/doc/Mocha/API.html +898 -0
- data/doc/Mocha/ClassMethods.html +246 -0
- data/doc/Mocha/Configuration.html +471 -0
- data/doc/Mocha/Expectation.html +2570 -0
- data/doc/Mocha/Mock.html +830 -0
- data/doc/Mocha/ObjectMethods.html +668 -0
- data/doc/Mocha/ParameterMatchers.html +2715 -0
- data/doc/Mocha/ParameterMatchers/AllOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/AnyParameters.html +136 -0
- data/doc/Mocha/ParameterMatchers/Anything.html +136 -0
- data/doc/Mocha/ParameterMatchers/Base.html +419 -0
- data/doc/Mocha/ParameterMatchers/Equals.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntries.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasEntry.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasKey.html +137 -0
- data/doc/Mocha/ParameterMatchers/HasValue.html +137 -0
- data/doc/Mocha/ParameterMatchers/Includes.html +137 -0
- data/doc/Mocha/ParameterMatchers/InstanceOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/IsA.html +136 -0
- data/doc/Mocha/ParameterMatchers/KindOf.html +137 -0
- data/doc/Mocha/ParameterMatchers/Not.html +137 -0
- data/doc/Mocha/ParameterMatchers/Optionally.html +136 -0
- data/doc/Mocha/ParameterMatchers/QueryStringMatches.html +136 -0
- data/doc/Mocha/ParameterMatchers/RegexpMatches.html +137 -0
- data/doc/Mocha/ParameterMatchers/RespondsWith.html +137 -0
- data/doc/Mocha/ParameterMatchers/YamlEquivalent.html +137 -0
- data/doc/Mocha/Sequence.html +133 -0
- data/doc/Mocha/StateMachine.html +510 -0
- data/doc/Mocha/StateMachine/State.html +125 -0
- data/doc/Mocha/StateMachine/StatePredicate.html +125 -0
- data/doc/Mocha/StubbingError.html +134 -0
- data/doc/Mocha/UnexpectedInvocation.html +124 -0
- data/doc/_index.html +481 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +55 -0
- data/doc/css/style.css +322 -0
- data/doc/file.COPYING.html +72 -0
- data/doc/file.MIT-LICENSE.html +86 -0
- data/doc/file.README.html +153 -0
- data/doc/file.RELEASE.html +933 -0
- data/doc/file.misc.html +108 -0
- data/doc/file.mocha.html +90 -0
- data/doc/file.stubba.html +129 -0
- data/doc/file_list.html +67 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +153 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +510 -0
- data/doc/top-level-namespace.html +105 -0
- data/lib/mocha/any_instance_method.rb +16 -11
- data/lib/mocha/api.rb +120 -106
- data/lib/mocha/argument_iterator.rb +6 -6
- data/lib/mocha/backtrace_filter.rb +1 -1
- data/lib/mocha/cardinality.rb +21 -21
- data/lib/mocha/central.rb +8 -8
- data/lib/mocha/change_state_side_effect.rb +5 -5
- data/lib/mocha/class_method.rb +14 -19
- data/lib/mocha/configuration.rb +47 -37
- data/lib/mocha/deprecation.rb +8 -8
- data/lib/mocha/exception_raiser.rb +7 -7
- data/lib/mocha/expectation.rb +173 -77
- data/lib/mocha/expectation_error.rb +2 -2
- data/lib/mocha/expectation_list.rb +11 -11
- data/lib/mocha/in_state_ordering_constraint.rb +5 -5
- data/lib/mocha/inspect.rb +8 -8
- data/lib/mocha/instance_method.rb +1 -17
- data/lib/mocha/integration.rb +9 -9
- data/lib/mocha/integration/mini_test/assertion_counter.rb +9 -9
- data/lib/mocha/integration/mini_test/exception_translation.rb +6 -6
- data/lib/mocha/integration/mini_test/version_13.rb +6 -6
- data/lib/mocha/integration/mini_test/version_140.rb +6 -6
- data/lib/mocha/integration/mini_test/version_141.rb +6 -6
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +7 -7
- data/lib/mocha/integration/mini_test/version_200.rb +7 -7
- data/lib/mocha/integration/test_unit/assertion_counter.rb +10 -10
- data/lib/mocha/integration/test_unit/gem_version_200.rb +6 -6
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +6 -6
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +6 -6
- data/lib/mocha/is_a.rb +1 -1
- data/lib/mocha/logger.rb +6 -6
- data/lib/mocha/method_matcher.rb +7 -7
- data/lib/mocha/mock.rb +85 -48
- data/lib/mocha/mockery.rb +47 -33
- data/lib/mocha/module_method.rb +2 -2
- data/lib/mocha/multiple_yields.rb +9 -9
- data/lib/mocha/names.rb +18 -18
- data/lib/mocha/no_yields.rb +7 -7
- data/lib/mocha/object.rb +104 -75
- data/lib/mocha/parameter_matchers.rb +3 -3
- data/lib/mocha/parameter_matchers/all_of.rb +22 -12
- data/lib/mocha/parameter_matchers/any_of.rb +23 -12
- data/lib/mocha/parameter_matchers/any_parameters.rb +15 -8
- data/lib/mocha/parameter_matchers/anything.rb +20 -11
- data/lib/mocha/parameter_matchers/base.rb +35 -27
- data/lib/mocha/parameter_matchers/equals.rb +23 -12
- data/lib/mocha/parameter_matchers/has_entries.rb +22 -12
- data/lib/mocha/parameter_matchers/has_entry.rb +31 -13
- data/lib/mocha/parameter_matchers/has_key.rb +21 -11
- data/lib/mocha/parameter_matchers/has_value.rb +21 -11
- data/lib/mocha/parameter_matchers/includes.rb +15 -5
- data/lib/mocha/parameter_matchers/instance_of.rb +23 -12
- data/lib/mocha/parameter_matchers/is_a.rb +23 -12
- data/lib/mocha/parameter_matchers/kind_of.rb +23 -12
- data/lib/mocha/parameter_matchers/not.rb +22 -12
- data/lib/mocha/parameter_matchers/object.rb +5 -3
- data/lib/mocha/parameter_matchers/optionally.rb +24 -12
- data/lib/mocha/parameter_matchers/query_string.rb +14 -3
- data/lib/mocha/parameter_matchers/regexp_matches.rb +21 -11
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -6
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +16 -6
- data/lib/mocha/parameters_matcher.rb +8 -8
- data/lib/mocha/pretty_parameters.rb +7 -7
- data/lib/mocha/return_values.rb +11 -11
- data/lib/mocha/sequence.rb +23 -14
- data/lib/mocha/single_return_value.rb +7 -7
- data/lib/mocha/single_yield.rb +9 -9
- data/lib/mocha/standalone.rb +1 -1
- data/lib/mocha/state_machine.rb +61 -46
- data/lib/mocha/stubbing_error.rb +8 -5
- data/lib/mocha/thrower.rb +2 -2
- data/lib/mocha/unexpected_invocation.rb +9 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +10 -10
- data/lib/mocha_standalone.rb +1 -1
- data/mocha.gemspec +4 -7
- data/test/acceptance/acceptance_test_helper.rb +10 -10
- data/test/acceptance/api_test.rb +20 -20
- data/test/acceptance/bug_18914_test.rb +12 -12
- data/test/acceptance/bug_21465_test.rb +6 -6
- data/test/acceptance/bug_21563_test.rb +5 -5
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +17 -17
- data/test/acceptance/failure_messages_test.rb +13 -13
- data/test/acceptance/minitest_test.rb +39 -39
- data/test/acceptance/mocha_example_test.rb +26 -26
- data/test/acceptance/mocha_test_result_test.rb +13 -13
- data/test/acceptance/mock_test.rb +5 -5
- data/test/acceptance/mock_with_initializer_block_test.rb +5 -5
- data/test/acceptance/mocked_methods_dispatch_test.rb +4 -4
- data/test/acceptance/multiple_expectations_failure_message_test.rb +2 -2
- data/test/acceptance/optional_parameters_test.rb +5 -5
- data/test/acceptance/parameter_matcher_test.rb +18 -18
- data/test/acceptance/partial_mocks_test.rb +9 -9
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +5 -5
- data/test/acceptance/sequence_test.rb +29 -29
- data/test/acceptance/states_test.rb +17 -17
- data/test/acceptance/stub_any_instance_method_test.rb +13 -13
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +7 -7
- data/test/acceptance/stub_everything_test.rb +5 -5
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +17 -17
- data/test/acceptance/stub_test.rb +5 -5
- data/test/acceptance/stubba_example_test.rb +24 -24
- data/test/acceptance/stubba_test_result_test.rb +11 -11
- data/test/acceptance/stubbing_error_backtrace_test.rb +6 -6
- data/test/acceptance/stubbing_frozen_object_test.rb +88 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +9 -9
- data/test/acceptance/stubbing_nil_test.rb +59 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +15 -15
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +14 -14
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +13 -13
- data/test/acceptance/stubbing_non_public_class_method_test.rb +12 -12
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +12 -12
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +9 -9
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +35 -0
- data/test/acceptance/throw_test.rb +1 -1
- data/test/deprecation_disabler.rb +1 -1
- data/test/execution_point.rb +7 -7
- data/test/method_definer.rb +1 -1
- data/test/mini_test_result.rb +21 -21
- data/test/simple_counter.rb +5 -5
- data/test/test_helper.rb +1 -1
- data/test/test_runner.rb +22 -24
- data/test/test_unit_result.rb +20 -0
- data/test/unit/any_instance_method_test.rb +28 -32
- data/test/unit/array_inspect_test.rb +3 -3
- data/test/unit/backtrace_filter_test.rb +3 -3
- data/test/unit/cardinality_test.rb +12 -12
- data/test/unit/central_test.rb +18 -18
- data/test/unit/change_state_side_effect_test.rb +12 -12
- data/test/unit/class_method_test.rb +33 -91
- data/test/unit/date_time_inspect_test.rb +4 -4
- data/test/unit/exception_raiser_test.rb +5 -5
- data/test/unit/expectation_list_test.rb +7 -7
- data/test/unit/expectation_test.rb +66 -66
- data/test/unit/hash_inspect_test.rb +4 -4
- data/test/unit/in_state_ordering_constraint_test.rb +13 -13
- data/test/unit/method_matcher_test.rb +3 -3
- data/test/unit/mock_test.rb +40 -40
- data/test/unit/mockery_test.rb +25 -25
- data/test/unit/multiple_yields_test.rb +2 -2
- data/test/unit/no_yields_test.rb +2 -2
- data/test/unit/object_inspect_test.rb +4 -4
- data/test/unit/object_test.rb +15 -15
- data/test/unit/parameter_matchers/all_of_test.rb +6 -6
- data/test/unit/parameter_matchers/any_of_test.rb +6 -6
- data/test/unit/parameter_matchers/anything_test.rb +5 -5
- data/test/unit/parameter_matchers/has_entries_test.rb +10 -10
- data/test/unit/parameter_matchers/has_entry_test.rb +13 -13
- data/test/unit/parameter_matchers/has_key_test.rb +11 -11
- data/test/unit/parameter_matchers/has_value_test.rb +12 -12
- data/test/unit/parameter_matchers/includes_test.rb +4 -4
- data/test/unit/parameter_matchers/not_test.rb +6 -6
- data/test/unit/parameter_matchers/regexp_matches_test.rb +9 -9
- data/test/unit/parameter_matchers/responds_with_test.rb +6 -6
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -4
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +6 -6
- data/test/unit/parameters_matcher_test.rb +16 -16
- data/test/unit/return_values_test.rb +5 -5
- data/test/unit/sequence_test.rb +10 -10
- data/test/unit/single_return_value_test.rb +3 -3
- data/test/unit/single_yield_test.rb +2 -2
- data/test/unit/state_machine_test.rb +19 -19
- data/test/unit/string_inspect_test.rb +2 -2
- data/test/unit/thrower_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +11 -11
- metadata +113 -101
@@ -3,17 +3,17 @@ require 'mocha'
|
|
3
3
|
require 'execution_point'
|
4
4
|
|
5
5
|
class StubbaTestResultTest < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
include AcceptanceTest
|
8
|
-
|
8
|
+
|
9
9
|
def setup
|
10
10
|
setup_acceptance_test
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def teardown
|
14
14
|
teardown_acceptance_test
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_should_include_expectation_verification_in_assertion_count
|
18
18
|
test_result = run_as_test do
|
19
19
|
object = Class.new { def message; end }.new
|
@@ -22,14 +22,14 @@ class StubbaTestResultTest < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
assert_equal 1, test_result.assertion_count
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_should_include_assertions_in_assertion_count
|
27
27
|
test_result = run_as_test do
|
28
28
|
assert true
|
29
29
|
end
|
30
30
|
assert_equal 1, test_result.assertion_count
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
34
34
|
test_result = run_as_test do
|
35
35
|
object = Class.new { def message; end }.new
|
@@ -38,7 +38,7 @@ class StubbaTestResultTest < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
assert_equal 0, test_result.assertion_count
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def test_should_include_expectation_verification_failure_in_failure_count
|
43
43
|
test_result = run_as_test do
|
44
44
|
object = Class.new { def message; end }.new
|
@@ -46,14 +46,14 @@ class StubbaTestResultTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
assert_equal 1, test_result.failure_count
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_should_include_assertion_failure_in_failure_count
|
51
51
|
test_result = run_as_test do
|
52
52
|
flunk
|
53
53
|
end
|
54
54
|
assert_equal 1, test_result.failure_count
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
58
58
|
execution_point = nil
|
59
59
|
test_result = run_as_test do
|
@@ -62,5 +62,5 @@ class StubbaTestResultTest < Test::Unit::TestCase
|
|
62
62
|
assert_equal 1, test_result.failure_count
|
63
63
|
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
64
64
|
end
|
65
|
-
|
66
|
-
end
|
65
|
+
|
66
|
+
end
|
@@ -3,17 +3,17 @@ require 'mocha'
|
|
3
3
|
require 'execution_point'
|
4
4
|
|
5
5
|
class StubbingErrorBacktraceTest < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
include AcceptanceTest
|
8
|
-
|
8
|
+
|
9
9
|
def setup
|
10
10
|
setup_acceptance_test
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def teardown
|
14
14
|
teardown_acceptance_test
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made
|
18
18
|
execution_point = nil
|
19
19
|
object = Object.new
|
@@ -24,7 +24,7 @@ class StubbingErrorBacktraceTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal 1, test_result.error_count
|
25
25
|
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_public_method_was_made
|
29
29
|
execution_point = nil
|
30
30
|
object = Class.new do
|
@@ -60,5 +60,5 @@ class StubbingErrorBacktraceTest < Test::Unit::TestCase
|
|
60
60
|
assert_equal 1, test_result.error_count
|
61
61
|
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
+
require 'mocha'
|
3
|
+
require 'execution_point'
|
4
|
+
|
5
|
+
class StubbingFrozenObjectTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include AcceptanceTest
|
8
|
+
|
9
|
+
def setup
|
10
|
+
setup_acceptance_test
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
teardown_acceptance_test
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_fail_fast_if_attempting_to_stub_method_on_frozen_object
|
18
|
+
object = Object.new
|
19
|
+
object.freeze
|
20
|
+
execution_point = nil
|
21
|
+
test_result = run_as_test do
|
22
|
+
execution_point = ExecutionPoint.current; object.stubs(:stubbed_method)
|
23
|
+
end
|
24
|
+
assert_failed(test_result)
|
25
|
+
assert_equal 1, test_result.error_count
|
26
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_fail_fast_if_attempting_to_expect_method_on_frozen_object
|
30
|
+
object = Object.new
|
31
|
+
object.freeze
|
32
|
+
execution_point = nil
|
33
|
+
test_result = run_as_test do
|
34
|
+
execution_point = ExecutionPoint.current; object.expects(:stubbed_method)
|
35
|
+
end
|
36
|
+
assert_failed(test_result)
|
37
|
+
assert_equal 1, test_result.error_count
|
38
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_fail_fast_if_attempting_to_stub_method_on_frozen_class
|
42
|
+
klass = Class.new
|
43
|
+
klass.freeze
|
44
|
+
execution_point = nil
|
45
|
+
test_result = run_as_test do
|
46
|
+
execution_point = ExecutionPoint.current; klass.stubs(:stubbed_method)
|
47
|
+
end
|
48
|
+
assert_failed(test_result)
|
49
|
+
assert_equal 1, test_result.error_count
|
50
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_fail_fast_if_attempting_to_expect_method_on_frozen_class
|
54
|
+
klass = Class.new
|
55
|
+
klass.freeze
|
56
|
+
execution_point = nil
|
57
|
+
test_result = run_as_test do
|
58
|
+
execution_point = ExecutionPoint.current; klass.expects(:stubbed_method)
|
59
|
+
end
|
60
|
+
assert_failed(test_result)
|
61
|
+
assert_equal 1, test_result.error_count
|
62
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_fail_fast_if_attempting_to_stub_method_on_any_instance_of_frozen_class
|
66
|
+
klass = Class.new
|
67
|
+
klass.freeze
|
68
|
+
execution_point = nil
|
69
|
+
test_result = run_as_test do
|
70
|
+
execution_point = ExecutionPoint.current; klass.any_instance.stubs(:stubbed_method)
|
71
|
+
end
|
72
|
+
assert_failed(test_result)
|
73
|
+
assert_equal 1, test_result.error_count
|
74
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_should_fail_fast_if_attempting_to_expect_method_on_any_instance_of_frozen_class
|
78
|
+
klass = Class.new
|
79
|
+
klass.freeze
|
80
|
+
execution_point = nil
|
81
|
+
test_result = run_as_test do
|
82
|
+
execution_point = ExecutionPoint.current; klass.any_instance.expects(:stubbed_method)
|
83
|
+
end
|
84
|
+
assert_failed(test_result)
|
85
|
+
assert_equal 1, test_result.error_count
|
86
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
|
87
|
+
end
|
88
|
+
end
|
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
include AcceptanceTest
|
7
|
-
|
7
|
+
|
8
8
|
def setup
|
9
9
|
setup_acceptance_test
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def teardown
|
13
13
|
teardown_acceptance_test
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_should_allow_stubbing_method_unnecessarily
|
17
17
|
Mocha::Configuration.allow(:stubbing_method_unnecessarily)
|
18
18
|
test_result = run_as_test do
|
@@ -22,7 +22,7 @@ class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
|
22
22
|
assert_passed(test_result)
|
23
23
|
assert !@logger.warnings.include?('stubbing method unnecessarily: #<Mock:mock>.public_method(any_parameters)')
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_should_warn_when_stubbing_method_unnecessarily
|
27
27
|
Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
|
28
28
|
test_result = run_as_test do
|
@@ -32,7 +32,7 @@ class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
|
32
32
|
assert_passed(test_result)
|
33
33
|
assert @logger.warnings.include?('stubbing method unnecessarily: #<Mock:mock>.public_method(any_parameters)')
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_should_prevent_stubbing_method_unnecessarily
|
37
37
|
Mocha::Configuration.prevent(:stubbing_method_unnecessarily)
|
38
38
|
test_result = run_as_test do
|
@@ -42,7 +42,7 @@ class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
|
42
42
|
assert_failed(test_result)
|
43
43
|
assert test_result.error_messages.include?('Mocha::StubbingError: stubbing method unnecessarily: #<Mock:mock>.public_method(any_parameters)')
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_should_default_to_allow_stubbing_method_unnecessarily
|
47
47
|
test_result = run_as_test do
|
48
48
|
mock = mock('mock')
|
@@ -51,7 +51,7 @@ class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
|
51
51
|
assert_passed(test_result)
|
52
52
|
assert !@logger.warnings.include?('stubbing method unnecessarily: #<Mock:mock>.public_method(any_parameters)')
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_should_allow_stubbing_method_when_stubbed_method_is_invoked
|
56
56
|
Mocha::Configuration.prevent(:stubbing_method_unnecessarily)
|
57
57
|
test_result = run_as_test do
|
@@ -62,4 +62,4 @@ class StubbingMethodUnnecessarilyTest < Test::Unit::TestCase
|
|
62
62
|
assert_passed(test_result)
|
63
63
|
end
|
64
64
|
|
65
|
-
end
|
65
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
class StubbingNilTest < 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_allow_stubbing_method_on_nil
|
17
|
+
Mocha::Configuration.allow(:stubbing_method_on_nil)
|
18
|
+
test_result = run_as_test do
|
19
|
+
nil.stubs(:stubbed_method)
|
20
|
+
end
|
21
|
+
assert_passed(test_result)
|
22
|
+
assert !@logger.warnings.include?("stubbing method on nil: nil.stubbed_method")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_warn_on_stubbing_method_on_nil
|
26
|
+
Mocha::Configuration.warn_when(:stubbing_method_on_nil)
|
27
|
+
test_result = run_as_test do
|
28
|
+
nil.stubs(:stubbed_method)
|
29
|
+
end
|
30
|
+
assert_passed(test_result)
|
31
|
+
assert @logger.warnings.include?("stubbing method on nil: nil.stubbed_method")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_prevent_stubbing_method_on_nil
|
35
|
+
Mocha::Configuration.prevent(:stubbing_method_on_nil)
|
36
|
+
test_result = run_as_test do
|
37
|
+
nil.stubs(:stubbed_method)
|
38
|
+
end
|
39
|
+
assert_failed(test_result)
|
40
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_default_to_prevent_stubbing_method_on_non_mock_object
|
44
|
+
test_result = run_as_test do
|
45
|
+
nil.stubs(:stubbed_method)
|
46
|
+
end
|
47
|
+
assert_failed(test_result)
|
48
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on nil: nil.stubbed_method")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_allow_stubbing_method_on_non_nil_object
|
52
|
+
Mocha::Configuration.prevent(:stubbing_method_on_nil)
|
53
|
+
object = Object.new
|
54
|
+
test_result = run_as_test do
|
55
|
+
object.stubs(:stubbed_method)
|
56
|
+
end
|
57
|
+
assert_passed(test_result)
|
58
|
+
end
|
59
|
+
end
|
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
include AcceptanceTest
|
7
|
-
|
7
|
+
|
8
8
|
def setup
|
9
9
|
setup_acceptance_test
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def teardown
|
13
13
|
teardown_acceptance_test
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_should_allow_stubbing_non_existent_any_instance_method
|
17
17
|
Mocha::Configuration.allow(:stubbing_non_existent_method)
|
18
18
|
klass = Class.new
|
@@ -22,7 +22,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
22
22
|
assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance.mocha_inspect}.non_existent_method")
|
23
23
|
assert_passed(test_result)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_should_warn_when_stubbing_non_existent_any_instance_method
|
27
27
|
Mocha::Configuration.warn_when(:stubbing_non_existent_method)
|
28
28
|
klass = Class.new
|
@@ -32,7 +32,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
32
32
|
assert_passed(test_result)
|
33
33
|
assert @logger.warnings.include?("stubbing non-existent method: #{klass.any_instance.mocha_inspect}.non_existent_method")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_should_prevent_stubbing_non_existent_any_instance_method
|
37
37
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
38
38
|
klass = Class.new
|
@@ -42,7 +42,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
42
42
|
assert_failed(test_result)
|
43
43
|
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass.any_instance.mocha_inspect}.non_existent_method")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_should_default_to_allow_stubbing_non_existent_any_instance_method
|
47
47
|
klass = Class.new
|
48
48
|
test_result = run_as_test do
|
@@ -51,7 +51,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
51
51
|
assert !@logger.warnings.include?("stubbing non-existent method: #{klass.any_instance.mocha_inspect}.non_existent_method")
|
52
52
|
assert_passed(test_result)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_should_allow_stubbing_existing_public_any_instance_method
|
56
56
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
57
57
|
klass = Class.new do
|
@@ -75,7 +75,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
assert_passed(test_result)
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def test_should_allow_stubbing_existing_private_any_instance_method
|
80
80
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
81
81
|
klass = Class.new do
|
@@ -87,7 +87,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
87
87
|
end
|
88
88
|
assert_passed(test_result)
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def test_should_allow_stubbing_existing_public_any_instance_superclass_method
|
92
92
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
93
93
|
superklass = Class.new do
|
@@ -100,7 +100,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
100
100
|
end
|
101
101
|
assert_passed(test_result)
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
def test_should_allow_stubbing_existing_protected_any_instance_superclass_method
|
105
105
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
106
106
|
superklass = Class.new do
|
@@ -113,7 +113,7 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
113
113
|
end
|
114
114
|
assert_passed(test_result)
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def test_should_allow_stubbing_existing_private_any_instance_superclass_method
|
118
118
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
119
119
|
superklass = Class.new do
|
@@ -126,5 +126,5 @@ class StubbingNonExistentAnyInstanceMethodTest < Test::Unit::TestCase
|
|
126
126
|
end
|
127
127
|
assert_passed(test_result)
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
end
|
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
include AcceptanceTest
|
7
|
-
|
7
|
+
|
8
8
|
def setup
|
9
9
|
setup_acceptance_test
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def teardown
|
13
13
|
teardown_acceptance_test
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def test_should_allow_stubbing_non_existent_class_method
|
17
17
|
Mocha::Configuration.allow(:stubbing_non_existent_method)
|
18
18
|
klass = Class.new
|
@@ -22,7 +22,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
22
22
|
assert !@logger.warnings.include?("stubbing non-existent method: #{klass.mocha_inspect}.non_existent_method")
|
23
23
|
assert_passed(test_result)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_should_warn_when_stubbing_non_existent_class_method
|
27
27
|
Mocha::Configuration.warn_when(:stubbing_non_existent_method)
|
28
28
|
klass = Class.new
|
@@ -32,7 +32,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
32
32
|
assert_passed(test_result)
|
33
33
|
assert @logger.warnings.include?("stubbing non-existent method: #{klass.mocha_inspect}.non_existent_method")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_should_prevent_stubbing_non_existent_class_method
|
37
37
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
38
38
|
klass = Class.new
|
@@ -42,7 +42,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
42
42
|
assert_failed(test_result)
|
43
43
|
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-existent method: #{klass.mocha_inspect}.non_existent_method")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_should_default_to_allow_stubbing_non_existent_class_method
|
47
47
|
klass = Class.new
|
48
48
|
test_result = run_as_test do
|
@@ -51,7 +51,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
51
51
|
assert !@logger.warnings.include?("stubbing non-existent method: #{klass.mocha_inspect}.non_existent_method")
|
52
52
|
assert_passed(test_result)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_should_allow_stubbing_existing_public_class_method
|
56
56
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
57
57
|
klass = Class.new do
|
@@ -65,7 +65,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
assert_passed(test_result)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_should_allow_stubbing_method_to_which_class_responds
|
70
70
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
71
71
|
klass = Class.new do
|
@@ -80,7 +80,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
80
80
|
end
|
81
81
|
assert_passed(test_result)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def test_should_allow_stubbing_existing_protected_class_method
|
85
85
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
86
86
|
klass = Class.new do
|
@@ -94,7 +94,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
94
94
|
end
|
95
95
|
assert_passed(test_result)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def test_should_allow_stubbing_existing_private_class_method
|
99
99
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
100
100
|
klass = Class.new do
|
@@ -108,7 +108,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
108
108
|
end
|
109
109
|
assert_passed(test_result)
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def test_should_allow_stubbing_existing_public_superclass_method
|
113
113
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
114
114
|
superklass = Class.new do
|
@@ -123,7 +123,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
123
123
|
end
|
124
124
|
assert_passed(test_result)
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
def test_should_allow_stubbing_existing_protected_superclass_method
|
128
128
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
129
129
|
superklass = Class.new do
|
@@ -138,7 +138,7 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
138
138
|
end
|
139
139
|
assert_passed(test_result)
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def test_should_allow_stubbing_existing_private_superclass_method
|
143
143
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
144
144
|
superklass = Class.new do
|
@@ -153,5 +153,5 @@ class StubbingNonExistentClassMethodTest < Test::Unit::TestCase
|
|
153
153
|
end
|
154
154
|
assert_passed(test_result)
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
end
|