mocha 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.rdoc +3 -0
- data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
- data/{README → README.rdoc} +4 -4
- data/{RELEASE → RELEASE.rdoc} +18 -0
- data/Rakefile +19 -17
- data/lib/mocha.rb +1 -0
- data/lib/mocha/expectation.rb +37 -34
- 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 +23 -8
- 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_209.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/options.rb +1 -0
- data/lib/mocha/parameter_matchers/base.rb +50 -2
- 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 +3 -1
- 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 +1 -1
- 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 +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +1 -1
- 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 +1 -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 +41 -18
- data/COPYING +0 -3
@@ -7,33 +7,28 @@ module Mocha
|
|
7
7
|
|
8
8
|
module MiniTest
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
translated_exception
|
15
|
-
end
|
16
|
-
|
17
|
-
module Version131AndAbove
|
10
|
+
module Version140
|
11
|
+
def self.included(mod)
|
12
|
+
$stderr.puts "Monkey patching MiniTest v1.4.0" if $options['debug']
|
13
|
+
end
|
18
14
|
def run runner
|
19
15
|
assertion_counter = AssertionCounter.new(self)
|
20
16
|
result = '.'
|
21
|
-
name = (self.respond_to?(:name) ? self.name : self.__name__)
|
22
17
|
begin
|
23
18
|
begin
|
24
19
|
@passed = nil
|
25
20
|
self.setup
|
26
|
-
self.__send__
|
21
|
+
self.__send__ self.__name__
|
27
22
|
mocha_verify(assertion_counter)
|
28
23
|
@passed = true
|
29
24
|
rescue Exception => e
|
30
25
|
@passed = false
|
31
|
-
result = runner.puke(self.class,
|
26
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
32
27
|
ensure
|
33
28
|
begin
|
34
29
|
self.teardown
|
35
30
|
rescue Exception => e
|
36
|
-
result = runner.puke(self.class,
|
31
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
37
32
|
end
|
38
33
|
end
|
39
34
|
ensure
|
@@ -0,0 +1,56 @@
|
|
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 Version141
|
11
|
+
def self.included(mod)
|
12
|
+
$stderr.puts "Monkey patching MiniTest v1.4.1"
|
13
|
+
end
|
14
|
+
def run runner
|
15
|
+
trap 'INFO' do
|
16
|
+
warn '%s#%s %.2fs' % [self.class, self.__name__,
|
17
|
+
(Time.now - runner.start_time)]
|
18
|
+
runner.status $stderr
|
19
|
+
end
|
20
|
+
|
21
|
+
assertion_counter = AssertionCounter.new(self)
|
22
|
+
result = '.'
|
23
|
+
begin
|
24
|
+
begin
|
25
|
+
@passed = nil
|
26
|
+
self.setup
|
27
|
+
self.__send__ self.__name__
|
28
|
+
mocha_verify(assertion_counter)
|
29
|
+
@passed = true
|
30
|
+
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
31
|
+
raise
|
32
|
+
rescue Exception => e
|
33
|
+
@passed = false
|
34
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
35
|
+
ensure
|
36
|
+
begin
|
37
|
+
self.teardown
|
38
|
+
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
39
|
+
raise
|
40
|
+
rescue Exception => e
|
41
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
42
|
+
end
|
43
|
+
trap 'INFO', 'DEFAULT'
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
mocha_teardown
|
47
|
+
end
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 Version142AndAbove
|
11
|
+
def self.included(mod)
|
12
|
+
$stderr.puts "Monkey patching MiniTest >= v1.4.2" if $options['debug']
|
13
|
+
end
|
14
|
+
def run runner
|
15
|
+
trap 'INFO' do
|
16
|
+
warn '%s#%s %.2fs' % [self.class, self.__name__,
|
17
|
+
(Time.now - runner.start_time)]
|
18
|
+
runner.status $stderr
|
19
|
+
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
20
|
+
|
21
|
+
assertion_counter = AssertionCounter.new(self)
|
22
|
+
result = '.'
|
23
|
+
begin
|
24
|
+
begin
|
25
|
+
@passed = nil
|
26
|
+
self.setup
|
27
|
+
self.__send__ self.__name__
|
28
|
+
mocha_verify(assertion_counter)
|
29
|
+
@passed = true
|
30
|
+
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
31
|
+
raise
|
32
|
+
rescue Exception => e
|
33
|
+
@passed = false
|
34
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
35
|
+
ensure
|
36
|
+
begin
|
37
|
+
self.teardown
|
38
|
+
rescue *PASSTHROUGH_EXCEPTIONS
|
39
|
+
raise
|
40
|
+
rescue Exception => e
|
41
|
+
result = runner.puke(self.class, self.__name__, Mocha::Integration::MiniTest.translate(e))
|
42
|
+
end
|
43
|
+
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
mocha_teardown
|
47
|
+
end
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -3,7 +3,8 @@ require 'mocha/api'
|
|
3
3
|
if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
|
4
4
|
|
5
5
|
require 'mocha/integration/test_unit/gem_version_200'
|
6
|
-
require 'mocha/integration/test_unit/
|
6
|
+
require 'mocha/integration/test_unit/gem_version_201_to_202'
|
7
|
+
require 'mocha/integration/test_unit/gem_version_203_to_209'
|
7
8
|
require 'mocha/integration/test_unit/ruby_version_185_and_below'
|
8
9
|
require 'mocha/integration/test_unit/ruby_version_186_and_above'
|
9
10
|
|
@@ -17,20 +18,34 @@ if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
|
|
17
18
|
remove_method :run
|
18
19
|
|
19
20
|
test_unit_version = begin
|
20
|
-
|
21
|
+
load 'test/unit/version.rb'
|
21
22
|
Test::Unit::VERSION
|
22
23
|
rescue LoadError
|
23
24
|
'1.x'
|
24
25
|
end
|
25
26
|
|
26
|
-
if
|
27
|
+
if $options['debug']
|
28
|
+
$stderr.puts "Detected Ruby version: #{RUBY_VERSION}"
|
29
|
+
$stderr.puts "Detected Test::Unit version: #{test_unit_version}"
|
30
|
+
end
|
31
|
+
|
32
|
+
if (test_unit_version == '1.x') || (test_unit_version == '1.2.3')
|
33
|
+
if RUBY_VERSION < '1.8.6'
|
34
|
+
include Mocha::Integration::TestUnit::RubyVersion185AndBelow
|
35
|
+
else
|
36
|
+
include Mocha::Integration::TestUnit::RubyVersion186AndAbove
|
37
|
+
end
|
38
|
+
elsif (test_unit_version == '2.0.0')
|
27
39
|
include Mocha::Integration::TestUnit::GemVersion200
|
28
|
-
elsif test_unit_version >= '2.0.1'
|
29
|
-
include Mocha::Integration::TestUnit::
|
30
|
-
elsif
|
31
|
-
include Mocha::Integration::TestUnit::
|
40
|
+
elsif (test_unit_version >= '2.0.1') && (test_unit_version <= '2.0.2')
|
41
|
+
include Mocha::Integration::TestUnit::GemVersion201To202
|
42
|
+
elsif (test_unit_version >= '2.0.3') && (test_unit_version <= '2.0.9')
|
43
|
+
include Mocha::Integration::TestUnit::GemVersion203To209
|
44
|
+
elsif (test_unit_version > '2.0.9')
|
45
|
+
$stderr.puts "*** Test::Unit integration has not been verified but patching anyway ***" if $options['debug']
|
46
|
+
include Mocha::Integration::TestUnit::GemVersion203To209
|
32
47
|
else
|
33
|
-
|
48
|
+
$stderr.puts "*** No Mocha integration for Test::Unit version ***" if $options['debug']
|
34
49
|
end
|
35
50
|
|
36
51
|
end
|
data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb}
RENAMED
@@ -8,7 +8,10 @@ module Mocha
|
|
8
8
|
|
9
9
|
module TestUnit
|
10
10
|
|
11
|
-
module
|
11
|
+
module GemVersion201To202
|
12
|
+
def self.included(mod)
|
13
|
+
$stderr.puts "Monkey patching Test::Unit gem >= v2.0.1 and <= v2.0.2" if $options['debug']
|
14
|
+
end
|
12
15
|
def run(result)
|
13
16
|
assertion_counter = AssertionCounter.new(result)
|
14
17
|
begin
|
@@ -0,0 +1,52 @@
|
|
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 GemVersion203To209
|
12
|
+
def self.included(mod)
|
13
|
+
$stderr.puts "Monkey patching Test::Unit gem >= v2.0.3 and <= v2.0.9" if $options['debug']
|
14
|
+
end
|
15
|
+
def run(result)
|
16
|
+
assertion_counter = AssertionCounter.new(result)
|
17
|
+
begin
|
18
|
+
@_result = result
|
19
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
20
|
+
begin
|
21
|
+
begin
|
22
|
+
run_setup
|
23
|
+
run_test
|
24
|
+
mocha_verify(assertion_counter)
|
25
|
+
rescue Mocha::ExpectationError => e
|
26
|
+
add_failure(e.message, e.backtrace)
|
27
|
+
rescue Exception
|
28
|
+
@interrupted = true
|
29
|
+
raise unless handle_exception($!)
|
30
|
+
ensure
|
31
|
+
begin
|
32
|
+
run_teardown
|
33
|
+
rescue Exception
|
34
|
+
raise unless handle_exception($!)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
ensure
|
38
|
+
mocha_teardown
|
39
|
+
end
|
40
|
+
result.add_run
|
41
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
42
|
+
ensure
|
43
|
+
# @_result = nil # For test-spec's after_all :<
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -9,6 +9,9 @@ module Mocha
|
|
9
9
|
module TestUnit
|
10
10
|
|
11
11
|
module RubyVersion185AndBelow
|
12
|
+
def self.included(mod)
|
13
|
+
$stderr.puts "Monkey patching Test::Unit for Ruby <= v1.8.5" if $options['debug']
|
14
|
+
end
|
12
15
|
def run(result)
|
13
16
|
assertion_counter = AssertionCounter.new(result)
|
14
17
|
yield(Test::Unit::TestCase::STARTED, name)
|
@@ -9,6 +9,9 @@ module Mocha
|
|
9
9
|
module TestUnit
|
10
10
|
|
11
11
|
module RubyVersion186AndAbove
|
12
|
+
def self.included(mod)
|
13
|
+
$stderr.puts "Monkey patching Test::Unit for Ruby >= v1.8.6" if $options['debug']
|
14
|
+
end
|
12
15
|
def run(result)
|
13
16
|
assertion_counter = AssertionCounter.new(result)
|
14
17
|
yield(Test::Unit::TestCase::STARTED, name)
|
data/lib/mocha/mock.rb
CHANGED
data/lib/mocha/module_method.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
$options = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) { |hash, key| hash[key] = true; hash }
|
@@ -2,12 +2,60 @@ module Mocha
|
|
2
2
|
|
3
3
|
module ParameterMatchers
|
4
4
|
|
5
|
-
class Base
|
5
|
+
class Base
|
6
6
|
|
7
|
-
def to_matcher
|
7
|
+
def to_matcher # :nodoc:
|
8
8
|
self
|
9
9
|
end
|
10
10
|
|
11
|
+
# :call-seq: &(matcher) -> parameter_matcher
|
12
|
+
#
|
13
|
+
# A short hand way of specifying multiple matchers that should
|
14
|
+
# all match.
|
15
|
+
#
|
16
|
+
# Returns a new +AllOf+ parameter matcher combining the
|
17
|
+
# given matcher and the receiver.
|
18
|
+
#
|
19
|
+
# The following statements are equivalent:
|
20
|
+
# object = mock()
|
21
|
+
# object.expects(:run).with(all_of(has_key(:foo), has_key(:bar)))
|
22
|
+
# object.run(:foo => 'foovalue', :bar => 'barvalue')
|
23
|
+
#
|
24
|
+
# # with the shorthand
|
25
|
+
# object.expects(:run).with(has_key(:foo) & has_key(:bar))
|
26
|
+
# object.run(:foo => 'foovalue', :bar => 'barvalue)
|
27
|
+
def &(matcher)
|
28
|
+
AllOf.new(self, matcher)
|
29
|
+
end
|
30
|
+
|
31
|
+
# :call-seq: |(matcher) -> parameter_matcher
|
32
|
+
#
|
33
|
+
# A short hand way of specifying multiple matchers, only at least
|
34
|
+
# one of which should pass.
|
35
|
+
#
|
36
|
+
# Returns a new +AnyOf+ parameter matcher combining the
|
37
|
+
# given matcher and the receiver.
|
38
|
+
#
|
39
|
+
# The following statements are equivalent:
|
40
|
+
# object = mock()
|
41
|
+
# object.expects(:run).with(any_of(has_key(:foo), has_key(:bar)))
|
42
|
+
# object.run(:foo => 'foovalue')
|
43
|
+
#
|
44
|
+
# # with the shorthand
|
45
|
+
# object.expects(:run).with(has_key(:foo) | has_key(:bar))
|
46
|
+
# object.run(:foo => 'foovalue')
|
47
|
+
#
|
48
|
+
# This shorthand will not work with an implicit equals match. Instead,
|
49
|
+
# an explicit equals matcher should be used:
|
50
|
+
#
|
51
|
+
# object.expects(:run).with(equals(1) | equals(2))
|
52
|
+
# object.run(1) # passes
|
53
|
+
# object.run(2) # passes
|
54
|
+
# object.run(3) # fails
|
55
|
+
def |(matcher)
|
56
|
+
AnyOf.new(self, matcher)
|
57
|
+
end
|
58
|
+
|
11
59
|
end
|
12
60
|
|
13
61
|
end
|
data/test/acceptance/api_test.rb
CHANGED
@@ -1,153 +1,157 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
9
12
|
|
10
|
-
begin
|
11
|
-
|
12
|
-
rescue LoadError
|
13
|
-
|
14
|
-
end
|
13
|
+
begin
|
14
|
+
require 'minitest/unit'
|
15
|
+
rescue LoadError
|
16
|
+
# MiniTest not available
|
17
|
+
end
|
15
18
|
|
16
|
-
if defined?(MiniTest)
|
19
|
+
if defined?(MiniTest)
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
# monkey-patch MiniTest now that it has hopefully been loaded
|
22
|
+
require 'mocha/integration/mini_test'
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
64
|
|
34
|
-
def test_mocha_with_unexpected_invocation
|
35
|
-
mockee = mock()
|
36
|
-
mockee.blah
|
37
65
|
end
|
38
|
-
|
39
|
-
def test_stubba_with_fulfilled_expectation
|
40
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
41
|
-
stubbee.expects(:blah)
|
42
|
-
stubbee.blah
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_stubba_with_unfulfilled_expectation
|
46
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
47
|
-
stubbee.expects(:blah)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_mocha_with_matching_parameter
|
51
|
-
mockee = mock()
|
52
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
53
|
-
mockee.blah(:wibble => 1)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_mocha_with_non_matching_parameter
|
57
|
-
mockee = mock()
|
58
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
59
|
-
mockee.blah(:wobble => 2)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
66
|
|
64
|
-
|
67
|
+
class MiniTestTest < Test::Unit::TestCase
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
def setup
|
70
|
+
@output = StringIO.new
|
71
|
+
MiniTest::Unit.output = @output
|
72
|
+
@runner = MiniTest::Unit.new
|
73
|
+
end
|
71
74
|
|
72
|
-
|
75
|
+
attr_reader :runner
|
73
76
|
|
74
|
-
|
75
|
-
|
77
|
+
def test_should_pass_mocha_test
|
78
|
+
runner.run(%w(-n test_mocha_with_fulfilled_expectation))
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
assert_equal 0, runner.failures
|
81
|
+
assert_equal 0, runner.errors
|
82
|
+
assert_equal 1, runner.assertion_count
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
85
|
+
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
86
|
+
runner.run(%w(-n test_mocha_with_unfulfilled_expectation))
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
+
runner.run(%w(-n test_mocha_with_unexpected_invocation))
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
+
runner.run(%w(-n test_stubba_with_fulfilled_expectation))
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
106
|
+
assert_equal 0, runner.failures
|
107
|
+
assert_equal 0, runner.errors
|
108
|
+
assert_equal 1, runner.assertion_count
|
109
|
+
end
|
107
110
|
|
108
|
-
|
109
|
-
|
111
|
+
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
112
|
+
runner.run(%w(-n test_stubba_with_unfulfilled_expectation))
|
110
113
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
+
runner.run(%w(-n test_mocha_with_matching_parameter))
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
123
|
+
assert_equal 0, runner.failures
|
124
|
+
assert_equal 0, runner.errors
|
125
|
+
assert_equal 1, runner.assertion_count
|
126
|
+
end
|
124
127
|
|
125
|
-
|
126
|
-
|
128
|
+
def test_should_fail_mocha_test_with_non_matching_parameter
|
129
|
+
runner.run(%w(-n test_mocha_with_non_matching_parameter))
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
133
136
|
|
134
|
-
|
137
|
+
private
|
135
138
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
def output
|
140
|
+
@output.rewind
|
141
|
+
@output.read
|
142
|
+
end
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
def assert_unexpected_invocation
|
145
|
+
assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
|
146
|
+
end
|
147
|
+
|
148
|
+
def assert_not_all_expectation_were_satisfied
|
149
|
+
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
150
|
+
end
|
144
151
|
|
145
|
-
def assert_not_all_expectation_were_satisfied
|
146
|
-
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
147
152
|
end
|
148
153
|
|
154
|
+
else
|
155
|
+
$stderr.puts "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
149
156
|
end
|
150
|
-
|
151
|
-
else
|
152
|
-
warn "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
153
157
|
end
|