mocha 0.10.5 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,25 +4,25 @@ require 'mocha/configuration'
|
|
4
4
|
require 'introspection'
|
5
5
|
|
6
6
|
module AcceptanceTest
|
7
|
-
|
7
|
+
|
8
8
|
class FakeLogger
|
9
|
-
|
9
|
+
|
10
10
|
attr_reader :warnings
|
11
|
-
|
11
|
+
|
12
12
|
def initialize
|
13
13
|
@warnings = []
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def warn(message)
|
17
17
|
@warnings << message
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
attr_reader :logger
|
23
23
|
|
24
24
|
include TestRunner
|
25
|
-
|
25
|
+
|
26
26
|
def setup_acceptance_test
|
27
27
|
Mocha::Configuration.reset_configuration
|
28
28
|
@logger = FakeLogger.new
|
@@ -30,12 +30,12 @@ module AcceptanceTest
|
|
30
30
|
@original_logger = mockery.logger
|
31
31
|
mockery.logger = @logger
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def teardown_acceptance_test
|
35
35
|
Mocha::Configuration.reset_configuration
|
36
36
|
Mocha::Mockery.instance.logger = @original_logger
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
include Introspection::Assertions
|
40
|
-
|
40
|
+
|
41
41
|
end
|
data/test/acceptance/api_test.rb
CHANGED
@@ -6,15 +6,15 @@ class NotATestUnitAssertionFailedError < StandardError
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class NotATestUnitTestCase
|
9
|
-
|
9
|
+
|
10
10
|
include Mocha::API
|
11
|
-
|
11
|
+
|
12
12
|
attr_reader :assertion_counter
|
13
|
-
|
13
|
+
|
14
14
|
def initialize
|
15
15
|
@assertion_counter = SimpleCounter.new
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def run(test_method)
|
19
19
|
mocha_setup
|
20
20
|
begin
|
@@ -33,75 +33,75 @@ class NotATestUnitTestCase
|
|
33
33
|
mocha_teardown
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def prepare
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def cleanup
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
44
|
|
45
45
|
class SampleTest < NotATestUnitTestCase
|
46
|
-
|
46
|
+
|
47
47
|
def mocha_with_fulfilled_expectation
|
48
48
|
mockee = mock()
|
49
49
|
mockee.expects(:blah)
|
50
50
|
mockee.blah
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def mocha_with_unfulfilled_expectation
|
54
54
|
mockee = mock()
|
55
55
|
mockee.expects(:blah)
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def mocha_with_unexpected_invocation
|
59
59
|
mockee = mock()
|
60
60
|
mockee.blah
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def stubba_with_fulfilled_expectation
|
64
64
|
stubbee = Class.new { define_method(:blah) {} }.new
|
65
65
|
stubbee.expects(:blah)
|
66
66
|
stubbee.blah
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def stubba_with_unfulfilled_expectation
|
70
70
|
stubbee = Class.new { define_method(:blah) {} }.new
|
71
71
|
stubbee.expects(:blah)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def mocha_with_matching_parameter
|
75
75
|
mockee = mock()
|
76
76
|
mockee.expects(:blah).with(has_key(:wibble))
|
77
77
|
mockee.blah(:wibble => 1)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def mocha_with_non_matching_parameter
|
81
81
|
mockee = mock()
|
82
82
|
mockee.expects(:blah).with(has_key(:wibble))
|
83
83
|
mockee.blah(:wobble => 2)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
end
|
87
87
|
|
88
88
|
require 'test/unit'
|
89
89
|
|
90
90
|
class APITest < Test::Unit::TestCase
|
91
|
-
|
91
|
+
|
92
92
|
attr_reader :sample_test
|
93
93
|
|
94
94
|
include AcceptanceTest
|
95
|
-
|
95
|
+
|
96
96
|
def setup
|
97
97
|
@sample_test = SampleTest.new
|
98
98
|
setup_acceptance_test
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def teardown
|
102
102
|
teardown_acceptance_test
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def test_should_pass_mocha_test
|
106
106
|
assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) }
|
107
107
|
assert_equal 1, sample_test.assertion_counter.count
|
@@ -136,4 +136,4 @@ class APITest < Test::Unit::TestCase
|
|
136
136
|
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) }
|
137
137
|
end
|
138
138
|
|
139
|
-
end
|
139
|
+
end
|
@@ -2,42 +2,42 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class Bug18914Test < 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
|
class AlwaysEql
|
17
|
-
|
17
|
+
|
18
18
|
def my_method
|
19
19
|
true
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def ==(o)
|
23
23
|
true
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def eql?(o)
|
27
27
|
true
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method
|
33
|
-
|
33
|
+
|
34
34
|
always_eql_1 = AlwaysEql.new
|
35
35
|
always_eql_1.stubs(:my_method).returns(false)
|
36
|
-
|
36
|
+
|
37
37
|
always_eql_2 = AlwaysEql.new
|
38
38
|
always_eql_2.stubs(:my_method).returns(false)
|
39
|
-
|
39
|
+
|
40
40
|
assert_equal false, always_eql_2.my_method
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class Bug21465Test < 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_expected_method_name_to_be_a_string
|
17
17
|
test_result = run_as_test do
|
18
18
|
mock = mock()
|
@@ -21,7 +21,7 @@ class Bug21465Test < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
assert_passed(test_result)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_should_allow_stubbed_method_name_to_be_a_string
|
26
26
|
test_result = run_as_test do
|
27
27
|
mock = mock()
|
@@ -30,5 +30,5 @@ class Bug21465Test < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
assert_passed(test_result)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
end
|
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class Bug21563Test < 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_of_verified_method
|
17
17
|
test_result = run_as_test do
|
18
18
|
object = Object.new
|
@@ -21,5 +21,5 @@ class Bug21563Test < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
assert_passed(test_result)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
@@ -4,11 +4,11 @@ require 'mocha'
|
|
4
4
|
class ExpectedInvocationCountTest < 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
|
@@ -21,7 +21,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
assert_passed(test_result)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once
|
26
26
|
test_result = run_as_test do
|
27
27
|
mock = mock('mock')
|
@@ -35,7 +35,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
35
35
|
"- expected never, invoked once: #<Mock:mock>.method(any_parameters)"
|
36
36
|
], test_result.failure_message_lines
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def test_should_pass_if_method_is_expected_twice_and_is_called_twice
|
40
40
|
test_result = run_as_test do
|
41
41
|
mock = mock('mock')
|
@@ -44,7 +44,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
assert_passed(test_result)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def test_should_fail_if_method_is_expected_twice_but_is_called_once
|
49
49
|
test_result = run_as_test do
|
50
50
|
mock = mock('mock')
|
@@ -58,7 +58,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
58
58
|
"- expected exactly twice, invoked once: #<Mock:mock>.method(any_parameters)"
|
59
59
|
], test_result.failure_message_lines
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times
|
63
63
|
test_result = run_as_test do
|
64
64
|
mock = mock('mock')
|
@@ -72,7 +72,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
72
72
|
"- expected exactly twice, invoked 3 times: #<Mock:mock>.method(any_parameters)"
|
73
73
|
], test_result.failure_message_lines
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice
|
77
77
|
test_result = run_as_test do
|
78
78
|
mock = mock('mock')
|
@@ -127,7 +127,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
127
127
|
"- expected between 2 and 4 times, invoked 5 times: #<Mock:mock>.method(any_parameters)"
|
128
128
|
], test_result.failure_message_lines
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once
|
132
132
|
test_result = run_as_test do
|
133
133
|
mock = mock('mock')
|
@@ -136,7 +136,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
136
136
|
end
|
137
137
|
assert_passed(test_result)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice
|
141
141
|
test_result = run_as_test do
|
142
142
|
mock = mock('mock')
|
@@ -145,7 +145,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
145
145
|
end
|
146
146
|
assert_passed(test_result)
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called
|
150
150
|
test_result = run_as_test do
|
151
151
|
mock = mock('mock')
|
@@ -159,7 +159,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
159
159
|
"- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)"
|
160
160
|
], test_result.failure_message_lines
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called
|
164
164
|
test_result = run_as_test do
|
165
165
|
mock = mock('mock')
|
@@ -168,7 +168,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
168
168
|
end
|
169
169
|
assert_passed(test_result)
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
def test_should_pass_if_method_is_expected_at_most_once_and_called_once
|
173
173
|
test_result = run_as_test do
|
174
174
|
mock = mock('mock')
|
@@ -177,7 +177,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
177
177
|
end
|
178
178
|
assert_passed(test_result)
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice
|
182
182
|
test_result = run_as_test do
|
183
183
|
mock = mock('mock')
|
@@ -191,7 +191,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
191
191
|
"- expected at most once, invoked twice: #<Mock:mock>.method(any_parameters)"
|
192
192
|
], test_result.failure_message_lines
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed
|
196
196
|
test_result = run_as_test do
|
197
197
|
stub = stub_everything('stub')
|
@@ -200,7 +200,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
200
200
|
end
|
201
201
|
assert_passed(test_result)
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed
|
205
205
|
test_result = run_as_test do
|
206
206
|
stub = stub_everything('stub')
|
@@ -214,7 +214,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
214
214
|
"- expected never, invoked once: #<Mock:stub>.method(any_parameters)"
|
215
215
|
], test_result.failure_message_lines
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
def test_should_fail_fast_if_there_is_no_matching_expectation
|
219
219
|
test_result = run_as_test do
|
220
220
|
mock = mock('mock')
|
@@ -228,5 +228,5 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
|
|
228
228
|
"- expected exactly once, not yet invoked: #<Mock:mock>.method(1)"
|
229
229
|
], test_result.failure_message_lines
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
end
|
@@ -2,42 +2,42 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class FailureMessagesTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'
|
7
|
-
|
7
|
+
|
8
8
|
include AcceptanceTest
|
9
|
-
|
9
|
+
|
10
10
|
def setup
|
11
11
|
setup_acceptance_test
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def teardown
|
15
15
|
teardown_acceptance_test
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
class Foo; end
|
19
|
-
|
19
|
+
|
20
20
|
def test_should_display_class_name_when_expectation_was_on_class
|
21
21
|
test_result = run_as_test do
|
22
22
|
Foo.expects(:bar)
|
23
23
|
end
|
24
24
|
assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_should_display_class_name_and_address_when_expectation_was_on_instance
|
28
28
|
test_result = run_as_test do
|
29
29
|
Foo.new.expects(:bar)
|
30
30
|
end
|
31
31
|
assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
|
35
35
|
test_result = run_as_test do
|
36
36
|
Foo.any_instance.expects(:bar)
|
37
37
|
end
|
38
38
|
assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_should_display_mock_name_when_expectation_was_on_named_mock
|
42
42
|
test_result = run_as_test do
|
43
43
|
foo = mock('foo')
|
@@ -45,7 +45,7 @@ class FailureMessagesTest < Test::Unit::TestCase
|
|
45
45
|
end
|
46
46
|
assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
|
50
50
|
test_result = run_as_test do
|
51
51
|
foo = mock()
|
@@ -53,12 +53,12 @@ class FailureMessagesTest < Test::Unit::TestCase
|
|
53
53
|
end
|
54
54
|
assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_should_display_string_when_expectation_was_on_string
|
58
58
|
test_result = run_as_test do
|
59
59
|
'Foo'.expects(:bar)
|
60
60
|
end
|
61
61
|
assert_match Regexp.new("'Foo'"), test_result.failures[0].message
|
62
62
|
end
|
63
|
-
|
64
|
-
end
|
63
|
+
|
64
|
+
end
|