mocha 0.5.6 → 0.9.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/README +4 -4
- data/RELEASE +45 -0
- data/Rakefile +55 -33
- data/lib/mocha.rb +1 -0
- data/lib/mocha/any_instance_method.rb +24 -4
- data/lib/mocha/backtrace_filter.rb +17 -0
- data/lib/mocha/cardinality.rb +92 -0
- data/lib/mocha/central.rb +1 -9
- data/lib/mocha/change_state_side_effect.rb +19 -0
- data/lib/mocha/class_method.rb +25 -5
- data/lib/mocha/configuration.rb +60 -0
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation.rb +109 -48
- data/lib/mocha/expectation_error.rb +6 -6
- data/lib/mocha/expectation_list.rb +10 -14
- data/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/lib/mocha/instance_method.rb +9 -0
- data/lib/mocha/logger.rb +15 -0
- data/lib/mocha/mock.rb +19 -14
- data/lib/mocha/mockery.rb +166 -0
- data/lib/mocha/module_method.rb +17 -0
- data/lib/mocha/names.rb +53 -0
- data/lib/mocha/object.rb +26 -9
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/parameter_matchers/all_of.rb +3 -3
- data/lib/mocha/parameter_matchers/any_of.rb +3 -3
- data/lib/mocha/parameter_matchers/anything.rb +1 -1
- data/lib/mocha/parameter_matchers/has_entries.rb +4 -1
- data/lib/mocha/parameter_matchers/has_entry.rb +3 -2
- data/lib/mocha/parameter_matchers/has_key.rb +1 -1
- data/lib/mocha/parameter_matchers/has_value.rb +1 -1
- data/lib/mocha/parameter_matchers/not.rb +2 -2
- data/lib/mocha/parameter_matchers/object.rb +1 -1
- data/lib/mocha/parameter_matchers/optionally.rb +22 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +2 -2
- data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/lib/mocha/single_return_value.rb +2 -9
- data/lib/mocha/standalone.rb +151 -17
- data/lib/mocha/state_machine.rb +91 -0
- data/lib/mocha/stubbing_error.rb +16 -0
- data/lib/mocha/test_case_adapter.rb +76 -22
- data/lib/stubba.rb +2 -1
- data/test/acceptance/acceptance_test_helper.rb +38 -0
- data/test/acceptance/bug_18914_test.rb +43 -0
- data/test/acceptance/{expected_invocation_count_acceptance_test.rb → expected_invocation_count_test.rb} +29 -20
- data/test/acceptance/failure_messages_test.rb +64 -0
- data/test/acceptance/{mocha_acceptance_test.rb → mocha_example_test.rb} +5 -5
- data/test/{integration/mocha_test_result_integration_test.rb → acceptance/mocha_test_result_test.rb} +19 -40
- data/test/acceptance/mock_test.rb +100 -0
- data/test/acceptance/{mock_with_initializer_block_acceptance_test.rb → mock_with_initializer_block_test.rb} +12 -5
- data/test/acceptance/{mocked_methods_dispatch_acceptance_test.rb → mocked_methods_dispatch_test.rb} +12 -5
- data/test/acceptance/{optional_parameters_acceptance_test.rb → optional_parameters_test.rb} +11 -4
- data/test/acceptance/{parameter_matcher_acceptance_test.rb → parameter_matcher_test.rb} +67 -5
- data/test/acceptance/{partial_mocks_acceptance_test.rb → partial_mocks_test.rb} +12 -5
- data/test/acceptance/return_value_test.rb +52 -0
- data/test/acceptance/{sequence_acceptance_test.rb → sequence_test.rb} +13 -6
- data/test/acceptance/{standalone_acceptance_test.rb → standalone_test.rb} +19 -11
- data/test/acceptance/states_test.rb +70 -0
- data/test/acceptance/stub_any_instance_method_test.rb +195 -0
- data/test/acceptance/stub_class_method_test.rb +203 -0
- data/test/acceptance/stub_everything_test.rb +56 -0
- data/test/acceptance/stub_instance_method_test.rb +165 -0
- data/test/acceptance/stub_module_method_test.rb +163 -0
- data/test/acceptance/stub_test.rb +52 -0
- data/test/acceptance/{stubba_acceptance_test.rb → stubba_example_test.rb} +1 -1
- data/test/{integration/stubba_test_result_integration_test.rb → acceptance/stubba_test_result_test.rb} +17 -36
- data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +155 -0
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +145 -0
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_public_class_method_test.rb +161 -0
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +141 -0
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
- data/test/execution_point.rb +3 -1
- data/test/simple_counter.rb +13 -0
- data/test/test_helper.rb +0 -1
- data/test/test_runner.rb +6 -4
- data/test/unit/any_instance_method_test.rb +1 -1
- data/test/unit/array_inspect_test.rb +1 -1
- data/test/unit/backtrace_filter_test.rb +19 -0
- data/test/unit/cardinality_test.rb +56 -0
- data/test/unit/central_test.rb +4 -63
- data/test/unit/change_state_side_effect_test.rb +41 -0
- data/test/unit/class_method_test.rb +38 -1
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/{expectation_raiser_test.rb → exception_raiser_test.rb} +14 -0
- data/test/unit/expectation_list_test.rb +4 -22
- data/test/unit/expectation_test.rb +70 -94
- data/test/unit/in_state_ordering_constraint_test.rb +43 -0
- data/test/unit/mock_test.rb +16 -37
- data/test/unit/mockery_test.rb +149 -0
- data/test/unit/{no_yield_test.rb → no_yields_test.rb} +0 -0
- data/test/unit/object_test.rb +6 -89
- data/test/unit/parameter_matchers/equals_test.rb +25 -0
- data/test/unit/parameter_matchers/has_entries_test.rb +22 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +24 -2
- data/test/unit/parameter_matchers/has_key_test.rb +11 -0
- data/test/unit/parameter_matchers/has_value_test.rb +12 -0
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -0
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
- data/test/unit/single_return_value_test.rb +0 -19
- data/test/unit/state_machine_test.rb +98 -0
- metadata +108 -69
- data/lib/mocha/auto_verify.rb +0 -118
- data/lib/mocha/infinite_range.rb +0 -25
- data/lib/mocha/missing_expectation.rb +0 -17
- data/lib/mocha/setup_and_teardown.rb +0 -23
- data/lib/mocha/stub.rb +0 -18
- data/test/integration/stubba_integration_test.rb +0 -89
- data/test/unit/auto_verify_test.rb +0 -129
- data/test/unit/expectation_error_test.rb +0 -24
- data/test/unit/infinite_range_test.rb +0 -53
- data/test/unit/missing_expectation_test.rb +0 -42
- data/test/unit/setup_and_teardown_test.rb +0 -76
- data/test/unit/stub_test.rb +0 -24
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mocha/backtrace_filter'
|
2
|
+
|
3
|
+
module Mocha # :nodoc:
|
4
|
+
|
5
|
+
# Exception raised when an action prevented by Configuration#prevent is attempted.
|
6
|
+
class StubbingError < StandardError
|
7
|
+
|
8
|
+
def initialize(message = nil, backtrace = []) # :nodoc:
|
9
|
+
super(message)
|
10
|
+
filter = BacktraceFilter.new
|
11
|
+
set_backtrace(filter.filtered(backtrace))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -3,43 +3,97 @@ require 'mocha/expectation_error'
|
|
3
3
|
module Mocha
|
4
4
|
|
5
5
|
module TestCaseAdapter
|
6
|
+
|
7
|
+
class AssertionCounter
|
8
|
+
|
9
|
+
def initialize(test_result)
|
10
|
+
@test_result = test_result
|
11
|
+
end
|
12
|
+
|
13
|
+
def increment
|
14
|
+
@test_result.add_assertion
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
6
18
|
|
7
19
|
def self.included(base)
|
8
|
-
|
20
|
+
if RUBY_VERSION < '1.8.6'
|
21
|
+
base.class_eval do
|
9
22
|
|
10
|
-
|
23
|
+
alias_method :run_before_mocha_test_case_adapter, :run
|
11
24
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
mocha_setup
|
25
|
+
def run(result)
|
26
|
+
assertion_counter = AssertionCounter.new(result)
|
27
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
28
|
+
@_result = result
|
17
29
|
begin
|
18
|
-
setup
|
19
|
-
__send__(@method_name)
|
20
|
-
mocha_verify { add_assertion }
|
21
|
-
rescue Mocha::ExpectationError => e
|
22
|
-
add_failure(e.message, e.backtrace)
|
23
|
-
rescue Test::Unit::AssertionFailedError => e
|
24
|
-
add_failure(e.message, e.backtrace)
|
25
|
-
rescue StandardError, ScriptError
|
26
|
-
add_error($!)
|
27
|
-
ensure
|
28
30
|
begin
|
29
|
-
|
31
|
+
setup
|
32
|
+
__send__(@method_name)
|
33
|
+
mocha_verify(assertion_counter)
|
34
|
+
rescue Mocha::ExpectationError => e
|
35
|
+
add_failure(e.message, e.backtrace)
|
30
36
|
rescue Test::Unit::AssertionFailedError => e
|
31
37
|
add_failure(e.message, e.backtrace)
|
32
38
|
rescue StandardError, ScriptError
|
33
39
|
add_error($!)
|
40
|
+
ensure
|
41
|
+
begin
|
42
|
+
teardown
|
43
|
+
rescue Test::Unit::AssertionFailedError => e
|
44
|
+
add_failure(e.message, e.backtrace)
|
45
|
+
rescue StandardError, ScriptError
|
46
|
+
add_error($!)
|
47
|
+
end
|
34
48
|
end
|
49
|
+
ensure
|
50
|
+
mocha_teardown
|
35
51
|
end
|
36
|
-
|
37
|
-
|
52
|
+
result.add_run
|
53
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
38
54
|
end
|
39
|
-
|
40
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
55
|
+
|
41
56
|
end
|
57
|
+
else
|
58
|
+
base.class_eval do
|
59
|
+
|
60
|
+
alias_method :run_before_mocha_test_case_adapter, :run
|
61
|
+
|
62
|
+
def run(result)
|
63
|
+
assertion_counter = AssertionCounter.new(result)
|
64
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
65
|
+
@_result = result
|
66
|
+
begin
|
67
|
+
begin
|
68
|
+
setup
|
69
|
+
__send__(@method_name)
|
70
|
+
mocha_verify(assertion_counter)
|
71
|
+
rescue Mocha::ExpectationError => e
|
72
|
+
add_failure(e.message, e.backtrace)
|
73
|
+
rescue Test::Unit::AssertionFailedError => e
|
74
|
+
add_failure(e.message, e.backtrace)
|
75
|
+
rescue Exception
|
76
|
+
raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
|
77
|
+
add_error($!)
|
78
|
+
ensure
|
79
|
+
begin
|
80
|
+
teardown
|
81
|
+
rescue Test::Unit::AssertionFailedError => e
|
82
|
+
add_failure(e.message, e.backtrace)
|
83
|
+
rescue Exception
|
84
|
+
raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
|
85
|
+
add_error($!)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
ensure
|
89
|
+
mocha_teardown
|
90
|
+
end
|
91
|
+
result.add_run
|
92
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
93
|
+
end
|
42
94
|
|
95
|
+
end
|
96
|
+
|
43
97
|
end
|
44
98
|
|
45
99
|
end
|
data/lib/stubba.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'test_runner'
|
3
|
+
require 'mocha/configuration'
|
4
|
+
|
5
|
+
module AcceptanceTest
|
6
|
+
|
7
|
+
class FakeLogger
|
8
|
+
|
9
|
+
attr_reader :warnings
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@warnings = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def warn(message)
|
16
|
+
@warnings << message
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :logger
|
22
|
+
|
23
|
+
include TestRunner
|
24
|
+
|
25
|
+
def setup_acceptance_test
|
26
|
+
Mocha::Configuration.reset_configuration
|
27
|
+
@logger = FakeLogger.new
|
28
|
+
mockery = Mocha::Mockery.instance
|
29
|
+
@original_logger = mockery.logger
|
30
|
+
mockery.logger = @logger
|
31
|
+
end
|
32
|
+
|
33
|
+
def teardown_acceptance_test
|
34
|
+
Mocha::Configuration.reset_configuration
|
35
|
+
Mocha::Mockery.instance.logger = @original_logger
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
class Bug18914Test < 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
|
+
class AlwaysEql
|
17
|
+
|
18
|
+
def my_method
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(o)
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def eql?(o)
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method
|
33
|
+
|
34
|
+
always_eql_1 = AlwaysEql.new
|
35
|
+
always_eql_1.stubs(:my_method).returns(false)
|
36
|
+
|
37
|
+
always_eql_2 = AlwaysEql.new
|
38
|
+
always_eql_2.stubs(:my_method).returns(false)
|
39
|
+
|
40
|
+
assert_equal false, always_eql_2.my_method
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -1,10 +1,17 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "
|
1
|
+
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
2
|
require 'mocha'
|
3
|
-
require 'test_runner'
|
4
3
|
|
5
|
-
class
|
4
|
+
class ExpectedInvocationCountTest < Test::Unit::TestCase
|
6
5
|
|
7
|
-
include
|
6
|
+
include AcceptanceTest
|
7
|
+
|
8
|
+
def setup
|
9
|
+
setup_acceptance_test
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
teardown_acceptance_test
|
14
|
+
end
|
8
15
|
|
9
16
|
def test_should_pass_if_method_is_never_expected_and_is_never_called
|
10
17
|
test_result = run_test do
|
@@ -22,8 +29,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
22
29
|
1.times { mock.method }
|
23
30
|
end
|
24
31
|
assert_failed(test_result)
|
25
|
-
|
26
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: 0, actual calls: 1'], failure_messages
|
32
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected never, already invoked 1 time: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
27
33
|
end
|
28
34
|
|
29
35
|
def test_should_pass_if_method_is_expected_twice_and_is_called_twice
|
@@ -42,8 +48,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
42
48
|
1.times { mock.method }
|
43
49
|
end
|
44
50
|
assert_failed(test_result)
|
45
|
-
|
46
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: 2, actual calls: 1'], failure_messages
|
51
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected exactly 2 times, already invoked 1 time: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
47
52
|
end
|
48
53
|
|
49
54
|
def test_should_fail_if_method_is_expected_twice_but_is_called_three_times
|
@@ -53,8 +58,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
53
58
|
3.times { mock.method }
|
54
59
|
end
|
55
60
|
assert_failed(test_result)
|
56
|
-
|
57
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: 2, actual calls: 3'], failure_messages
|
61
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected exactly 2 times, already invoked 3 times: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
58
62
|
end
|
59
63
|
|
60
64
|
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice
|
@@ -91,8 +95,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
91
95
|
1.times { mock.method }
|
92
96
|
end
|
93
97
|
assert_failed(test_result)
|
94
|
-
|
95
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: 2..4, actual calls: 1'], failure_messages
|
98
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected between 2 and 4 times, already invoked 1 time: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
96
99
|
end
|
97
100
|
|
98
101
|
def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_five_times
|
@@ -102,8 +105,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
102
105
|
5.times { mock.method }
|
103
106
|
end
|
104
107
|
assert_failed(test_result)
|
105
|
-
|
106
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: 2..4, actual calls: 5'], failure_messages
|
108
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected between 2 and 4 times, already invoked 5 times: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
107
109
|
end
|
108
110
|
|
109
111
|
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once
|
@@ -131,8 +133,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
131
133
|
0.times { mock.method }
|
132
134
|
end
|
133
135
|
assert_failed(test_result)
|
134
|
-
|
135
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: at least 1, actual calls: 0'], failure_messages
|
136
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected at least once, never invoked: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
136
137
|
end
|
137
138
|
|
138
139
|
def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called
|
@@ -160,8 +161,7 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
160
161
|
2.times { mock.method }
|
161
162
|
end
|
162
163
|
assert_failed(test_result)
|
163
|
-
|
164
|
-
assert_equal ['#<Mock:mock>.method(any_parameters) - expected calls: at most 1, actual calls: 2'], failure_messages
|
164
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected at most once, already invoked 2 times: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages
|
165
165
|
end
|
166
166
|
|
167
167
|
def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed
|
@@ -180,8 +180,17 @@ class ExpectedInvocationCountAcceptanceTest < Test::Unit::TestCase
|
|
180
180
|
1.times { stub.method }
|
181
181
|
end
|
182
182
|
assert_failed(test_result)
|
183
|
-
|
184
|
-
|
183
|
+
assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected never, already invoked 1 time: #<Mock:stub>.method(any_parameters)\n"], test_result.failure_messages
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_should_fail_if_there_is_no_matching_expectation
|
187
|
+
test_result = run_test do
|
188
|
+
mock = mock('mock')
|
189
|
+
mock.expects(:method).with(1)
|
190
|
+
1.times { mock.method }
|
191
|
+
end
|
192
|
+
assert_failed(test_result)
|
193
|
+
assert_equal ["unexpected invocation: #<Mock:mock>.method()\nunsatisfied expectations:\n- expected exactly once, never invoked: #<Mock:mock>.method(1)\n"], test_result.failure_messages
|
185
194
|
end
|
186
195
|
|
187
196
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
class FailureMessagesTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'
|
7
|
+
|
8
|
+
include AcceptanceTest
|
9
|
+
|
10
|
+
def setup
|
11
|
+
setup_acceptance_test
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
teardown_acceptance_test
|
16
|
+
end
|
17
|
+
|
18
|
+
class Foo; end
|
19
|
+
|
20
|
+
def test_should_display_class_name_when_expectation_was_on_class
|
21
|
+
test_result = run_test do
|
22
|
+
Foo.expects(:bar)
|
23
|
+
end
|
24
|
+
assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_display_class_name_and_address_when_expectation_was_on_instance
|
28
|
+
test_result = run_test do
|
29
|
+
Foo.new.expects(:bar)
|
30
|
+
end
|
31
|
+
assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
|
35
|
+
test_result = run_test do
|
36
|
+
Foo.any_instance.expects(:bar)
|
37
|
+
end
|
38
|
+
assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_display_mock_name_when_expectation_was_on_named_mock
|
42
|
+
test_result = run_test do
|
43
|
+
foo = mock('foo')
|
44
|
+
foo.expects(:bar)
|
45
|
+
end
|
46
|
+
assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
|
50
|
+
test_result = run_test do
|
51
|
+
foo = mock()
|
52
|
+
foo.expects(:bar)
|
53
|
+
end
|
54
|
+
assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_display_string_when_expectation_was_on_string
|
58
|
+
test_result = run_test do
|
59
|
+
'Foo'.expects(:bar)
|
60
|
+
end
|
61
|
+
assert_match Regexp.new("'Foo'"), test_result.failures[0].message
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
2
|
require 'mocha'
|
3
3
|
|
4
|
-
class
|
4
|
+
class MochaExampleTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
class Rover
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(left_track, right_track, steps_per_metre, steps_per_degree)
|
9
9
|
@left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def forward(metres)
|
13
13
|
@left_track.step(metres * @steps_per_metre)
|
14
14
|
@right_track.step(metres * @steps_per_metre)
|
15
15
|
wait
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def backward(metres)
|
19
19
|
forward(-metres)
|
20
20
|
end
|
@@ -32,7 +32,7 @@ class MochaAcceptanceTest < Test::Unit::TestCase
|
|
32
32
|
def wait
|
33
33
|
while (@left_track.moving? or @right_track.moving?); end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_should_step_both_tracks_forward_ten_steps
|
data/test/{integration/mocha_test_result_integration_test.rb → acceptance/mocha_test_result_test.rb}
RENAMED
@@ -1,10 +1,19 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "
|
2
|
-
require 'mocha
|
3
|
-
require 'mocha/test_case_adapter'
|
1
|
+
require File.join(File.dirname(__FILE__), "acceptance_test_helper")
|
2
|
+
require 'mocha'
|
4
3
|
require 'execution_point'
|
5
4
|
|
6
|
-
class
|
5
|
+
class MochaTestResultTest < Test::Unit::TestCase
|
7
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
|
+
|
8
17
|
def test_should_include_expectation_verification_in_assertion_count
|
9
18
|
test_result = run_test do
|
10
19
|
object = mock()
|
@@ -53,53 +62,23 @@ class MochaTestResultIntegrationTest < Test::Unit::TestCase
|
|
53
62
|
assert_equal 1, test_result.failure_count
|
54
63
|
end
|
55
64
|
|
56
|
-
def test_should_display_backtrace_indicating_line_number_where_expects_was_called
|
57
|
-
test_result = Test::Unit::TestResult.new
|
58
|
-
faults = []
|
59
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
60
|
-
execution_point = nil
|
61
|
-
run_test(test_result) do
|
62
|
-
object = mock()
|
63
|
-
execution_point = ExecutionPoint.current; object.expects(:message)
|
64
|
-
end
|
65
|
-
assert_equal 1, faults.length
|
66
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
67
|
-
end
|
68
|
-
|
69
65
|
def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
|
70
|
-
test_result = Test::Unit::TestResult.new
|
71
|
-
faults = []
|
72
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
73
66
|
execution_point = nil
|
74
|
-
|
67
|
+
test_result = run_test do
|
75
68
|
object = mock()
|
76
69
|
execution_point = ExecutionPoint.current; object.message
|
77
70
|
end
|
78
|
-
assert_equal 1,
|
79
|
-
assert_equal execution_point, ExecutionPoint.new(
|
71
|
+
assert_equal 1, test_result.failure_count
|
72
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
80
73
|
end
|
81
74
|
|
82
75
|
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
83
|
-
test_result = Test::Unit::TestResult.new
|
84
|
-
faults = []
|
85
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
86
76
|
execution_point = nil
|
87
|
-
|
77
|
+
test_result = run_test do
|
88
78
|
execution_point = ExecutionPoint.current; flunk
|
89
79
|
end
|
90
|
-
assert_equal 1,
|
91
|
-
assert_equal execution_point, ExecutionPoint.new(
|
92
|
-
end
|
93
|
-
|
94
|
-
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
95
|
-
test_class = Class.new(Test::Unit::TestCase) do
|
96
|
-
include Mocha::Standalone
|
97
|
-
include Mocha::TestCaseAdapter
|
98
|
-
define_method(:test_me, &block)
|
99
|
-
end
|
100
|
-
test = test_class.new(:test_me)
|
101
|
-
test.run(test_result) {}
|
102
|
-
test_result
|
80
|
+
assert_equal 1, test_result.failure_count
|
81
|
+
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
103
82
|
end
|
104
83
|
|
105
84
|
end
|