jferris-mocha 0.9.7.20090911190113 → 0.9.8.20100526112143
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 +3 -1
- data/RELEASE +7 -0
- data/Rakefile +3 -3
- data/lib/mocha/configuration.rb +29 -10
- data/lib/mocha/expectation.rb +5 -1
- data/lib/mocha/integration/mini_test.rb +27 -2
- data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
- data/lib/mocha/integration/mini_test/version_13.rb +44 -0
- data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_140.rb} +7 -12
- data/lib/mocha/integration/mini_test/version_141.rb +56 -0
- data/lib/mocha/integration/mini_test/version_142_and_above.rb +56 -0
- data/lib/mocha/integration/test_unit.rb +20 -7
- data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
- data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
- data/lib/mocha/integration/test_unit/gem_version_203_to_207.rb +52 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
- data/lib/mocha/mock.rb +0 -1
- data/lib/mocha/module_method.rb +1 -1
- data/lib/mocha/parameter_matchers/base.rb +50 -2
- data/lib/mocha/parameter_matchers/has_key.rb +1 -0
- data/lib/mocha/parameter_matchers/has_value.rb +1 -0
- data/lib/mocha/parameter_matchers/includes.rb +1 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +1 -0
- data/test/acceptance/acceptance_test_helper.rb +1 -1
- data/test/acceptance/api_test.rb +1 -1
- data/test/acceptance/bug_18914_test.rb +1 -1
- data/test/acceptance/bug_21465_test.rb +1 -1
- data/test/acceptance/bug_21563_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/minitest_test.rb +128 -124
- data/test/acceptance/mocha_example_test.rb +1 -1
- data/test/acceptance/mocha_test_result_test.rb +1 -1
- data/test/acceptance/mock_test.rb +1 -1
- data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
- data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
- data/test/acceptance/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +38 -1
- data/test/acceptance/partial_mocks_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +1 -1
- data/test/acceptance/sequence_test.rb +1 -1
- data/test/acceptance/states_test.rb +1 -1
- data/test/acceptance/stub_any_instance_method_test.rb +5 -2
- data/test/acceptance/stub_class_method_test.rb +5 -2
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_test.rb +5 -2
- data/test/acceptance/stub_module_method_test.rb +3 -3
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_test.rb +1 -1
- data/test/acceptance/stubba_test_result_test.rb +1 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/mini_test_result.rb +74 -0
- data/test/test_helper.rb +1 -0
- data/test/test_runner.rb +25 -11
- 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 +1 -1
- data/test/unit/cardinality_test.rb +1 -1
- data/test/unit/central_test.rb +1 -1
- data/test/unit/change_state_side_effect_test.rb +1 -1
- data/test/unit/class_method_test.rb +1 -1
- data/test/unit/configuration_test.rb +38 -0
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/exception_raiser_test.rb +1 -1
- data/test/unit/expectation_list_test.rb +1 -1
- data/test/unit/expectation_test.rb +1 -1
- data/test/unit/hash_inspect_test.rb +1 -1
- data/test/unit/in_state_ordering_constraint_test.rb +1 -1
- data/test/unit/metaclass_test.rb +1 -1
- data/test/unit/method_matcher_test.rb +1 -1
- data/test/unit/mock_test.rb +1 -1
- data/test/unit/mockery_test.rb +1 -1
- data/test/unit/multiple_yields_test.rb +1 -1
- data/test/unit/no_yields_test.rb +1 -1
- data/test/unit/object_inspect_test.rb +9 -8
- data/test/unit/object_test.rb +1 -1
- data/test/unit/parameter_matchers/all_of_test.rb +1 -1
- data/test/unit/parameter_matchers/any_of_test.rb +1 -1
- data/test/unit/parameter_matchers/anything_test.rb +1 -1
- data/test/unit/parameter_matchers/equals_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +20 -1
- data/test/unit/parameter_matchers/has_value_test.rb +21 -1
- data/test/unit/parameter_matchers/includes_test.rb +21 -2
- data/test/unit/parameter_matchers/instance_of_test.rb +1 -1
- data/test/unit/parameter_matchers/is_a_test.rb +1 -1
- data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
- data/test/unit/parameter_matchers/not_test.rb +1 -1
- data/test/unit/parameter_matchers/regexp_matches_test.rb +22 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
- data/test/unit/parameters_matcher_test.rb +1 -1
- data/test/unit/return_values_test.rb +1 -1
- data/test/unit/sequence_test.rb +1 -1
- data/test/unit/single_return_value_test.rb +1 -1
- data/test/unit/single_yield_test.rb +1 -1
- data/test/unit/state_machine_test.rb +1 -1
- data/test/unit/string_inspect_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +1 -1
- metadata +39 -13
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
@@ -25,7 +25,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
25
25
|
klass.stubs(:private_method)
|
26
26
|
end
|
27
27
|
assert_passed(test_result)
|
28
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method")
|
28
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.private_method")
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_should_allow_stubbing_protected_class_method
|
@@ -40,7 +40,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
40
40
|
klass.stubs(:protected_method)
|
41
41
|
end
|
42
42
|
assert_passed(test_result)
|
43
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method")
|
43
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.protected_method")
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_should_warn_when_stubbing_private_class_method
|
@@ -55,7 +55,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
55
55
|
klass.stubs(:private_method)
|
56
56
|
end
|
57
57
|
assert_passed(test_result)
|
58
|
-
assert @logger.warnings.include?("stubbing non-public method: #{klass}.private_method")
|
58
|
+
assert @logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.private_method")
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_should_warn_when_stubbing_protected_class_method
|
@@ -70,7 +70,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
70
70
|
klass.stubs(:protected_method)
|
71
71
|
end
|
72
72
|
assert_passed(test_result)
|
73
|
-
assert @logger.warnings.include?("stubbing non-public method: #{klass}.protected_method")
|
73
|
+
assert @logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.protected_method")
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_should_prevent_stubbing_private_class_method
|
@@ -85,7 +85,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
85
85
|
klass.stubs(:private_method)
|
86
86
|
end
|
87
87
|
assert_failed(test_result)
|
88
|
-
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.private_method")
|
88
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.mocha_inspect}.private_method")
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_should_prevent_stubbing_protected_class_method
|
@@ -100,7 +100,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
100
100
|
klass.stubs(:protected_method)
|
101
101
|
end
|
102
102
|
assert_failed(test_result)
|
103
|
-
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass}.protected_method")
|
103
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{klass.mocha_inspect}.protected_method")
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_should_default_to_allow_stubbing_private_class_method
|
@@ -114,7 +114,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
114
114
|
klass.stubs(:private_method)
|
115
115
|
end
|
116
116
|
assert_passed(test_result)
|
117
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{klass}.private_method")
|
117
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.private_method")
|
118
118
|
end
|
119
119
|
|
120
120
|
def test_should_default_to_allow_stubbing_protected_class_method
|
@@ -128,7 +128,7 @@ class StubbingNonPublicClassMethodTest < Test::Unit::TestCase
|
|
128
128
|
klass.stubs(:protected_method)
|
129
129
|
end
|
130
130
|
assert_passed(test_result)
|
131
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{klass}.protected_method")
|
131
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{klass.mocha_inspect}.protected_method")
|
132
132
|
end
|
133
133
|
|
134
134
|
def test_should_allow_stubbing_public_class_method
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
@@ -23,7 +23,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
23
23
|
instance.stubs(:private_method)
|
24
24
|
end
|
25
25
|
assert_passed(test_result)
|
26
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method")
|
26
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.private_method")
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_should_allow_stubbing_protected_instance_method
|
@@ -36,7 +36,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
36
36
|
instance.stubs(:protected_method)
|
37
37
|
end
|
38
38
|
assert_passed(test_result)
|
39
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method")
|
39
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.protected_method")
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_should_warn_when_stubbing_private_instance_method
|
@@ -49,7 +49,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
49
49
|
instance.stubs(:private_method)
|
50
50
|
end
|
51
51
|
assert_passed(test_result)
|
52
|
-
assert @logger.warnings.include?("stubbing non-public method: #{instance}.private_method")
|
52
|
+
assert @logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.private_method")
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_should_warn_when_stubbing_protected_instance_method
|
@@ -62,7 +62,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
62
62
|
instance.stubs(:protected_method)
|
63
63
|
end
|
64
64
|
assert_passed(test_result)
|
65
|
-
assert @logger.warnings.include?("stubbing non-public method: #{instance}.protected_method")
|
65
|
+
assert @logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.protected_method")
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_should_prevent_stubbing_private_instance_method
|
@@ -75,7 +75,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
75
75
|
instance.stubs(:private_method)
|
76
76
|
end
|
77
77
|
assert_failed(test_result)
|
78
|
-
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.private_method")
|
78
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance.mocha_inspect}.private_method")
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_should_prevent_stubbing_protected_instance_method
|
@@ -88,7 +88,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
88
88
|
instance.stubs(:protected_method)
|
89
89
|
end
|
90
90
|
assert_failed(test_result)
|
91
|
-
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance}.protected_method")
|
91
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing non-public method: #{instance.mocha_inspect}.protected_method")
|
92
92
|
end
|
93
93
|
|
94
94
|
def test_should_default_to_allow_stubbing_private_instance_method
|
@@ -100,7 +100,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
100
100
|
instance.stubs(:private_method)
|
101
101
|
end
|
102
102
|
assert_passed(test_result)
|
103
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{instance}.private_method")
|
103
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.private_method")
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_should_default_to_allow_stubbing_protected_instance_method
|
@@ -112,7 +112,7 @@ class StubbingNonPublicInstanceMethodTest < Test::Unit::TestCase
|
|
112
112
|
instance.stubs(:protected_method)
|
113
113
|
end
|
114
114
|
assert_passed(test_result)
|
115
|
-
assert !@logger.warnings.include?("stubbing non-public method: #{instance}.protected_method")
|
115
|
+
assert !@logger.warnings.include?("stubbing non-public method: #{instance.mocha_inspect}.protected_method")
|
116
116
|
end
|
117
117
|
|
118
118
|
def test_should_allow_stubbing_public_instance_method
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubbingOnNonMockObjectTest < Test::Unit::TestCase
|
@@ -20,7 +20,7 @@ class StubbingOnNonMockObjectTest < Test::Unit::TestCase
|
|
20
20
|
non_mock_object.stubs(:existing_method)
|
21
21
|
end
|
22
22
|
assert_passed(test_result)
|
23
|
-
assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method")
|
23
|
+
assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object.mocha_inspect}.existing_method")
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_should_warn_on_stubbing_method_on_non_mock_object
|
@@ -30,7 +30,7 @@ class StubbingOnNonMockObjectTest < Test::Unit::TestCase
|
|
30
30
|
non_mock_object.stubs(:existing_method)
|
31
31
|
end
|
32
32
|
assert_passed(test_result)
|
33
|
-
assert @logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method")
|
33
|
+
assert @logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object.mocha_inspect}.existing_method")
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_should_prevent_stubbing_method_on_non_mock_object
|
@@ -40,7 +40,7 @@ class StubbingOnNonMockObjectTest < Test::Unit::TestCase
|
|
40
40
|
non_mock_object.stubs(:existing_method)
|
41
41
|
end
|
42
42
|
assert_failed(test_result)
|
43
|
-
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on non-mock object: #{non_mock_object}.existing_method")
|
43
|
+
assert test_result.error_messages.include?("Mocha::StubbingError: stubbing method on non-mock object: #{non_mock_object.mocha_inspect}.existing_method")
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_should_default_to_allow_stubbing_method_on_non_mock_object
|
@@ -49,7 +49,7 @@ class StubbingOnNonMockObjectTest < Test::Unit::TestCase
|
|
49
49
|
non_mock_object.stubs(:existing_method)
|
50
50
|
end
|
51
51
|
assert_passed(test_result)
|
52
|
-
assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object}.existing_method")
|
52
|
+
assert !@logger.warnings.include?("stubbing method on non-mock object: #{non_mock_object.mocha_inspect}.existing_method")
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_should_allow_stubbing_method_on_mock_object
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'test/unit/testcase'
|
3
|
+
require 'minitest/unit'
|
4
|
+
|
5
|
+
class MiniTestResult
|
6
|
+
def self.parse_failure(raw)
|
7
|
+
matches = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m.match(raw)
|
8
|
+
return nil unless matches
|
9
|
+
Failure.new(matches[2], matches[3], [matches[4]], matches[5])
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_error(raw)
|
13
|
+
matches = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n.+ (.*)\n}m.match(raw)
|
14
|
+
return nil unless matches
|
15
|
+
Error.new(matches[2], matches[3], matches[4], [matches[5]])
|
16
|
+
end
|
17
|
+
|
18
|
+
class Failure
|
19
|
+
attr_reader :method, :test_case, :location, :message
|
20
|
+
def initialize(method, test_case, location, message)
|
21
|
+
@method, @test_case, @location, @message = method, test_case, location, message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Error
|
26
|
+
class Exception
|
27
|
+
attr_reader :message, :backtrace
|
28
|
+
def initialize(message, location)
|
29
|
+
@message, @backtrace = message, location
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :method, :test_case, :exception
|
34
|
+
def initialize(method, test_case, message, backtrace)
|
35
|
+
@method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(runner, test)
|
40
|
+
@runner, @test = runner, test
|
41
|
+
end
|
42
|
+
|
43
|
+
def failure_count
|
44
|
+
@runner.failures
|
45
|
+
end
|
46
|
+
|
47
|
+
def assertion_count
|
48
|
+
@test._assertions
|
49
|
+
end
|
50
|
+
|
51
|
+
def error_count
|
52
|
+
@runner.errors
|
53
|
+
end
|
54
|
+
|
55
|
+
def passed?
|
56
|
+
@test.passed?
|
57
|
+
end
|
58
|
+
|
59
|
+
def failures
|
60
|
+
@runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
|
61
|
+
end
|
62
|
+
|
63
|
+
def errors
|
64
|
+
@runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
|
65
|
+
end
|
66
|
+
|
67
|
+
def failure_messages
|
68
|
+
failures.map(&:message)
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_messages
|
72
|
+
errors.map { |e| e.exception.message }
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/test_runner.rb
CHANGED
@@ -1,23 +1,37 @@
|
|
1
|
-
require 'test/unit/testresult'
|
2
1
|
require 'test/unit/testcase'
|
3
2
|
|
3
|
+
if defined?(MiniTest)
|
4
|
+
require 'mocha/integration/mini_test'
|
5
|
+
require File.expand_path('../mini_test_result', __FILE__)
|
6
|
+
else
|
7
|
+
require 'test/unit/testresult'
|
8
|
+
end
|
9
|
+
|
4
10
|
module TestRunner
|
5
|
-
|
6
|
-
def run_as_test(test_result = Test::Unit::TestResult.new, &block)
|
11
|
+
def run_as_test(test_result = nil, &block)
|
7
12
|
test_class = Class.new(Test::Unit::TestCase) do
|
8
13
|
define_method(:test_me, &block)
|
9
14
|
end
|
10
15
|
test = test_class.new(:test_me)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
if defined?(Test::Unit::TestResult)
|
18
|
+
test_result ||= Test::Unit::TestResult.new
|
19
|
+
test.run(test_result) {}
|
20
|
+
class << test_result
|
21
|
+
attr_reader :failures, :errors
|
22
|
+
def failure_messages
|
23
|
+
failures.map { |failure| failure.message }
|
24
|
+
end
|
25
|
+
def error_messages
|
26
|
+
errors.map { |error| error.message }
|
27
|
+
end
|
19
28
|
end
|
29
|
+
else
|
30
|
+
runner = MiniTest::Unit.new
|
31
|
+
test.run(runner)
|
32
|
+
test_result = MiniTestResult.new(runner, test)
|
20
33
|
end
|
34
|
+
|
21
35
|
test_result
|
22
36
|
end
|
23
37
|
|
data/test/unit/central_test.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require "mocha/configuration"
|
3
|
+
|
4
|
+
class ConfigurationTest < Test::Unit::TestCase
|
5
|
+
def test_allow_temporarily_changes_config_when_given_block
|
6
|
+
Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
|
7
|
+
yielded = false
|
8
|
+
Mocha::Configuration.allow(:stubbing_method_unnecessarily) do
|
9
|
+
yielded = true
|
10
|
+
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
11
|
+
end
|
12
|
+
assert yielded
|
13
|
+
assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_prevent_temporarily_changes_config_when_given_block
|
17
|
+
Mocha::Configuration.allow(:stubbing_method_unnecessarily)
|
18
|
+
yielded = false
|
19
|
+
Mocha::Configuration.prevent(:stubbing_method_unnecessarily) do
|
20
|
+
yielded = true
|
21
|
+
assert Mocha::Configuration.prevent?(:stubbing_method_unnecessarily)
|
22
|
+
end
|
23
|
+
assert yielded
|
24
|
+
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_warn_when_temporarily_changes_config_when_given_block
|
28
|
+
Mocha::Configuration.allow(:stubbing_method_unnecessarily)
|
29
|
+
yielded = false
|
30
|
+
Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) do
|
31
|
+
yielded = true
|
32
|
+
assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
|
33
|
+
end
|
34
|
+
assert yielded
|
35
|
+
assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|