mocha 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +58 -0
- data/.rubocop_todo.yml +50 -0
- data/RELEASE.md +7 -0
- data/Rakefile +35 -28
- data/bin/build-matrix +17 -18
- data/lib/mocha/any_instance_method.rb +19 -25
- data/lib/mocha/api.rb +1 -5
- data/lib/mocha/argument_iterator.rb +4 -8
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/cardinality.rb +20 -27
- data/lib/mocha/central.rb +7 -15
- data/lib/mocha/change_state_side_effect.rb +0 -4
- data/lib/mocha/class_method.rb +31 -37
- data/lib/mocha/class_methods.rb +5 -13
- data/lib/mocha/configuration.rb +3 -9
- data/lib/mocha/debug.rb +3 -2
- data/lib/mocha/deprecation.rb +4 -11
- data/lib/mocha/detection/mini_test.rb +0 -2
- data/lib/mocha/detection/test_unit.rb +4 -4
- data/lib/mocha/error_with_filtered_backtrace.rb +0 -4
- data/lib/mocha/exception_raiser.rb +2 -5
- data/lib/mocha/expectation.rb +15 -18
- data/lib/mocha/expectation_error.rb +2 -0
- data/lib/mocha/expectation_error_factory.rb +0 -1
- data/lib/mocha/expectation_list.rb +2 -6
- data/lib/mocha/hooks.rb +0 -1
- data/lib/mocha/in_state_ordering_constraint.rb +0 -4
- data/lib/mocha/inspect.rb +3 -5
- data/lib/mocha/instance_method.rb +0 -2
- data/lib/mocha/integration.rb +3 -4
- data/lib/mocha/integration/mini_test/adapter.rb +2 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
- data/lib/mocha/integration/mini_test/nothing.rb +4 -4
- data/lib/mocha/integration/mini_test/version_13.rb +3 -1
- data/lib/mocha/integration/mini_test/version_140.rb +3 -1
- data/lib/mocha/integration/mini_test/version_141.rb +3 -1
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +3 -1
- data/lib/mocha/integration/mini_test/version_200.rb +3 -1
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +3 -1
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +3 -1
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +3 -1
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +3 -1
- data/lib/mocha/integration/monkey_patcher.rb +5 -7
- data/lib/mocha/integration/test_unit/adapter.rb +5 -6
- data/lib/mocha/integration/test_unit/gem_version_200.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +4 -2
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +4 -2
- data/lib/mocha/integration/test_unit/nothing.rb +4 -4
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -1
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -1
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +0 -4
- data/lib/mocha/method_matcher.rb +1 -5
- data/lib/mocha/minitest.rb +1 -1
- data/lib/mocha/mock.rb +25 -30
- data/lib/mocha/mockery.rb +27 -43
- data/lib/mocha/module_method.rb +0 -2
- data/lib/mocha/module_methods.rb +0 -4
- data/lib/mocha/multiple_yields.rb +0 -5
- data/lib/mocha/names.rb +1 -11
- data/lib/mocha/no_yields.rb +1 -7
- data/lib/mocha/not_initialized_error.rb +0 -2
- data/lib/mocha/object_methods.rb +10 -14
- data/lib/mocha/parameter_matchers.rb +0 -2
- data/lib/mocha/parameter_matchers/all_of.rb +1 -7
- data/lib/mocha/parameter_matchers/any_of.rb +1 -7
- data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
- data/lib/mocha/parameter_matchers/anything.rb +2 -8
- data/lib/mocha/parameter_matchers/base.rb +6 -12
- data/lib/mocha/parameter_matchers/equals.rb +0 -6
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +6 -6
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -6
- data/lib/mocha/parameter_matchers/has_entry.rb +8 -11
- data/lib/mocha/parameter_matchers/has_key.rb +2 -6
- data/lib/mocha/parameter_matchers/has_value.rb +2 -6
- data/lib/mocha/parameter_matchers/includes.rb +2 -6
- data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
- data/lib/mocha/parameter_matchers/is_a.rb +2 -6
- data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
- data/lib/mocha/parameter_matchers/not.rb +2 -6
- data/lib/mocha/parameter_matchers/object.rb +0 -2
- data/lib/mocha/parameter_matchers/optionally.rb +4 -10
- data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
- data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
- data/lib/mocha/parameters_matcher.rb +6 -9
- data/lib/mocha/pretty_parameters.rb +0 -4
- data/lib/mocha/receivers.rb +6 -12
- data/lib/mocha/return_values.rb +3 -7
- data/lib/mocha/sequence.rb +4 -9
- data/lib/mocha/single_return_value.rb +0 -4
- data/lib/mocha/single_yield.rb +0 -5
- data/lib/mocha/state_machine.rb +6 -10
- data/lib/mocha/stubbing_error.rb +0 -2
- data/lib/mocha/test_unit.rb +1 -1
- data/lib/mocha/thrower.rb +2 -5
- data/lib/mocha/unexpected_invocation.rb +3 -5
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +3 -7
- data/mocha.gemspec +34 -58
- data/test/acceptance/acceptance_test_helper.rb +0 -4
- data/test/acceptance/bug_18914_test.rb +7 -12
- data/test/acceptance/bug_21465_test.rb +0 -2
- data/test/acceptance/bug_21563_test.rb +0 -2
- data/test/acceptance/exception_rescue_test.rb +7 -8
- data/test/acceptance/expectations_on_multiple_methods_test.rb +2 -1
- data/test/acceptance/expected_invocation_count_test.rb +27 -29
- data/test/acceptance/failure_messages_test.rb +3 -5
- data/test/acceptance/issue_272_test.rb +0 -1
- data/test/acceptance/issue_65_test.rb +15 -13
- data/test/acceptance/issue_70_test.rb +0 -1
- data/test/acceptance/mocha_example_test.rb +5 -6
- data/test/acceptance/mocha_test_result_test.rb +7 -7
- data/test/acceptance/mock_test.rb +2 -4
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -2
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -2
- data/test/acceptance/multiple_expectations_failure_message_test.rb +16 -17
- data/test/acceptance/optional_parameters_test.rb +0 -2
- data/test/acceptance/parameter_matcher_test.rb +2 -3
- data/test/acceptance/partial_mocks_test.rb +4 -6
- data/test/acceptance/prepend_test.rb +14 -16
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -2
- data/test/acceptance/raise_exception_test.rb +2 -4
- data/test/acceptance/return_value_test.rb +0 -2
- data/test/acceptance/sequence_test.rb +9 -11
- data/test/acceptance/states_test.rb +6 -4
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +5 -4
- data/test/acceptance/stub_any_instance_method_test.rb +19 -17
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +8 -8
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +2 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +7 -4
- data/test/acceptance/stub_everything_test.rb +1 -3
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +6 -7
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +2 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -2
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
- data/test/acceptance/stub_module_method_test.rb +13 -13
- data/test/acceptance/stub_test.rb +1 -3
- data/test/acceptance/stubba_example_test.rb +6 -14
- data/test/acceptance/stubba_test_result_test.rb +5 -8
- data/test/acceptance/stubbing_error_backtrace_test.rb +2 -2
- data/test/acceptance/stubbing_frozen_object_test.rb +2 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +12 -7
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -2
- data/test/acceptance/stubbing_nil_test.rb +4 -5
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +3 -3
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -2
- data/test/acceptance/stubbing_non_public_class_method_test.rb +3 -3
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -3
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +4 -10
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -4
- data/test/acceptance/throw_test.rb +0 -2
- data/test/acceptance/unexpected_invocation_test.rb +2 -3
- data/test/acceptance/unstubbing_test.rb +41 -14
- data/test/deprecation_disabler.rb +0 -1
- data/test/execution_point.rb +2 -4
- data/test/integration/mini_test_test.rb +2 -2
- data/test/integration/shared_tests.rb +24 -22
- data/test/integration/test_unit_test.rb +2 -2
- data/test/method_definer.rb +1 -3
- data/test/mini_test_result.rb +17 -11
- data/test/minitest_result.rb +0 -1
- data/test/simple_counter.rb +0 -2
- data/test/test_helper.rb +13 -5
- data/test/test_runner.rb +2 -4
- data/test/test_unit_result.rb +4 -2
- data/test/unit/any_instance_method_test.rb +31 -17
- data/test/unit/array_inspect_test.rb +2 -4
- data/test/unit/backtrace_filter_test.rb +3 -5
- data/test/unit/cardinality_test.rb +0 -2
- data/test/unit/central_test.rb +26 -27
- data/test/unit/change_state_side_effect_test.rb +0 -4
- data/test/unit/class_method_test.rb +59 -34
- data/test/unit/class_methods_test.rb +9 -11
- data/test/unit/configuration_test.rb +1 -2
- data/test/unit/date_time_inspect_test.rb +1 -3
- data/test/unit/exception_raiser_test.rb +0 -2
- data/test/unit/expectation_list_test.rb +0 -2
- data/test/unit/expectation_test.rb +41 -46
- data/test/unit/hash_inspect_test.rb +3 -5
- data/test/unit/hooks_test.rb +9 -4
- data/test/unit/in_state_ordering_constraint_test.rb +0 -4
- data/test/unit/method_matcher_test.rb +1 -3
- data/test/unit/mock_test.rb +35 -22
- data/test/unit/mockery_test.rb +28 -26
- data/test/unit/module_methods_test.rb +0 -2
- data/test/unit/multiple_yields_test.rb +0 -2
- data/test/unit/no_yields_test.rb +0 -2
- data/test/unit/object_inspect_test.rb +16 -7
- data/test/unit/object_methods_test.rb +6 -8
- data/test/unit/parameter_matchers/all_of_test.rb +0 -2
- data/test/unit/parameter_matchers/any_of_test.rb +0 -2
- data/test/unit/parameter_matchers/anything_test.rb +2 -4
- data/test/unit/parameter_matchers/equals_test.rb +1 -3
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -1
- data/test/unit/parameter_matchers/has_entries_test.rb +2 -2
- data/test/unit/parameter_matchers/has_entry_test.rb +13 -14
- data/test/unit/parameter_matchers/has_key_test.rb +0 -1
- data/test/unit/parameter_matchers/has_value_test.rb +0 -2
- data/test/unit/parameter_matchers/includes_test.rb +8 -9
- data/test/unit/parameter_matchers/instance_of_test.rb +1 -3
- data/test/unit/parameter_matchers/is_a_test.rb +1 -3
- data/test/unit/parameter_matchers/kind_of_test.rb +1 -3
- data/test/unit/parameter_matchers/not_test.rb +0 -2
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -2
- data/test/unit/parameter_matchers/responds_with_test.rb +9 -3
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -4
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -3
- data/test/unit/parameters_matcher_test.rb +2 -4
- data/test/unit/receivers_test.rb +8 -6
- data/test/unit/return_values_test.rb +3 -5
- data/test/unit/sequence_test.rb +1 -5
- data/test/unit/single_return_value_test.rb +0 -2
- data/test/unit/single_yield_test.rb +0 -2
- data/test/unit/state_machine_test.rb +1 -3
- data/test/unit/string_inspect_test.rb +2 -4
- data/test/unit/thrower_test.rb +0 -2
- data/test/unit/yield_parameters_test.rb +0 -2
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +22 -6
@@ -2,15 +2,13 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/inspect'
|
3
3
|
|
4
4
|
class ArrayInspectTest < Mocha::TestCase
|
5
|
-
|
6
5
|
def test_should_use_inspect
|
7
6
|
array = [1, 2]
|
8
7
|
assert_equal array.inspect, array.mocha_inspect
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_should_use_mocha_inspect_on_each_item
|
12
|
-
array = [1, 2,
|
13
|
-
assert_equal %
|
11
|
+
array = [1, 2, 'chris']
|
12
|
+
assert_equal %([1, 2, "chris"]), array.mocha_inspect
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
@@ -2,18 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/backtrace_filter'
|
3
3
|
|
4
4
|
class BacktraceFilterTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include Mocha
|
7
6
|
|
8
7
|
def test_should_exclude_mocha_locations_from_backtrace
|
9
|
-
mocha_lib =
|
10
|
-
backtrace = [
|
8
|
+
mocha_lib = '/username/workspace/mocha_wibble/lib/'
|
9
|
+
backtrace = [mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3']
|
11
10
|
filter = BacktraceFilter.new(mocha_lib)
|
12
11
|
assert_equal ['/keep/me'], filter.filtered(backtrace)
|
13
12
|
end
|
14
13
|
|
15
14
|
def test_should_determine_path_for_mocha_lib_directory
|
16
|
-
assert_match Regexp.new(
|
15
|
+
assert_match Regexp.new('/lib/$'), BacktraceFilter::LIB_DIRECTORY
|
17
16
|
end
|
18
|
-
|
19
17
|
end
|
@@ -2,7 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/cardinality'
|
3
3
|
|
4
4
|
class CardinalityTest < Mocha::TestCase
|
5
|
-
|
6
5
|
include Mocha
|
7
6
|
|
8
7
|
def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum
|
@@ -52,5 +51,4 @@ class CardinalityTest < Mocha::TestCase
|
|
52
51
|
def test_should_not_need_verifying
|
53
52
|
assert_equal false, Cardinality.at_least(0).needs_verifying?
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
data/test/unit/central_test.rb
CHANGED
@@ -5,7 +5,6 @@ require 'mocha/mock'
|
|
5
5
|
require 'method_definer'
|
6
6
|
|
7
7
|
class CentralTest < Mocha::TestCase
|
8
|
-
|
9
8
|
include Mocha
|
10
9
|
|
11
10
|
def test_should_start_with_empty_stubba_methods
|
@@ -48,48 +47,48 @@ class CentralTest < Mocha::TestCase
|
|
48
47
|
|
49
48
|
def test_should_unstub_specified_method
|
50
49
|
stubba = Central.new
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
stubba.stubba_methods = [
|
50
|
+
method1 = build_mock
|
51
|
+
method1.stubs(:matches?).returns(false)
|
52
|
+
method2 = build_mock
|
53
|
+
method2.stubs(:matches?).returns(true)
|
54
|
+
method2.expects(:unstub)
|
55
|
+
stubba.stubba_methods = [method1, method2]
|
57
56
|
|
58
|
-
stubba.unstub(
|
57
|
+
stubba.unstub(method2)
|
59
58
|
|
60
|
-
assert_equal [
|
61
|
-
assert
|
59
|
+
assert_equal [method1], stubba.stubba_methods
|
60
|
+
assert method2.__verified__?
|
62
61
|
end
|
63
62
|
|
64
63
|
def test_should_not_unstub_specified_method_if_not_already_stubbed
|
65
64
|
stubba = Central.new
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
stubba.stubba_methods = [
|
65
|
+
method1 = build_mock
|
66
|
+
method1.stubs(:matches?).returns(false)
|
67
|
+
method2 = build_mock
|
68
|
+
method2.expects(:unstub).never
|
69
|
+
stubba.stubba_methods = [method1]
|
71
70
|
|
72
|
-
stubba.unstub(
|
71
|
+
stubba.unstub(method2)
|
73
72
|
|
74
|
-
assert_equal [
|
75
|
-
assert
|
73
|
+
assert_equal [method1], stubba.stubba_methods
|
74
|
+
assert method2.__verified__?
|
76
75
|
end
|
77
76
|
|
78
77
|
def test_should_unstub_all_methods
|
79
78
|
stubba = Central.new
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
stubba.stubba_methods = [
|
79
|
+
method1 = build_mock
|
80
|
+
method1.stubs(:matches?).returns(true)
|
81
|
+
method1.expects(:unstub)
|
82
|
+
method2 = build_mock
|
83
|
+
method2.stubs(:matches?).returns(true)
|
84
|
+
method2.expects(:unstub)
|
85
|
+
stubba.stubba_methods = [method1, method2]
|
87
86
|
|
88
87
|
stubba.unstub_all
|
89
88
|
|
90
89
|
assert_equal [], stubba.stubba_methods
|
91
|
-
assert
|
92
|
-
assert
|
90
|
+
assert method1.__verified__?
|
91
|
+
assert method2.__verified__?
|
93
92
|
end
|
94
93
|
|
95
94
|
private
|
@@ -3,11 +3,9 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
3
3
|
require 'mocha/change_state_side_effect'
|
4
4
|
|
5
5
|
class ChangeStateSideEffectTest < Mocha::TestCase
|
6
|
-
|
7
6
|
include Mocha
|
8
7
|
|
9
8
|
class FakeState
|
10
|
-
|
11
9
|
attr_reader :active
|
12
10
|
attr_writer :description
|
13
11
|
|
@@ -18,7 +16,6 @@ class ChangeStateSideEffectTest < Mocha::TestCase
|
|
18
16
|
def mocha_inspect
|
19
17
|
@description
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
|
24
21
|
def test_should_activate_the_given_state
|
@@ -37,5 +34,4 @@ class ChangeStateSideEffectTest < Mocha::TestCase
|
|
37
34
|
|
38
35
|
assert_equal 'then the-new-state', side_effect.mocha_inspect
|
39
36
|
end
|
40
|
-
|
41
37
|
end
|
@@ -5,20 +5,19 @@ require 'mocha/mock'
|
|
5
5
|
require 'mocha/class_method'
|
6
6
|
|
7
7
|
class ClassMethodTest < Mocha::TestCase
|
8
|
-
|
9
8
|
include Mocha
|
10
9
|
|
11
|
-
unless RUBY_V2_PLUS
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
unless RUBY_V2_PLUS
|
11
|
+
def test_should_hide_original_method
|
12
|
+
klass = Class.new { def self.method_x; end }
|
13
|
+
klass.__metaclass__.send(:alias_method, :_method, :method)
|
14
|
+
method = ClassMethod.new(klass, :method_x)
|
16
15
|
|
17
|
-
|
16
|
+
method.hide_original_method
|
18
17
|
|
19
|
-
|
18
|
+
assert_equal false, klass.respond_to?(:method_x)
|
19
|
+
end
|
20
20
|
end
|
21
|
-
end
|
22
21
|
|
23
22
|
def test_should_not_raise_error_hiding_method_that_isnt_defined
|
24
23
|
klass = Class.new
|
@@ -59,7 +58,11 @@ end
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def test_should_restore_original_method
|
62
|
-
klass = Class.new
|
61
|
+
klass = Class.new do
|
62
|
+
def self.method_x
|
63
|
+
:original_result
|
64
|
+
end
|
65
|
+
end
|
63
66
|
klass.__metaclass__.send(:alias_method, :_method, :method)
|
64
67
|
method = ClassMethod.new(klass, :method_x)
|
65
68
|
|
@@ -73,7 +76,11 @@ end
|
|
73
76
|
end
|
74
77
|
|
75
78
|
def test_should_restore_original_method_accepting_a_block_parameter
|
76
|
-
klass = Class.new
|
79
|
+
klass = Class.new do
|
80
|
+
def self.method_x(&block)
|
81
|
+
block.call if block_given?
|
82
|
+
end
|
83
|
+
end
|
77
84
|
klass.__metaclass__.send(:alias_method, :_method, :method)
|
78
85
|
method = ClassMethod.new(klass, :method_x)
|
79
86
|
|
@@ -88,7 +95,11 @@ end
|
|
88
95
|
end
|
89
96
|
|
90
97
|
def test_should_not_restore_original_method_if_none_was_defined_in_first_place
|
91
|
-
klass = Class.new
|
98
|
+
klass = Class.new do
|
99
|
+
def self.method_x
|
100
|
+
:new_result
|
101
|
+
end
|
102
|
+
end
|
92
103
|
method = ClassMethod.new(klass, :method_x)
|
93
104
|
|
94
105
|
method.restore_original_method
|
@@ -124,7 +135,7 @@ end
|
|
124
135
|
method = ClassMethod.new(klass, :method_x)
|
125
136
|
mocha = build_mock
|
126
137
|
klass.define_instance_method(:mocha) { mocha }
|
127
|
-
method.replace_instance_method(:reset_mocha) {
|
138
|
+
method.replace_instance_method(:reset_mocha) {}
|
128
139
|
method.define_instance_accessor(:remove_called)
|
129
140
|
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
130
141
|
|
@@ -138,7 +149,7 @@ end
|
|
138
149
|
mocha = build_mock
|
139
150
|
klass.define_instance_method(:mocha) { mocha }
|
140
151
|
method = ClassMethod.new(klass, :method_x)
|
141
|
-
method.replace_instance_method(:reset_mocha) {
|
152
|
+
method.replace_instance_method(:reset_mocha) {}
|
142
153
|
method.define_instance_accessor(:restore_called)
|
143
154
|
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
144
155
|
|
@@ -150,8 +161,15 @@ end
|
|
150
161
|
def test_should_call_mocha_unstub
|
151
162
|
klass = Class.new { def self.method_x; end }
|
152
163
|
method = ClassMethod.new(klass, :method_x)
|
153
|
-
method.replace_instance_method(:restore_original_method) {
|
154
|
-
mocha = Class.new
|
164
|
+
method.replace_instance_method(:restore_original_method) {}
|
165
|
+
mocha = Class.new do
|
166
|
+
class << self
|
167
|
+
attr_accessor :unstub_method
|
168
|
+
end
|
169
|
+
def self.unstub(method)
|
170
|
+
self.unstub_method = method
|
171
|
+
end
|
172
|
+
end
|
155
173
|
mocha.define_instance_method(:any_expectations?) { true }
|
156
174
|
method.replace_instance_method(:mock) { mocha }
|
157
175
|
|
@@ -162,13 +180,18 @@ end
|
|
162
180
|
def test_should_call_stubbee_reset_mocha_if_no_expectations_remaining
|
163
181
|
klass = Class.new { def self.method_x; end }
|
164
182
|
method = ClassMethod.new(klass, :method_x)
|
165
|
-
method.replace_instance_method(:remove_new_method) {
|
166
|
-
method.replace_instance_method(:restore_original_method) {
|
183
|
+
method.replace_instance_method(:remove_new_method) {}
|
184
|
+
method.replace_instance_method(:restore_original_method) {}
|
167
185
|
mocha = Class.new
|
168
186
|
mocha.define_instance_method(:unstub) { |method_name| }
|
169
187
|
mocha.define_instance_method(:any_expectations?) { false }
|
170
188
|
method.replace_instance_method(:mock) { mocha }
|
171
|
-
stubbee = Class.new
|
189
|
+
stubbee = Class.new do
|
190
|
+
attr_accessor :reset_mocha_called
|
191
|
+
def reset_mocha
|
192
|
+
self.reset_mocha_called = true
|
193
|
+
end
|
194
|
+
end.new
|
172
195
|
method.replace_instance_method(:stubbee) { stubbee }
|
173
196
|
|
174
197
|
method.unstub
|
@@ -191,34 +214,36 @@ end
|
|
191
214
|
end
|
192
215
|
|
193
216
|
def test_should_not_match_if_other_class_method_has_different_stubbee
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
assert !
|
217
|
+
stubbee1 = Object.new
|
218
|
+
stubbee2 = Object.new
|
219
|
+
class_method1 = ClassMethod.new(stubbee1, :method)
|
220
|
+
class_method2 = ClassMethod.new(stubbee2, :method)
|
221
|
+
assert !class_method1.matches?(class_method2)
|
199
222
|
end
|
200
223
|
|
201
224
|
def test_should_not_match_if_other_class_method_has_different_method
|
202
225
|
stubbee = Object.new
|
203
|
-
|
204
|
-
|
205
|
-
assert !
|
226
|
+
class_method1 = ClassMethod.new(stubbee, :method_1)
|
227
|
+
class_method2 = ClassMethod.new(stubbee, :method_2)
|
228
|
+
assert !class_method1.matches?(class_method2)
|
206
229
|
end
|
207
230
|
|
208
231
|
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice
|
209
232
|
stubbee = Object.new
|
210
|
-
|
211
|
-
|
212
|
-
assert
|
233
|
+
class_method1 = ClassMethod.new(stubbee, :method)
|
234
|
+
class_method2 = ClassMethod.new(stubbee, :method)
|
235
|
+
assert class_method1.matches?(class_method2)
|
213
236
|
end
|
214
237
|
|
215
238
|
def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy
|
216
239
|
stubbee = Class.new do
|
217
|
-
def equal?(
|
240
|
+
def equal?(_other)
|
241
|
+
false
|
242
|
+
end
|
218
243
|
end.new
|
219
|
-
|
220
|
-
|
221
|
-
assert
|
244
|
+
class_method1 = ClassMethod.new(stubbee, :method)
|
245
|
+
class_method2 = ClassMethod.new(stubbee, :method)
|
246
|
+
assert class_method1.matches?(class_method2)
|
222
247
|
end
|
223
248
|
|
224
249
|
private
|
@@ -5,7 +5,6 @@ require 'mocha/mockery'
|
|
5
5
|
require 'mocha/names'
|
6
6
|
|
7
7
|
class ClassMethodsTest < Mocha::TestCase
|
8
|
-
|
9
8
|
def setup
|
10
9
|
Mocha::Mockery.setup
|
11
10
|
@klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
|
@@ -22,9 +21,9 @@ class ClassMethodsTest < Mocha::TestCase
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def test_should_return_same_any_instance_object
|
25
|
-
|
26
|
-
|
27
|
-
assert_equal
|
24
|
+
any_instance1 = @klass.any_instance
|
25
|
+
any_instance2 = @klass.any_instance
|
26
|
+
assert_equal any_instance1, any_instance2
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_any_instance_should_build_mocha_referring_to_klass
|
@@ -40,15 +39,15 @@ class ClassMethodsTest < Mocha::TestCase
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def test_any_instance_should_reuse_existing_mocha
|
43
|
-
|
44
|
-
|
45
|
-
assert_equal
|
42
|
+
mocha1 = @klass.any_instance.mocha
|
43
|
+
mocha2 = @klass.any_instance.mocha
|
44
|
+
assert_equal mocha1, mocha2
|
46
45
|
end
|
47
46
|
|
48
47
|
def test_any_instance_should_reuse_existing_mocha_even_if_instantiate_is_false
|
49
|
-
|
50
|
-
|
51
|
-
assert_equal
|
48
|
+
mocha1 = @klass.any_instance.mocha
|
49
|
+
mocha2 = @klass.any_instance.mocha(false)
|
50
|
+
assert_equal mocha1, mocha2
|
52
51
|
end
|
53
52
|
|
54
53
|
def test_should_use_stubba_class_method_for_class
|
@@ -67,5 +66,4 @@ class ClassMethodsTest < Mocha::TestCase
|
|
67
66
|
any_instance = @klass.any_instance
|
68
67
|
assert_equal @klass, any_instance.stubba_object
|
69
68
|
end
|
70
|
-
|
71
69
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require
|
2
|
+
require 'mocha/configuration'
|
3
3
|
|
4
4
|
class ConfigurationTest < Mocha::TestCase
|
5
5
|
def test_allow_temporarily_changes_config_when_given_block
|
@@ -35,4 +35,3 @@ class ConfigurationTest < Mocha::TestCase
|
|
35
35
|
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
@@ -2,7 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
require 'mocha/inspect'
|
3
3
|
|
4
4
|
class DateTimeInspectTest < Mocha::TestCase
|
5
|
-
|
6
5
|
def test_should_use_include_date_in_seconds
|
7
6
|
time = Time.now
|
8
7
|
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
@@ -14,8 +13,7 @@ class DateTimeInspectTest < Mocha::TestCase
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_should_use_to_s_for_datetime
|
17
|
-
datetime = DateTime.new(2006, 1, 1)
|
16
|
+
datetime = DateTime.new(2006, 1, 1) # rubocop:disable Style/DateTime
|
18
17
|
assert_equal datetime.to_s, datetime.mocha_inspect
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
@@ -4,7 +4,6 @@ require 'mocha/exception_raiser'
|
|
4
4
|
require 'timeout'
|
5
5
|
|
6
6
|
class ExceptionRaiserTest < Mocha::TestCase
|
7
|
-
|
8
7
|
include Mocha
|
9
8
|
|
10
9
|
def test_should_raise_exception_with_specified_class_and_default_message
|
@@ -38,5 +37,4 @@ class ExceptionRaiserTest < Mocha::TestCase
|
|
38
37
|
raiser = ExceptionRaiser.new(exception_class, nil)
|
39
38
|
assert_raises(exception_class) { raiser.evaluate }
|
40
39
|
end
|
41
|
-
|
42
40
|
end
|
@@ -5,7 +5,6 @@ require 'set'
|
|
5
5
|
require 'method_definer'
|
6
6
|
|
7
7
|
class ExpectationListTest < Mocha::TestCase
|
8
|
-
|
9
8
|
include Mocha
|
10
9
|
|
11
10
|
def test_should_return_added_expectation
|
@@ -78,5 +77,4 @@ class ExpectationListTest < Mocha::TestCase
|
|
78
77
|
expectation_list = expectation_list1 + expectation_list2
|
79
78
|
assert_equal [expectation1, expectation2], expectation_list.to_a
|
80
79
|
end
|
81
|
-
|
82
80
|
end
|
@@ -6,7 +6,6 @@ require 'execution_point'
|
|
6
6
|
require 'simple_counter'
|
7
7
|
|
8
8
|
class ExpectationTest < Mocha::TestCase
|
9
|
-
|
10
9
|
include Mocha
|
11
10
|
|
12
11
|
def new_expectation
|
@@ -18,12 +17,12 @@ class ExpectationTest < Mocha::TestCase
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_should_match_calls_to_same_method_with_exactly_zero_parameters
|
21
|
-
expectation = new_expectation.with
|
20
|
+
expectation = new_expectation.with
|
22
21
|
assert expectation.match?(:expected_method)
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
|
26
|
-
expectation = new_expectation.with
|
25
|
+
expectation = new_expectation.with
|
27
26
|
assert !expectation.match?(:expected_method, 1, 2, 3)
|
28
27
|
end
|
29
28
|
|
@@ -33,12 +32,12 @@ class ExpectationTest < Mocha::TestCase
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
|
36
|
-
expectation = new_expectation.with
|
35
|
+
expectation = new_expectation.with { |x, y, z| x + y == z }
|
37
36
|
assert expectation.match?(:expected_method, 1, 2, 3)
|
38
37
|
end
|
39
38
|
|
40
39
|
def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
|
41
|
-
expectation = new_expectation.with
|
40
|
+
expectation = new_expectation.with { |x, y, z| x + y == z }
|
42
41
|
assert !expectation.match?(:different_method, 1, 2, 3)
|
43
42
|
end
|
44
43
|
|
@@ -62,7 +61,7 @@ class ExpectationTest < Mocha::TestCase
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
|
65
|
-
expectation = new_expectation.with
|
64
|
+
expectation = new_expectation.with { |x, y, z| x + y == z }
|
66
65
|
assert !expectation.match?(:expected_method, 1, 0, 3)
|
67
66
|
end
|
68
67
|
|
@@ -99,51 +98,53 @@ class ExpectationTest < Mocha::TestCase
|
|
99
98
|
assert_equal backtrace, expectation.backtrace
|
100
99
|
end
|
101
100
|
|
101
|
+
# rubocop:disable Style/Semicolon
|
102
102
|
def test_should_default_backtrace_to_caller
|
103
103
|
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
104
104
|
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
105
105
|
end
|
106
|
+
# rubocop:enable Style/Semicolon
|
106
107
|
|
107
108
|
def test_should_not_yield
|
108
109
|
yielded = false
|
109
|
-
new_expectation.invoke
|
110
|
+
new_expectation.invoke { yielded = true }
|
110
111
|
assert_equal false, yielded
|
111
112
|
end
|
112
113
|
|
113
114
|
def test_should_yield_no_parameters
|
114
|
-
expectation = new_expectation
|
115
|
+
expectation = new_expectation.yields
|
115
116
|
yielded_parameters = nil
|
116
|
-
expectation.invoke
|
117
|
-
assert_equal
|
117
|
+
expectation.invoke { |*parameters| yielded_parameters = parameters }
|
118
|
+
assert_equal [], yielded_parameters
|
118
119
|
end
|
119
120
|
|
120
121
|
def test_should_yield_with_specified_parameters
|
121
|
-
expectation = new_expectation
|
122
|
+
expectation = new_expectation.yields(1, 2, 3)
|
122
123
|
yielded_parameters = nil
|
123
|
-
expectation.invoke
|
124
|
+
expectation.invoke { |*parameters| yielded_parameters = parameters }
|
124
125
|
assert_equal [1, 2, 3], yielded_parameters
|
125
126
|
end
|
126
127
|
|
127
128
|
def test_should_yield_different_parameters_on_consecutive_invocations
|
128
|
-
expectation = new_expectation
|
129
|
+
expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
|
129
130
|
yielded_parameters = []
|
130
|
-
expectation.invoke
|
131
|
-
expectation.invoke
|
131
|
+
expectation.invoke { |*parameters| yielded_parameters << parameters }
|
132
|
+
expectation.invoke { |*parameters| yielded_parameters << parameters }
|
132
133
|
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
133
134
|
end
|
134
135
|
|
135
136
|
def test_should_yield_multiple_times_for_single_invocation
|
136
|
-
expectation = new_expectation
|
137
|
+
expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5])
|
137
138
|
yielded_parameters = []
|
138
|
-
expectation.invoke
|
139
|
+
expectation.invoke { |*parameters| yielded_parameters << parameters }
|
139
140
|
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
140
141
|
end
|
141
142
|
|
142
143
|
def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
|
143
|
-
expectation = new_expectation
|
144
|
+
expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
|
144
145
|
yielded_parameters = []
|
145
|
-
expectation.invoke
|
146
|
-
expectation.invoke
|
146
|
+
expectation.invoke { |*parameters| yielded_parameters << parameters }
|
147
|
+
expectation.invoke { |*parameters| yielded_parameters << parameters }
|
147
148
|
assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
|
148
149
|
end
|
149
150
|
|
@@ -179,7 +180,7 @@ class ExpectationTest < Mocha::TestCase
|
|
179
180
|
end
|
180
181
|
|
181
182
|
def test_should_return_nil_if_no_value_specified
|
182
|
-
expectation = new_expectation.returns
|
183
|
+
expectation = new_expectation.returns
|
183
184
|
assert_nil expectation.invoke
|
184
185
|
end
|
185
186
|
|
@@ -209,21 +210,21 @@ class ExpectationTest < Mocha::TestCase
|
|
209
210
|
end
|
210
211
|
|
211
212
|
def test_should_raise_custom_exception_with_message
|
212
|
-
exception_msg =
|
213
|
+
exception_msg = 'exception message'
|
213
214
|
expectation = new_expectation.raises(Exception, exception_msg)
|
214
215
|
exception = assert_raise(Exception) { expectation.invoke }
|
215
216
|
assert_equal exception_msg, exception.message
|
216
217
|
end
|
217
218
|
|
218
219
|
def test_should_return_values_then_raise_exception
|
219
|
-
expectation = new_expectation.returns(1, 2).then.raises
|
220
|
+
expectation = new_expectation.returns(1, 2).then.raises
|
220
221
|
assert_equal 1, expectation.invoke
|
221
222
|
assert_equal 2, expectation.invoke
|
222
223
|
assert_raise(RuntimeError) { expectation.invoke }
|
223
224
|
end
|
224
225
|
|
225
226
|
def test_should_raise_exception_then_return_values
|
226
|
-
expectation = new_expectation.raises
|
227
|
+
expectation = new_expectation.raises.then.returns(1, 2)
|
227
228
|
assert_raise(RuntimeError) { expectation.invoke }
|
228
229
|
assert_equal 1, expectation.invoke
|
229
230
|
assert_equal 2, expectation.invoke
|
@@ -276,7 +277,7 @@ class ExpectationTest < Mocha::TestCase
|
|
276
277
|
|
277
278
|
def test_should_verify_successfully_if_expected_call_was_made_at_least_once
|
278
279
|
expectation = new_expectation.at_least_once
|
279
|
-
3.times {expectation.invoke}
|
280
|
+
3.times { expectation.invoke }
|
280
281
|
assert expectation.verified?
|
281
282
|
end
|
282
283
|
|
@@ -288,20 +289,20 @@ class ExpectationTest < Mocha::TestCase
|
|
288
289
|
|
289
290
|
def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
|
290
291
|
expectation = new_expectation.times(2)
|
291
|
-
2.times {expectation.invoke}
|
292
|
+
2.times { expectation.invoke }
|
292
293
|
assert expectation.verified?
|
293
294
|
end
|
294
295
|
|
295
296
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
|
296
297
|
expectation = new_expectation.times(2)
|
297
|
-
1.times {expectation.invoke}
|
298
|
+
1.times { expectation.invoke }
|
298
299
|
assert !expectation.verified?
|
299
300
|
assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
|
300
301
|
end
|
301
302
|
|
302
303
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
|
303
304
|
expectation = new_expectation.times(2)
|
304
|
-
3.times {expectation.invoke}
|
305
|
+
3.times { expectation.invoke }
|
305
306
|
assert !expectation.verified?
|
306
307
|
end
|
307
308
|
|
@@ -320,13 +321,14 @@ class ExpectationTest < Mocha::TestCase
|
|
320
321
|
assert_equal 0, assertion_counter.count
|
321
322
|
end
|
322
323
|
|
324
|
+
# rubocop:disable Style/Semicolon
|
323
325
|
def test_should_store_backtrace_from_point_where_expectation_was_created
|
324
326
|
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
325
327
|
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
326
328
|
end
|
329
|
+
# rubocop:enable Style/Semicolon
|
327
330
|
|
328
331
|
class FakeMock
|
329
|
-
|
330
332
|
def initialize(name)
|
331
333
|
@name = name
|
332
334
|
end
|
@@ -334,20 +336,18 @@ class ExpectationTest < Mocha::TestCase
|
|
334
336
|
def mocha_inspect
|
335
337
|
@name
|
336
338
|
end
|
337
|
-
|
338
339
|
end
|
339
340
|
|
340
341
|
def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
|
341
342
|
mock = FakeMock.new('mock')
|
342
343
|
sequence_one = Sequence.new('one')
|
343
344
|
sequence_two = Sequence.new('two')
|
344
|
-
expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
|
345
|
+
expectation = Expectation.new(mock, :expected_method).with(1, 2, { 'a' => true }, { :b => false }, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
|
345
346
|
assert !expectation.verified?
|
346
347
|
assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
|
347
348
|
end
|
348
349
|
|
349
350
|
class FakeConstraint
|
350
|
-
|
351
351
|
def initialize(allows_invocation_now)
|
352
352
|
@allows_invocation_now = allows_invocation_now
|
353
353
|
end
|
@@ -355,12 +355,11 @@ class ExpectationTest < Mocha::TestCase
|
|
355
355
|
def allows_invocation_now?
|
356
356
|
@allows_invocation_now
|
357
357
|
end
|
358
|
-
|
359
358
|
end
|
360
359
|
|
361
360
|
def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
|
362
|
-
constraint_one = FakeConstraint.new(
|
363
|
-
constraint_two = FakeConstraint.new(
|
361
|
+
constraint_one = FakeConstraint.new(true)
|
362
|
+
constraint_two = FakeConstraint.new(true)
|
364
363
|
expectation = Expectation.new(nil, :method_one)
|
365
364
|
expectation.add_ordering_constraint(constraint_one)
|
366
365
|
expectation.add_ordering_constraint(constraint_two)
|
@@ -368,8 +367,8 @@ class ExpectationTest < Mocha::TestCase
|
|
368
367
|
end
|
369
368
|
|
370
369
|
def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
|
371
|
-
constraint_one = FakeConstraint.new(
|
372
|
-
constraint_two = FakeConstraint.new(
|
370
|
+
constraint_one = FakeConstraint.new(true)
|
371
|
+
constraint_two = FakeConstraint.new(false)
|
373
372
|
expectation = Expectation.new(nil, :method_one)
|
374
373
|
expectation.add_ordering_constraint(constraint_one)
|
375
374
|
expectation.add_ordering_constraint(constraint_two)
|
@@ -377,8 +376,8 @@ class ExpectationTest < Mocha::TestCase
|
|
377
376
|
end
|
378
377
|
|
379
378
|
def test_should_match_if_all_ordering_constraints_allow_invocation_now
|
380
|
-
constraint_one = FakeConstraint.new(
|
381
|
-
constraint_two = FakeConstraint.new(
|
379
|
+
constraint_one = FakeConstraint.new(true)
|
380
|
+
constraint_two = FakeConstraint.new(true)
|
382
381
|
expectation = Expectation.new(nil, :method_one)
|
383
382
|
expectation.add_ordering_constraint(constraint_one)
|
384
383
|
expectation.add_ordering_constraint(constraint_two)
|
@@ -386,8 +385,8 @@ class ExpectationTest < Mocha::TestCase
|
|
386
385
|
end
|
387
386
|
|
388
387
|
def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
|
389
|
-
constraint_one = FakeConstraint.new(
|
390
|
-
constraint_two = FakeConstraint.new(
|
388
|
+
constraint_one = FakeConstraint.new(true)
|
389
|
+
constraint_two = FakeConstraint.new(false)
|
391
390
|
expectation = Expectation.new(nil, :method_one)
|
392
391
|
expectation.add_ordering_constraint(constraint_one)
|
393
392
|
expectation.add_ordering_constraint(constraint_two)
|
@@ -418,7 +417,6 @@ class ExpectationTest < Mocha::TestCase
|
|
418
417
|
end
|
419
418
|
|
420
419
|
class FakeSequence
|
421
|
-
|
422
420
|
attr_reader :expectations
|
423
421
|
|
424
422
|
def initialize
|
@@ -428,7 +426,6 @@ class ExpectationTest < Mocha::TestCase
|
|
428
426
|
def constrain_as_next_in_sequence(expectation)
|
429
427
|
@expectations << expectation
|
430
428
|
end
|
431
|
-
|
432
429
|
end
|
433
430
|
|
434
431
|
def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
|
@@ -441,7 +438,6 @@ class ExpectationTest < Mocha::TestCase
|
|
441
438
|
end
|
442
439
|
|
443
440
|
class FakeState
|
444
|
-
|
445
441
|
def initialize
|
446
442
|
@active = false
|
447
443
|
end
|
@@ -453,7 +449,6 @@ class ExpectationTest < Mocha::TestCase
|
|
453
449
|
def active?
|
454
450
|
@active
|
455
451
|
end
|
456
|
-
|
457
452
|
end
|
458
453
|
|
459
454
|
def test_should_change_state_when_expectation_is_invoked
|
@@ -483,7 +478,7 @@ class ExpectationTest < Mocha::TestCase
|
|
483
478
|
define_method(:inspect) { 'mock' }
|
484
479
|
end
|
485
480
|
expectation = Expectation.new(object, :method_one)
|
486
|
-
assert_match Regexp.new(
|
481
|
+
assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), expectation.inspect
|
487
482
|
end
|
488
483
|
|
489
484
|
def test_should_include_output_of_mocha_inspect_in_inspect
|