mocha 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/COPYING.rdoc +3 -0
  2. data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
  3. data/{README → README.rdoc} +4 -4
  4. data/{RELEASE → RELEASE.rdoc} +18 -0
  5. data/Rakefile +19 -17
  6. data/lib/mocha.rb +1 -0
  7. data/lib/mocha/expectation.rb +37 -34
  8. data/lib/mocha/integration/mini_test.rb +27 -2
  9. data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
  10. data/lib/mocha/integration/mini_test/version_13.rb +44 -0
  11. data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_140.rb} +7 -12
  12. data/lib/mocha/integration/mini_test/version_141.rb +56 -0
  13. data/lib/mocha/integration/mini_test/version_142_and_above.rb +56 -0
  14. data/lib/mocha/integration/test_unit.rb +23 -8
  15. data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
  16. data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
  17. data/lib/mocha/integration/test_unit/gem_version_203_to_209.rb +52 -0
  18. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
  19. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
  20. data/lib/mocha/mock.rb +0 -1
  21. data/lib/mocha/module_method.rb +1 -1
  22. data/lib/mocha/options.rb +1 -0
  23. data/lib/mocha/parameter_matchers/base.rb +50 -2
  24. data/test/acceptance/acceptance_test_helper.rb +1 -1
  25. data/test/acceptance/api_test.rb +1 -1
  26. data/test/acceptance/bug_18914_test.rb +1 -1
  27. data/test/acceptance/bug_21465_test.rb +1 -1
  28. data/test/acceptance/bug_21563_test.rb +1 -1
  29. data/test/acceptance/expected_invocation_count_test.rb +1 -1
  30. data/test/acceptance/failure_messages_test.rb +1 -1
  31. data/test/acceptance/minitest_test.rb +128 -124
  32. data/test/acceptance/mocha_example_test.rb +1 -1
  33. data/test/acceptance/mocha_test_result_test.rb +1 -1
  34. data/test/acceptance/mock_test.rb +1 -1
  35. data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
  36. data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
  37. data/test/acceptance/optional_parameters_test.rb +1 -1
  38. data/test/acceptance/parameter_matcher_test.rb +38 -1
  39. data/test/acceptance/partial_mocks_test.rb +1 -1
  40. data/test/acceptance/return_value_test.rb +1 -1
  41. data/test/acceptance/sequence_test.rb +1 -1
  42. data/test/acceptance/states_test.rb +1 -1
  43. data/test/acceptance/stub_any_instance_method_test.rb +5 -2
  44. data/test/acceptance/stub_class_method_test.rb +5 -2
  45. data/test/acceptance/stub_everything_test.rb +1 -1
  46. data/test/acceptance/stub_instance_method_test.rb +5 -2
  47. data/test/acceptance/stub_module_method_test.rb +3 -3
  48. data/test/acceptance/stub_test.rb +1 -1
  49. data/test/acceptance/stubba_example_test.rb +1 -1
  50. data/test/acceptance/stubba_test.rb +1 -1
  51. data/test/acceptance/stubba_test_result_test.rb +1 -1
  52. data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
  53. data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
  54. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
  55. data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
  56. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
  57. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
  58. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  59. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  60. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  61. data/test/mini_test_result.rb +74 -0
  62. data/test/test_helper.rb +3 -1
  63. data/test/test_runner.rb +25 -11
  64. data/test/unit/any_instance_method_test.rb +1 -1
  65. data/test/unit/array_inspect_test.rb +1 -1
  66. data/test/unit/backtrace_filter_test.rb +1 -1
  67. data/test/unit/cardinality_test.rb +1 -1
  68. data/test/unit/central_test.rb +1 -1
  69. data/test/unit/change_state_side_effect_test.rb +1 -1
  70. data/test/unit/class_method_test.rb +1 -1
  71. data/test/unit/configuration_test.rb +1 -1
  72. data/test/unit/date_time_inspect_test.rb +1 -1
  73. data/test/unit/exception_raiser_test.rb +1 -1
  74. data/test/unit/expectation_list_test.rb +1 -1
  75. data/test/unit/expectation_test.rb +1 -1
  76. data/test/unit/hash_inspect_test.rb +1 -1
  77. data/test/unit/in_state_ordering_constraint_test.rb +1 -1
  78. data/test/unit/metaclass_test.rb +1 -1
  79. data/test/unit/method_matcher_test.rb +1 -1
  80. data/test/unit/mock_test.rb +1 -1
  81. data/test/unit/mockery_test.rb +1 -1
  82. data/test/unit/multiple_yields_test.rb +1 -1
  83. data/test/unit/no_yields_test.rb +1 -1
  84. data/test/unit/object_inspect_test.rb +9 -8
  85. data/test/unit/object_test.rb +1 -1
  86. data/test/unit/parameter_matchers/all_of_test.rb +1 -1
  87. data/test/unit/parameter_matchers/any_of_test.rb +1 -1
  88. data/test/unit/parameter_matchers/anything_test.rb +1 -1
  89. data/test/unit/parameter_matchers/equals_test.rb +1 -1
  90. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  91. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  92. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  93. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  94. data/test/unit/parameter_matchers/includes_test.rb +1 -1
  95. data/test/unit/parameter_matchers/instance_of_test.rb +1 -1
  96. data/test/unit/parameter_matchers/is_a_test.rb +1 -1
  97. data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
  98. data/test/unit/parameter_matchers/not_test.rb +1 -1
  99. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
  100. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  101. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
  102. data/test/unit/parameters_matcher_test.rb +1 -1
  103. data/test/unit/return_values_test.rb +1 -1
  104. data/test/unit/sequence_test.rb +1 -1
  105. data/test/unit/single_return_value_test.rb +1 -1
  106. data/test/unit/single_yield_test.rb +1 -1
  107. data/test/unit/state_machine_test.rb +1 -1
  108. data/test/unit/string_inspect_test.rb +1 -1
  109. data/test/unit/yield_parameters_test.rb +1 -1
  110. metadata +41 -18
  111. data/COPYING +0 -3
@@ -7,33 +7,28 @@ module Mocha
7
7
 
8
8
  module MiniTest
9
9
 
10
- def self.translate(exception)
11
- return exception unless exception.kind_of?(::Mocha::ExpectationError)
12
- translated_exception = ::MiniTest::Assertion.new(exception.message)
13
- translated_exception.set_backtrace(exception.backtrace)
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__ name
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, name, Mocha::Integration::MiniTest.translate(e))
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, name, Mocha::Integration::MiniTest.translate(e))
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/gem_version_201_and_above'
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
- require 'test/unit/version'
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 test_unit_version == '2.0.0'
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::GemVersion201AndAbove
30
- elsif RUBY_VERSION < '1.8.6'
31
- include Mocha::Integration::TestUnit::RubyVersion185AndBelow
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
- include Mocha::Integration::TestUnit::RubyVersion186AndAbove
48
+ $stderr.puts "*** No Mocha integration for Test::Unit version ***" if $options['debug']
34
49
  end
35
50
 
36
51
  end
@@ -9,6 +9,9 @@ module Mocha
9
9
  module TestUnit
10
10
 
11
11
  module GemVersion200
12
+ def self.included(mod)
13
+ $stderr.puts "Monkey patching Test::Unit gem v2.0.0" if $options['debug']
14
+ end
12
15
  def run(result)
13
16
  assertion_counter = AssertionCounter.new(result)
14
17
  begin
@@ -8,7 +8,10 @@ module Mocha
8
8
 
9
9
  module TestUnit
10
10
 
11
- module GemVersion201AndAbove
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)
@@ -2,7 +2,6 @@ require 'mocha/expectation'
2
2
  require 'mocha/expectation_list'
3
3
  require 'mocha/metaclass'
4
4
  require 'mocha/names'
5
- require 'mocha/mockery'
6
5
  require 'mocha/method_matcher'
7
6
  require 'mocha/parameters_matcher'
8
7
  require 'mocha/unexpected_invocation'
@@ -1,4 +1,4 @@
1
- require 'mocha/module_method'
1
+ require 'mocha/class_method'
2
2
 
3
3
  module Mocha
4
4
 
@@ -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 # :nodoc:
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
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "..", "test_helper")
1
+ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'test_runner'
3
3
  require 'mocha/configuration'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha_standalone'
3
3
  require 'simple_counter'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class Bug18914Test < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class Bug21465Test < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class Bug21563Test < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class ExpectedInvocationCountTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class FailureMessagesTest < Test::Unit::TestCase
@@ -1,153 +1,157 @@
1
- require File.join(File.dirname(__FILE__), "acceptance_test_helper")
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
 
3
- begin
4
- require 'rubygems'
5
- gem 'minitest'
6
- rescue Gem::LoadError
7
- # MiniTest gem not available
8
- end
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
- require 'minitest/unit'
12
- rescue LoadError
13
- # MiniTest not available
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
- # monkey-patch MiniTest now that it has hopefully been loaded
19
- require 'mocha/integration/mini_test'
21
+ # monkey-patch MiniTest now that it has hopefully been loaded
22
+ require 'mocha/integration/mini_test'
20
23
 
21
- class MiniTestSampleTest < MiniTest::Unit::TestCase
22
-
23
- def test_mocha_with_fulfilled_expectation
24
- mockee = mock()
25
- mockee.expects(:blah)
26
- mockee.blah
27
- end
28
-
29
- def test_mocha_with_unfulfilled_expectation
30
- mockee = mock()
31
- mockee.expects(:blah)
32
- end
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
- class MiniTestTest < Test::Unit::TestCase
67
+ class MiniTestTest < Test::Unit::TestCase
65
68
 
66
- def setup
67
- @output = StringIO.new
68
- MiniTest::Unit.output = @output
69
- @runner = MiniTest::Unit.new
70
- end
69
+ def setup
70
+ @output = StringIO.new
71
+ MiniTest::Unit.output = @output
72
+ @runner = MiniTest::Unit.new
73
+ end
71
74
 
72
- attr_reader :runner
75
+ attr_reader :runner
73
76
 
74
- def test_should_pass_mocha_test
75
- runner.run(%w(-n test_mocha_with_fulfilled_expectation))
77
+ def test_should_pass_mocha_test
78
+ runner.run(%w(-n test_mocha_with_fulfilled_expectation))
76
79
 
77
- assert_equal 0, runner.failures
78
- assert_equal 0, runner.errors
79
- assert_equal 1, runner.assertion_count
80
- end
80
+ assert_equal 0, runner.failures
81
+ assert_equal 0, runner.errors
82
+ assert_equal 1, runner.assertion_count
83
+ end
81
84
 
82
- def test_should_fail_mocha_test_due_to_unfulfilled_expectation
83
- runner.run(%w(-n test_mocha_with_unfulfilled_expectation))
85
+ def test_should_fail_mocha_test_due_to_unfulfilled_expectation
86
+ runner.run(%w(-n test_mocha_with_unfulfilled_expectation))
84
87
 
85
- assert_equal 1, runner.failures
86
- assert_equal 0, runner.errors
87
- assert_equal 1, runner.assertion_count
88
- assert_not_all_expectation_were_satisfied
89
- end
90
-
91
- def test_should_fail_mocha_test_due_to_unexpected_invocation
92
- runner.run(%w(-n test_mocha_with_unexpected_invocation))
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
- assert_equal 1, runner.failures
95
- assert_equal 0, runner.errors
96
- assert_equal 0, runner.assertion_count
97
- assert_unexpected_invocation
98
- end
99
-
100
- def test_should_pass_stubba_test
101
- runner.run(%w(-n test_stubba_with_fulfilled_expectation))
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
- assert_equal 0, runner.failures
104
- assert_equal 0, runner.errors
105
- assert_equal 1, runner.assertion_count
106
- end
106
+ assert_equal 0, runner.failures
107
+ assert_equal 0, runner.errors
108
+ assert_equal 1, runner.assertion_count
109
+ end
107
110
 
108
- def test_should_fail_stubba_test_due_to_unfulfilled_expectation
109
- runner.run(%w(-n test_stubba_with_unfulfilled_expectation))
111
+ def test_should_fail_stubba_test_due_to_unfulfilled_expectation
112
+ runner.run(%w(-n test_stubba_with_unfulfilled_expectation))
110
113
 
111
- assert_equal 1, runner.failures
112
- assert_equal 0, runner.errors
113
- assert_equal 1, runner.assertion_count
114
- assert_not_all_expectation_were_satisfied
115
- end
116
-
117
- def test_should_pass_mocha_test_with_matching_parameter
118
- runner.run(%w(-n test_mocha_with_matching_parameter))
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
- assert_equal 0, runner.failures
121
- assert_equal 0, runner.errors
122
- assert_equal 1, runner.assertion_count
123
- end
123
+ assert_equal 0, runner.failures
124
+ assert_equal 0, runner.errors
125
+ assert_equal 1, runner.assertion_count
126
+ end
124
127
 
125
- def test_should_fail_mocha_test_with_non_matching_parameter
126
- runner.run(%w(-n test_mocha_with_non_matching_parameter))
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
- assert_equal 1, runner.failures
129
- assert_equal 0, runner.errors
130
- assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified
131
- assert_unexpected_invocation
132
- end
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
- private
137
+ private
135
138
 
136
- def output
137
- @output.rewind
138
- @output.read
139
- end
139
+ def output
140
+ @output.rewind
141
+ @output.read
142
+ end
140
143
 
141
- def assert_unexpected_invocation
142
- assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
143
- end
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