mocha 0.12.10 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +22 -0
- data/COPYING.md +3 -0
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +0 -0
- data/README.md +230 -0
- data/{RELEASE.rdoc → RELEASE.md} +61 -56
- data/Rakefile +45 -37
- data/build-matrix.rb +16 -4
- data/lib/mocha.rb +6 -2
- data/lib/mocha/api.rb +13 -16
- data/lib/mocha/class_method.rb +7 -3
- data/lib/mocha/class_methods.rb +63 -0
- data/lib/mocha/debug.rb +11 -0
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation_error.rb +5 -0
- data/lib/mocha/expectation_error_factory.rb +19 -0
- data/lib/mocha/hooks.rb +43 -0
- data/lib/mocha/integration.rb +6 -38
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test.rb +42 -60
- data/lib/mocha/integration/mini_test/adapter.rb +54 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +0 -6
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +32 -25
- data/lib/mocha/integration/mini_test/version_140.rb +32 -26
- data/lib/mocha/integration/mini_test/version_141.rb +40 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +40 -34
- data/lib/mocha/integration/mini_test/version_200.rb +41 -35
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +41 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +49 -43
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +53 -47
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +43 -37
- data/lib/mocha/integration/monkey_patcher.rb +18 -0
- data/lib/mocha/integration/test_unit.rb +38 -45
- data/lib/mocha/integration/test_unit/adapter.rb +51 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +65 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +36 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +37 -30
- data/lib/mocha/method_matcher.rb +1 -1
- data/lib/mocha/module_methods.rb +14 -0
- data/lib/mocha/{object.rb → object_methods.rb} +0 -83
- data/lib/mocha/setup.rb +10 -0
- data/lib/mocha/standalone.rb +3 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha_standalone.rb +3 -1
- data/mocha.gemspec +16 -9
- 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/exception_rescue_test.rb +1 -1
- data/test/acceptance/expectations_on_multiple_methods_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/issue_65_test.rb +1 -1
- data/test/acceptance/issue_70_test.rb +1 -1
- 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/multiple_expectations_failure_message_test.rb +1 -1
- data/test/acceptance/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +1 -1
- data/test/acceptance/partial_mocks_test.rb +1 -1
- data/test/acceptance/raise_exception_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 +1 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +1 -1
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_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_frozen_object_test.rb +1 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +1 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_nil_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +1 -1
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -3
- data/test/acceptance/throw_test.rb +1 -1
- data/test/acceptance/unstubbing_test.rb +1 -1
- data/test/integration/mini_test_test.rb +9 -0
- data/test/integration/shared_tests.rb +174 -0
- data/test/integration/test_unit_test.rb +9 -0
- data/test/mini_test_result.rb +0 -1
- data/test/test_runner.rb +14 -14
- data/test/unit/class_methods_test.rb +40 -0
- data/test/unit/method_matcher_test.rb +5 -0
- data/test/unit/mock_test.rb +6 -0
- data/test/unit/module_methods_test.rb +19 -0
- data/test/unit/object_methods_test.rb +45 -0
- metadata +45 -74
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -56
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.3.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.4.2.0 +0 -7
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_330_to_410.rb +0 -65
- data/lib/mocha/integration/mini_test/version_420_to_433.rb +0 -70
- data/lib/mocha/integration/mini_test/version_440.rb +0 -70
- data/lib/mocha/integration/mini_test/version_450_to_461.rb +0 -72
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_254.rb +0 -58
- data/lib/mocha/options.rb +0 -1
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/unit/object_test.rb +0 -92
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'mocha/integration/mini_test/assertion_counter'
|
2
|
-
require 'mocha/expectation_error'
|
3
|
-
|
4
|
-
module Mocha
|
5
|
-
|
6
|
-
module Integration
|
7
|
-
|
8
|
-
module MiniTest
|
9
|
-
|
10
|
-
module Version450To461
|
11
|
-
def self.included(mod)
|
12
|
-
$stderr.puts "Monkey patching MiniTest >= v4.5.0 <= v4.6.1" if $mocha_options['debug']
|
13
|
-
end
|
14
|
-
def run runner
|
15
|
-
trap "INFO" do
|
16
|
-
runner.report.each_with_index do |msg, i|
|
17
|
-
warn "\n%3d) %s" % [i + 1, msg]
|
18
|
-
end
|
19
|
-
warn ''
|
20
|
-
time = runner.start_time ? Time.now - runner.start_time : 0
|
21
|
-
warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
|
22
|
-
runner.status $stderr
|
23
|
-
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
24
|
-
start_time = Time.now
|
25
|
-
assertion_counter = AssertionCounter.new(self)
|
26
|
-
result = ""
|
27
|
-
begin
|
28
|
-
begin
|
29
|
-
@passed = nil
|
30
|
-
self.before_setup
|
31
|
-
self.setup
|
32
|
-
self.after_setup
|
33
|
-
self.run_test self.__name__
|
34
|
-
mocha_verify(assertion_counter)
|
35
|
-
result = "." unless io?
|
36
|
-
time = Time.now - start_time
|
37
|
-
runner.record self.class, self.__name__, self._assertions, time, nil
|
38
|
-
@passed = true
|
39
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
40
|
-
raise
|
41
|
-
rescue Exception => e
|
42
|
-
@passed = ::MiniTest::Skip === e
|
43
|
-
time = Time.now - start_time
|
44
|
-
runner.record self.class, self.__name__, self._assertions, time, e
|
45
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
46
|
-
ensure
|
47
|
-
%w{ before_teardown teardown after_teardown }.each do |hook|
|
48
|
-
begin
|
49
|
-
self.send hook
|
50
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
51
|
-
raise
|
52
|
-
rescue Exception => e
|
53
|
-
@passed = false
|
54
|
-
translated_exception = Mocha::Integration::MiniTest.translate(e)
|
55
|
-
runner.record self.class, self.__name__, self._assertions, time, translated_exception
|
56
|
-
result = runner.puke self.class, self.__name__, translated_exception
|
57
|
-
end
|
58
|
-
end
|
59
|
-
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
60
|
-
end
|
61
|
-
ensure
|
62
|
-
mocha_teardown
|
63
|
-
end
|
64
|
-
result
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Mocha
|
2
|
-
|
3
|
-
module Integration
|
4
|
-
|
5
|
-
module TestUnit
|
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
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'mocha/integration/test_unit/assertion_counter'
|
3
|
-
require 'mocha/expectation_error'
|
4
|
-
|
5
|
-
module Mocha
|
6
|
-
|
7
|
-
module Integration
|
8
|
-
|
9
|
-
module TestUnit
|
10
|
-
|
11
|
-
module GemVersion230To254
|
12
|
-
def self.included(mod)
|
13
|
-
$stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.5.4" if $mocha_options['debug']
|
14
|
-
end
|
15
|
-
def run(result)
|
16
|
-
assertion_counter = AssertionCounter.new(result)
|
17
|
-
begin
|
18
|
-
@internal_data.test_started
|
19
|
-
@_result = result
|
20
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
21
|
-
yield(Test::Unit::TestCase::STARTED_OBJECT, self)
|
22
|
-
begin
|
23
|
-
begin
|
24
|
-
run_setup
|
25
|
-
run_test
|
26
|
-
run_cleanup
|
27
|
-
mocha_verify(assertion_counter)
|
28
|
-
add_pass
|
29
|
-
rescue Mocha::ExpectationError => e
|
30
|
-
add_failure(e.message, e.backtrace)
|
31
|
-
rescue Exception
|
32
|
-
@internal_data.interrupted
|
33
|
-
raise unless handle_exception($!)
|
34
|
-
ensure
|
35
|
-
begin
|
36
|
-
run_teardown
|
37
|
-
rescue Exception
|
38
|
-
raise unless handle_exception($!)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
ensure
|
42
|
-
mocha_teardown
|
43
|
-
end
|
44
|
-
@internal_data.test_finished
|
45
|
-
result.add_run
|
46
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
47
|
-
yield(Test::Unit::TestCase::FINISHED_OBJECT, self)
|
48
|
-
ensure
|
49
|
-
# @_result = nil # For test-spec's after_all :<
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
data/lib/mocha/options.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
$mocha_options = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) { |hash, key| hash[key] = true; hash }
|
data/test/acceptance/api_test.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha_standalone'
|
3
|
-
require 'simple_counter'
|
4
|
-
|
5
|
-
class NotATestUnitAssertionFailedError < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
class NotATestUnitTestCase
|
9
|
-
|
10
|
-
include Mocha::API
|
11
|
-
|
12
|
-
attr_reader :assertion_counter
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@assertion_counter = SimpleCounter.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def run(test_method)
|
19
|
-
mocha_setup
|
20
|
-
begin
|
21
|
-
prepare
|
22
|
-
begin
|
23
|
-
send(test_method)
|
24
|
-
mocha_verify(@assertion_counter)
|
25
|
-
rescue Mocha::ExpectationError => e
|
26
|
-
new_error = NotATestUnitAssertionFailedError.new(e.message)
|
27
|
-
new_error.set_backtrace(e.backtrace)
|
28
|
-
raise new_error
|
29
|
-
ensure
|
30
|
-
cleanup
|
31
|
-
end
|
32
|
-
ensure
|
33
|
-
mocha_teardown
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def prepare
|
38
|
-
end
|
39
|
-
|
40
|
-
def cleanup
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
class SampleTest < NotATestUnitTestCase
|
46
|
-
|
47
|
-
def mock_object_with_fulfilled_expectation
|
48
|
-
mockee = mock()
|
49
|
-
mockee.expects(:blah)
|
50
|
-
mockee.blah
|
51
|
-
end
|
52
|
-
|
53
|
-
def mock_object_with_unfulfilled_expectation
|
54
|
-
mockee = mock()
|
55
|
-
mockee.expects(:blah)
|
56
|
-
end
|
57
|
-
|
58
|
-
def mock_object_with_unexpected_invocation
|
59
|
-
mockee = mock()
|
60
|
-
mockee.blah
|
61
|
-
end
|
62
|
-
|
63
|
-
def real_object_with_fulfilled_expectation
|
64
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
65
|
-
stubbee.expects(:blah)
|
66
|
-
stubbee.blah
|
67
|
-
end
|
68
|
-
|
69
|
-
def real_object_with_unfulfilled_expectation
|
70
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
71
|
-
stubbee.expects(:blah)
|
72
|
-
end
|
73
|
-
|
74
|
-
def mock_object_with_matching_parameter
|
75
|
-
mockee = mock()
|
76
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
77
|
-
mockee.blah(:wibble => 1)
|
78
|
-
end
|
79
|
-
|
80
|
-
def mock_object_with_non_matching_parameter
|
81
|
-
mockee = mock()
|
82
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
83
|
-
mockee.blah(:wobble => 2)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
require 'test/unit'
|
89
|
-
|
90
|
-
class APITest < Test::Unit::TestCase
|
91
|
-
|
92
|
-
attr_reader :sample_test
|
93
|
-
|
94
|
-
include AcceptanceTest
|
95
|
-
|
96
|
-
def setup
|
97
|
-
@sample_test = SampleTest.new
|
98
|
-
setup_acceptance_test
|
99
|
-
end
|
100
|
-
|
101
|
-
def teardown
|
102
|
-
teardown_acceptance_test
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_should_pass_mock_object_test
|
106
|
-
assert_nothing_raised { sample_test.run(:mock_object_with_fulfilled_expectation) }
|
107
|
-
assert_equal 1, sample_test.assertion_counter.count
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_should_fail_mock_object_test_due_to_unfulfilled_exception
|
111
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_unfulfilled_expectation) }
|
112
|
-
assert_equal 1, sample_test.assertion_counter.count
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_should_fail_mock_object_test_due_to_unexpected_invocation
|
116
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_unexpected_invocation) }
|
117
|
-
assert_equal 0, sample_test.assertion_counter.count
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_should_pass_real_object_test
|
121
|
-
assert_nothing_raised { sample_test.run(:real_object_with_fulfilled_expectation) }
|
122
|
-
assert_equal 1, sample_test.assertion_counter.count
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_should_fail_real_object_test
|
126
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:real_object_with_unfulfilled_expectation) }
|
127
|
-
assert_equal 1, sample_test.assertion_counter.count
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_should_pass_mock_object_test_with_matching_parameter
|
131
|
-
assert_nothing_raised { sample_test.run(:mock_object_with_matching_parameter) }
|
132
|
-
assert_equal 1, sample_test.assertion_counter.count
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_should_fail_mock_object_test_with_non_matching_parameter
|
136
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_non_matching_parameter) }
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
|
3
|
-
if defined?(MiniTest)
|
4
|
-
$stderr.puts "TODO: Running suite with MiniTest, running the MiniTestAdapterTest results in an error so skipping it for now."
|
5
|
-
else
|
6
|
-
begin
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'minitest'
|
9
|
-
rescue Gem::LoadError
|
10
|
-
# MiniTest gem not available
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'minitest/unit'
|
15
|
-
rescue LoadError
|
16
|
-
# MiniTest not available
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined?(MiniTest)
|
20
|
-
|
21
|
-
# monkey-patch MiniTest now that it has hopefully been loaded
|
22
|
-
require 'mocha/integration/mini_test'
|
23
|
-
|
24
|
-
class MiniTestSampleTest < MiniTest::Unit::TestCase
|
25
|
-
|
26
|
-
def test_mocha_with_fulfilled_expectation
|
27
|
-
mockee = mock()
|
28
|
-
mockee.expects(:blah)
|
29
|
-
mockee.blah
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_mocha_with_unfulfilled_expectation
|
33
|
-
mockee = mock()
|
34
|
-
mockee.expects(:blah)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_mocha_with_unexpected_invocation
|
38
|
-
mockee = mock()
|
39
|
-
mockee.blah
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stubba_with_fulfilled_expectation
|
43
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
44
|
-
stubbee.expects(:blah)
|
45
|
-
stubbee.blah
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_stubba_with_unfulfilled_expectation
|
49
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
50
|
-
stubbee.expects(:blah)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mocha_with_matching_parameter
|
54
|
-
mockee = mock()
|
55
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
56
|
-
mockee.blah(:wibble => 1)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_mocha_with_non_matching_parameter
|
60
|
-
mockee = mock()
|
61
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
62
|
-
mockee.blah(:wobble => 2)
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
class MiniTestTest < Test::Unit::TestCase
|
68
|
-
|
69
|
-
def setup
|
70
|
-
@output = StringIO.new
|
71
|
-
MiniTest::Unit.output = @output
|
72
|
-
@runner = MiniTest::Unit.new
|
73
|
-
end
|
74
|
-
|
75
|
-
attr_reader :runner
|
76
|
-
|
77
|
-
def test_should_pass_mocha_test
|
78
|
-
run_test_method :test_mocha_with_fulfilled_expectation
|
79
|
-
|
80
|
-
assert_equal 0, runner.failures
|
81
|
-
assert_equal 0, runner.errors
|
82
|
-
assert_equal 1, runner.assertion_count
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
86
|
-
run_test_method :test_mocha_with_unfulfilled_expectation
|
87
|
-
|
88
|
-
assert_equal 1, runner.failures
|
89
|
-
assert_equal 0, runner.errors
|
90
|
-
assert_equal 1, runner.assertion_count
|
91
|
-
assert_not_all_expectation_were_satisfied
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
95
|
-
run_test_method :test_mocha_with_unexpected_invocation
|
96
|
-
|
97
|
-
assert_equal 1, runner.failures
|
98
|
-
assert_equal 0, runner.errors
|
99
|
-
assert_equal 0, runner.assertion_count
|
100
|
-
assert_unexpected_invocation
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_pass_stubba_test
|
104
|
-
run_test_method :test_stubba_with_fulfilled_expectation
|
105
|
-
|
106
|
-
assert_equal 0, runner.failures
|
107
|
-
assert_equal 0, runner.errors
|
108
|
-
assert_equal 1, runner.assertion_count
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
112
|
-
run_test_method :test_stubba_with_unfulfilled_expectation
|
113
|
-
|
114
|
-
assert_equal 1, runner.failures
|
115
|
-
assert_equal 0, runner.errors
|
116
|
-
assert_equal 1, runner.assertion_count
|
117
|
-
assert_not_all_expectation_were_satisfied
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_should_pass_mocha_test_with_matching_parameter
|
121
|
-
run_test_method :test_mocha_with_matching_parameter
|
122
|
-
|
123
|
-
assert_equal 0, runner.failures
|
124
|
-
assert_equal 0, runner.errors
|
125
|
-
assert_equal 1, runner.assertion_count
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_should_fail_mocha_test_with_non_matching_parameter
|
129
|
-
run_test_method :test_mocha_with_non_matching_parameter
|
130
|
-
|
131
|
-
assert_equal 1, runner.failures
|
132
|
-
assert_equal 0, runner.errors
|
133
|
-
assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified
|
134
|
-
assert_unexpected_invocation
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def run_test_method(method_name)
|
140
|
-
run_method = (MiniTest::Unit::VERSION >= "2.1.0") ? :_run : :run
|
141
|
-
runner.send(run_method, ["-n", method_name.to_s])
|
142
|
-
end
|
143
|
-
|
144
|
-
def output
|
145
|
-
@output.rewind
|
146
|
-
@output.read
|
147
|
-
end
|
148
|
-
|
149
|
-
def assert_unexpected_invocation
|
150
|
-
assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
|
151
|
-
end
|
152
|
-
|
153
|
-
def assert_not_all_expectation_were_satisfied
|
154
|
-
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
else
|
160
|
-
$stderr.puts "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
161
|
-
end
|
162
|
-
end
|