mocha 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/RELEASE.rdoc +9 -1
  2. data/{Gemfile.minitest.1.3.0 → gemfiles/Gemfile.minitest.1.3.0} +1 -1
  3. data/{Gemfile.minitest.1.4.0 → gemfiles/Gemfile.minitest.1.4.0} +1 -1
  4. data/{Gemfile.minitest.1.4.1 → gemfiles/Gemfile.minitest.1.4.1} +2 -2
  5. data/{Gemfile.minitest.1.4.2 → gemfiles/Gemfile.minitest.1.4.2} +2 -2
  6. data/{Gemfile.minitest.2.0.0 → gemfiles/Gemfile.minitest.2.0.0} +2 -2
  7. data/{Gemfile.minitest.2.0.1 → gemfiles/Gemfile.minitest.2.0.1} +2 -2
  8. data/{Gemfile.minitest.2.3.0 → gemfiles/Gemfile.minitest.2.3.0} +1 -1
  9. data/{Gemfile.minitest.latest → gemfiles/Gemfile.minitest.latest} +1 -1
  10. data/{Gemfile.test-unit.2.0.0 → gemfiles/Gemfile.test-unit.2.0.0} +2 -2
  11. data/{Gemfile.test-unit.2.0.1 → gemfiles/Gemfile.test-unit.2.0.1} +2 -2
  12. data/{Gemfile.test-unit.2.0.3 → gemfiles/Gemfile.test-unit.2.0.3} +1 -1
  13. data/{Gemfile.test-unit.latest → gemfiles/Gemfile.test-unit.latest} +2 -2
  14. data/lib/mocha/any_instance_method.rb +5 -1
  15. data/lib/mocha/class_method.rb +7 -0
  16. data/lib/mocha/expectation_list.rb +5 -1
  17. data/lib/mocha/integration/mini_test.rb +3 -3
  18. data/lib/mocha/integration/mini_test/version_13.rb +1 -1
  19. data/lib/mocha/integration/mini_test/version_140.rb +1 -1
  20. data/lib/mocha/integration/mini_test/version_142_to_172.rb +1 -1
  21. data/lib/mocha/integration/mini_test/version_200.rb +1 -1
  22. data/lib/mocha/integration/mini_test/version_201_to_222.rb +1 -1
  23. data/lib/mocha/integration/mini_test/version_230_to_262.rb +1 -1
  24. data/lib/mocha/integration/test_unit.rb +3 -3
  25. data/lib/mocha/integration/test_unit/gem_version_200.rb +1 -1
  26. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +1 -1
  27. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +1 -1
  28. data/lib/mocha/integration/test_unit/gem_version_230_to_240.rb +1 -1
  29. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +1 -1
  30. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +1 -1
  31. data/lib/mocha/mock.rb +5 -1
  32. data/lib/mocha/options.rb +1 -1
  33. data/lib/mocha/parameter_matchers/has_entry.rb +10 -1
  34. data/lib/mocha/version.rb +1 -1
  35. data/test/acceptance/issue_65_test.rb +63 -0
  36. data/test/acceptance/sequence_test.rb +10 -4
  37. data/test/unit/any_instance_method_test.rb +1 -0
  38. data/test/unit/class_method_test.rb +19 -1
  39. data/test/unit/parameter_matchers/has_entry_test.rb +16 -2
  40. metadata +17 -16
@@ -1,4 +1,12 @@
1
- = 0.10.3 ()
1
+ = 0.10.4 ()
2
+ * Fix for issue #65 - expectations not being verified in subsequent tests
3
+ * Fix for issue #63 - require Mocha::Mockery at Mocha::Mock class load time and not on invocation of Mock#method_missing.
4
+ * Fix for issue #45 - raise ArgumentError if Mocha::ParameterMatchers#has_entry is given
5
+ Hash with wrong number of entries.
6
+ * Make global variable name more obscure to avoid clashes with other libraries.
7
+ * Move travis-ci-related gemfiles into their own directory.
8
+
9
+ = 0.10.3 (e7f88af8e7c3396bc85fe9f9cb9e5f5fef04bea2)
2
10
  * Fix for issue #57. Gem::Requirement#=~ was only added in rubygems v1.8.0, but Object#=~ means the result of various monkey-patching checks is always false/nil for earlier versions of rubygems. However, the method it aliases #satisfied_by? has existed since Gem::Dependency was extracted from Gem::Version in rubygems v0.9.4.4, so it's much safer to use that. Thanks to fguillen for reporting and helping with diagnosis.
3
11
 
4
12
  = 0.10.2 (e05d9a555f1cf97c5961900dab0d884e9753257b)
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "1.3.0"
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "1.4.0"
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "1.4.1"
7
- end
7
+ end
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "1.4.2"
7
- end
7
+ end
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "2.0.0"
7
- end
7
+ end
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "2.0.1"
7
- end
7
+ end
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest", "2.3.0"
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "minitest"
@@ -1,8 +1,8 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "test-unit", "2.0.0"
7
7
  gem "hoe", "2.8.0" # later versions of hoe depend on Rubygems >= 1.4 which in turn depends on Ruby >= 1.8.7
8
- end
8
+ end
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "test-unit", "2.0.1"
7
- end
7
+ end
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "test-unit", "2.0.3"
@@ -1,7 +1,7 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec :path=>"../"
4
4
 
5
5
  group :development do
6
6
  gem "test-unit"
7
- end
7
+ end
@@ -7,7 +7,11 @@ module Mocha
7
7
  def mock
8
8
  stubbee.any_instance.mocha
9
9
  end
10
-
10
+
11
+ def reset_mocha
12
+ stubbee.any_instance.reset_mocha
13
+ end
14
+
11
15
  def hide_original_method
12
16
  if method_exists?(method)
13
17
  begin
@@ -20,12 +20,19 @@ module Mocha
20
20
  remove_new_method
21
21
  restore_original_method
22
22
  mock.unstub(method.to_sym)
23
+ unless mock.any_expectations?
24
+ reset_mocha
25
+ end
23
26
  end
24
27
 
25
28
  def mock
26
29
  stubbee.mocha
27
30
  end
28
31
 
32
+ def reset_mocha
33
+ stubbee.reset_mocha
34
+ end
35
+
29
36
  def hide_original_method
30
37
  if method_exists?(method)
31
38
  begin
@@ -42,7 +42,11 @@ module Mocha # :nodoc:
42
42
  def length
43
43
  @expectations.length
44
44
  end
45
-
45
+
46
+ def any?
47
+ @expectations.any?
48
+ end
49
+
46
50
  private
47
51
 
48
52
  def matching_expectations(method_name, *arguments)
@@ -27,7 +27,7 @@ if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
27
27
  Gem::Version.new('0.0.0')
28
28
  end
29
29
 
30
- $stderr.puts "Detected MiniTest version: #{mini_test_version}" if $options['debug']
30
+ $stderr.puts "Detected MiniTest version: #{mini_test_version}" if $mocha_options['debug']
31
31
 
32
32
  if Gem::Requirement.new('>= 1.3.0', '<= 1.3.1').satisfied_by?(mini_test_version)
33
33
  include Mocha::Integration::MiniTest::Version13
@@ -42,10 +42,10 @@ if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
42
42
  elsif Gem::Requirement.new('>= 2.0.1', '<= 2.2.2').satisfied_by?(mini_test_version)
43
43
  include Mocha::Integration::MiniTest::Version201To222
44
44
  elsif Gem::Requirement.new('>= 2.3.0').satisfied_by?(mini_test_version)
45
- $stderr.puts "*** MiniTest integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.6.2').satisfied_by?(mini_test_version)) && $options['debug']
45
+ $stderr.puts "*** MiniTest integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.6.2').satisfied_by?(mini_test_version)) && $mocha_options['debug']
46
46
  include Mocha::Integration::MiniTest::Version230To262
47
47
  else
48
- $stderr.puts "*** No Mocha integration for MiniTest version ***" if $options['debug']
48
+ $stderr.puts "*** No Mocha integration for MiniTest version ***" if $mocha_options['debug']
49
49
  end
50
50
 
51
51
  end
@@ -8,7 +8,7 @@ module Mocha
8
8
 
9
9
  module Version13
10
10
  def self.included(mod)
11
- $stderr.puts "Monkey patching MiniTest v1.3" if $options['debug']
11
+ $stderr.puts "Monkey patching MiniTest v1.3" if $mocha_options['debug']
12
12
  end
13
13
  def run runner
14
14
  assertion_counter = AssertionCounter.new(self)
@@ -9,7 +9,7 @@ module Mocha
9
9
 
10
10
  module Version140
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest v1.4.0" if $options['debug']
12
+ $stderr.puts "Monkey patching MiniTest v1.4.0" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  assertion_counter = AssertionCounter.new(self)
@@ -9,7 +9,7 @@ module Mocha
9
9
 
10
10
  module Version142To172
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest >= v1.4.2 and <= v1.7.2" if $options['debug']
12
+ $stderr.puts "Monkey patching MiniTest >= v1.4.2 and <= v1.7.2" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  trap 'INFO' do
@@ -9,7 +9,7 @@ module Mocha
9
9
 
10
10
  module Version200
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest v2.0.0" if $options['debug']
12
+ $stderr.puts "Monkey patching MiniTest v2.0.0" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  trap 'INFO' do
@@ -9,7 +9,7 @@ module Mocha
9
9
 
10
10
  module Version201To222
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest >= v2.0.1 <= v2.2.2" if $options['debug']
12
+ $stderr.puts "Monkey patching MiniTest >= v2.0.1 <= v2.2.2" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  trap 'INFO' do
@@ -9,7 +9,7 @@ module Mocha
9
9
 
10
10
  module Version230To262
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest >= v2.3.0 <= v2.6.2" if $options['debug']
12
+ $stderr.puts "Monkey patching MiniTest >= v2.3.0 <= v2.6.2" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  trap 'INFO' do
@@ -26,7 +26,7 @@ if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
26
26
  Gem::Version.new('1.x')
27
27
  end
28
28
 
29
- if $options['debug']
29
+ if $mocha_options['debug']
30
30
  $stderr.puts "Detected Ruby version: #{RUBY_VERSION}"
31
31
  $stderr.puts "Detected Test::Unit version: #{test_unit_version}"
32
32
  end
@@ -44,10 +44,10 @@ if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
44
44
  elsif Gem::Requirement.new('>= 2.0.3', '<= 2.2.0').satisfied_by?(test_unit_version)
45
45
  include Mocha::Integration::TestUnit::GemVersion203To220
46
46
  elsif Gem::Requirement.new('>= 2.3.0').satisfied_by?(test_unit_version)
47
- $stderr.puts "*** Test::Unit integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.4.0').satisfied_by?(test_unit_version)) && $options['debug']
47
+ $stderr.puts "*** Test::Unit integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.4.0').satisfied_by?(test_unit_version)) && $mocha_options['debug']
48
48
  include Mocha::Integration::TestUnit::GemVersion230To240
49
49
  else
50
- $stderr.puts "*** No Mocha integration for Test::Unit version ***" if $options['debug']
50
+ $stderr.puts "*** No Mocha integration for Test::Unit version ***" if $mocha_options['debug']
51
51
  end
52
52
 
53
53
  end
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module GemVersion200
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit gem v2.0.0" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit gem v2.0.0" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module GemVersion201To202
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit gem >= v2.0.1 and <= v2.0.2" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit gem >= v2.0.1 and <= v2.0.2" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module GemVersion203To220
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit gem >= v2.0.3 and <= v2.2.0" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit gem >= v2.0.3 and <= v2.2.0" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module GemVersion230To240
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.4.0" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.4.0" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module RubyVersion185AndBelow
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit for Ruby <= v1.8.5" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit for Ruby <= v1.8.5" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -10,7 +10,7 @@ module Mocha
10
10
 
11
11
  module RubyVersion186AndAbove
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit for Ruby >= v1.8.6" if $options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit for Ruby >= v1.8.6" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -6,6 +6,7 @@ require 'mocha/method_matcher'
6
6
  require 'mocha/parameters_matcher'
7
7
  require 'mocha/unexpected_invocation'
8
8
  require 'mocha/argument_iterator'
9
+ require 'mocha/mockery'
9
10
 
10
11
  module Mocha # :nodoc:
11
12
 
@@ -163,7 +164,6 @@ module Mocha # :nodoc:
163
164
  if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
164
165
  matching_expectation.invoke(&block) if matching_expectation
165
166
  message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
166
- require 'mocha/mockery'
167
167
  message << Mockery.instance.mocha_inspect
168
168
  raise ExpectationError.new(message, caller)
169
169
  end
@@ -198,6 +198,10 @@ module Mocha # :nodoc:
198
198
  self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name)
199
199
  end
200
200
 
201
+ def any_expectations?
202
+ @expectations.any?
203
+ end
204
+
201
205
  # :startdoc:
202
206
 
203
207
  end
@@ -1 +1 @@
1
- $options = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) { |hash, key| hash[key] = true; hash }
1
+ $mocha_options = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) { |hash, key| hash[key] = true; hash }
@@ -29,7 +29,16 @@ module Mocha
29
29
  # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
30
30
  def has_entry(*options)
31
31
  key, value = options.shift, options.shift
32
- key, value = key.to_a[0][0..1] if key.is_a?(Hash)
32
+ if key.is_a?(Hash)
33
+ case key.length
34
+ when 0
35
+ raise ArgumentError.new("Argument has no entries.")
36
+ when 1
37
+ key, value = key.to_a.flatten
38
+ else
39
+ raise ArgumentError.new("Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.")
40
+ end
41
+ end
33
42
  HasEntry.new(key, value)
34
43
  end
35
44
 
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = "0.10.3"
2
+ VERSION = "0.10.4"
3
3
  end
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+ require 'mocha'
3
+
4
+ class Issue65Test < Test::Unit::TestCase
5
+
6
+ include AcceptanceTest
7
+
8
+ def setup
9
+ setup_acceptance_test
10
+ end
11
+
12
+ def teardown
13
+ teardown_acceptance_test
14
+ end
15
+
16
+ def test_expectations_on_class_methods_on_same_class_should_be_verified_in_consecutive_tests
17
+ klass = Class.new do
18
+ def self.foo; end
19
+ def self.bar; end
20
+ end
21
+ test_1 = run_as_test do
22
+ klass.expects(:foo)
23
+ klass.foo
24
+ end
25
+ assert_passed(test_1)
26
+ test_2 = run_as_test do
27
+ klass.expects(:bar)
28
+ end
29
+ assert_failed(test_2)
30
+ end
31
+
32
+ def test_expectations_on_any_instance_methods_on_same_class_should_be_verified_in_consecutive_tests
33
+ klass = Class.new do
34
+ def foo; end
35
+ def bar; end
36
+ end
37
+ test_1 = run_as_test do
38
+ klass.any_instance.expects(:foo)
39
+ klass.new.foo
40
+ end
41
+ assert_passed(test_1)
42
+ test_2 = run_as_test do
43
+ klass.any_instance.expects(:bar)
44
+ end
45
+ assert_failed(test_2)
46
+ end
47
+
48
+ def test_expectations_on_instance_methods_on_same_object_should_be_verified_in_consecutive_tests
49
+ instance = Class.new do
50
+ def foo; end
51
+ def bar; end
52
+ end.new
53
+ test_1 = run_as_test do
54
+ instance.expects(:foo)
55
+ instance.foo
56
+ end
57
+ assert_passed(test_1)
58
+ test_2 = run_as_test do
59
+ instance.expects(:bar)
60
+ end
61
+ assert_failed(test_2)
62
+ end
63
+ end
@@ -22,6 +22,7 @@ class SequenceTest < Test::Unit::TestCase
22
22
  mock.expects(:second).in_sequence(sequence)
23
23
 
24
24
  mock.second
25
+ mock.first
25
26
  end
26
27
  assert_failed(test_result)
27
28
  end
@@ -50,6 +51,7 @@ class SequenceTest < Test::Unit::TestCase
50
51
  mock_two.expects(:second).in_sequence(sequence)
51
52
 
52
53
  mock_two.second
54
+ mock_one.first
53
55
  end
54
56
  assert_failed(test_result)
55
57
  end
@@ -79,6 +81,7 @@ class SequenceTest < Test::Unit::TestCase
79
81
  partial_mock_two.expects(:second).in_sequence(sequence)
80
82
 
81
83
  partial_mock_two.second
84
+ partial_mock_one.first
82
85
  end
83
86
  assert_failed(test_result)
84
87
  end
@@ -142,6 +145,7 @@ class SequenceTest < Test::Unit::TestCase
142
145
  mock.expects(:second).in_sequence(sequence)
143
146
 
144
147
  mock.second
148
+ mock.first
145
149
  end
146
150
  assert_failed(test_result)
147
151
  assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
@@ -155,10 +159,11 @@ class SequenceTest < Test::Unit::TestCase
155
159
 
156
160
  mock.expects(:first).in_sequence(sequence_one)
157
161
  mock.expects(:second).in_sequence(sequence_two)
158
- mock.expects(:three).in_sequence(sequence_one).in_sequence(sequence_two)
162
+ mock.expects(:third).in_sequence(sequence_one).in_sequence(sequence_two)
159
163
 
160
164
  mock.first
161
- mock.three
165
+ mock.third
166
+ mock.second
162
167
  end
163
168
  assert_failed(test_result)
164
169
  assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
@@ -173,10 +178,11 @@ class SequenceTest < Test::Unit::TestCase
173
178
 
174
179
  mock.expects(:first).in_sequence(sequence_one)
175
180
  mock.expects(:second).in_sequence(sequence_two)
176
- mock.expects(:three).in_sequence(sequence_one, sequence_two)
181
+ mock.expects(:third).in_sequence(sequence_one, sequence_two)
177
182
 
178
183
  mock.first
179
- mock.three
184
+ mock.third
185
+ mock.second
180
186
  end
181
187
  assert_failed(test_result)
182
188
  assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
@@ -110,6 +110,7 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
110
110
  method.replace_instance_method(:remove_new_method) { }
111
111
  method.replace_instance_method(:restore_original_method) { }
112
112
  mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
113
+ mocha.define_instance_method(:any_expectations?) { true }
113
114
  method.replace_instance_method(:mock) { mocha }
114
115
 
115
116
  method.unstub
@@ -183,12 +183,30 @@ class ClassMethodTest < Test::Unit::TestCase
183
183
  method = ClassMethod.new(klass, :method_x)
184
184
  method.replace_instance_method(:restore_original_method) { }
185
185
  mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
186
+ mocha.define_instance_method(:any_expectations?) { true }
186
187
  method.replace_instance_method(:mock) { mocha }
187
188
 
188
189
  method.unstub
189
190
  assert_equal mocha.unstub_method, :method_x
190
191
  end
191
-
192
+
193
+ def test_should_call_stubbee_reset_mocha_if_no_expectations_remaining
194
+ klass = Class.new { def self.method_x; end }
195
+ method = ClassMethod.new(klass, :method_x)
196
+ method.replace_instance_method(:remove_new_method) { }
197
+ method.replace_instance_method(:restore_original_method) { }
198
+ mocha = Class.new
199
+ mocha.define_instance_method(:unstub) { }
200
+ mocha.define_instance_method(:any_expectations?) { false }
201
+ method.replace_instance_method(:mock) { mocha }
202
+ stubbee = Class.new { attr_accessor :reset_mocha_called; def reset_mocha; self.reset_mocha_called = true; end; }.new
203
+ method.replace_instance_method(:stubbee) { stubbee }
204
+
205
+ method.unstub
206
+
207
+ assert stubbee.reset_mocha_called
208
+ end
209
+
192
210
  def test_should_return_mock_for_stubbee
193
211
  mocha = Object.new
194
212
  stubbee = Object.new
@@ -78,5 +78,19 @@ class HasEntryTest < Test::Unit::TestCase
78
78
  end.new
79
79
  assert !matcher.matches?([object])
80
80
  end
81
-
82
- end
81
+
82
+ def test_should_raise_argument_error_if_no_entries_are_supplied
83
+ e = assert_raises(ArgumentError) do
84
+ has_entry({})
85
+ end
86
+ assert_equal "Argument has no entries.", e.message
87
+ end
88
+
89
+ def test_should_raise_argument_error_if_multiple_entries_are_supplied
90
+ e = assert_raises(ArgumentError) do
91
+ has_entry(:key_1 => 'value_1', :key_2 => 'value_2')
92
+ end
93
+ assert_equal "Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.", e.message
94
+ end
95
+
96
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 3
10
- version: 0.10.3
9
+ - 4
10
+ version: 0.10.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Mead
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-20 00:00:00 +00:00
18
+ date: 2012-02-10 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -107,18 +107,6 @@ files:
107
107
  - .gemtest
108
108
  - COPYING.rdoc
109
109
  - Gemfile
110
- - Gemfile.minitest.1.3.0
111
- - Gemfile.minitest.1.4.0
112
- - Gemfile.minitest.1.4.1
113
- - Gemfile.minitest.1.4.2
114
- - Gemfile.minitest.2.0.0
115
- - Gemfile.minitest.2.0.1
116
- - Gemfile.minitest.2.3.0
117
- - Gemfile.minitest.latest
118
- - Gemfile.test-unit.2.0.0
119
- - Gemfile.test-unit.2.0.1
120
- - Gemfile.test-unit.2.0.3
121
- - Gemfile.test-unit.latest
122
110
  - MIT-LICENSE.rdoc
123
111
  - README.rdoc
124
112
  - RELEASE.rdoc
@@ -126,6 +114,18 @@ files:
126
114
  - examples/misc.rb
127
115
  - examples/mocha.rb
128
116
  - examples/stubba.rb
117
+ - gemfiles/Gemfile.minitest.1.3.0
118
+ - gemfiles/Gemfile.minitest.1.4.0
119
+ - gemfiles/Gemfile.minitest.1.4.1
120
+ - gemfiles/Gemfile.minitest.1.4.2
121
+ - gemfiles/Gemfile.minitest.2.0.0
122
+ - gemfiles/Gemfile.minitest.2.0.1
123
+ - gemfiles/Gemfile.minitest.2.3.0
124
+ - gemfiles/Gemfile.minitest.latest
125
+ - gemfiles/Gemfile.test-unit.2.0.0
126
+ - gemfiles/Gemfile.test-unit.2.0.1
127
+ - gemfiles/Gemfile.test-unit.2.0.3
128
+ - gemfiles/Gemfile.test-unit.latest
129
129
  - init.rb
130
130
  - lib/mocha.rb
131
131
  - lib/mocha/any_instance_method.rb
@@ -222,6 +222,7 @@ files:
222
222
  - test/acceptance/expectations_on_multiple_methods_test.rb
223
223
  - test/acceptance/expected_invocation_count_test.rb
224
224
  - test/acceptance/failure_messages_test.rb
225
+ - test/acceptance/issue_65_test.rb
225
226
  - test/acceptance/minitest_test.rb
226
227
  - test/acceptance/mocha_example_test.rb
227
228
  - test/acceptance/mocha_test_result_test.rb