mocha 0.10.4 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Mocha
1
+ = Mocha {<img src="https://secure.travis-ci.org/floehopper/mocha.png" />}[http://travis-ci.org/floehopper/mocha]
2
2
 
3
3
  Mocha is a library for mocking and stubbing using a syntax like that of {JMock}[http://www.jmock.org].
4
4
 
@@ -8,10 +8,6 @@ Mocha provides a unified, simple and readable syntax for both traditional mockin
8
8
 
9
9
  Mocha was harvested from projects at {Reevoo}[http://www.reevoo.com/] by me ({James}[http://jamesmead.org/]) and my (then) colleagues {Ben}[http://www.techbelly.com/], {Chris}[http://chrisroos.co.uk/] and {Paul}[http://po-ru.com/].
10
10
 
11
- == Build Status
12
-
13
- https://secure.travis-ci.org/floehopper/mocha.png
14
-
15
11
  == Installation
16
12
 
17
13
  Install the latest version of the gem with the following command...
@@ -38,10 +34,6 @@ Or install the {Rails}[http://www.rubyonrails.org/] plugin...
38
34
 
39
35
  Note that versions 0.9.6 & 0.9.7 of the Rails plugin were broken. As of version 0.9.8, you need to explicitly load Mocha after the test framework e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
40
36
 
41
- Or download Mocha...
42
-
43
- http://rubyforge.org/frs/?group_id=1917
44
-
45
37
  == Examples
46
38
 
47
39
  * Quick Start - {Usage Examples}[http://mocha.rubyforge.org/examples/misc.html]
@@ -50,6 +42,11 @@ Or download Mocha...
50
42
  * More examples on {James Mead's Blog}[http://jamesmead.org/blog/]
51
43
  * {Mailing List Archives}[http://groups.google.com/group/mocha-developer]
52
44
 
45
+ == Links
46
+
47
+ * {Source code}[http://github.com/floehopper/mocha]
48
+ * {Bug reports}[http://github.com/floehopper/mocha/issues]
49
+
53
50
  == License
54
51
 
55
52
  Copyright Revieworld Ltd. 2006
data/RELEASE.rdoc CHANGED
@@ -1,5 +1,12 @@
1
- = 0.10.4 ()
2
- * Fix for issue #65 - expectations not being verified in subsequent tests
1
+ = 0.10.5 (a5a64cf9755b21d4a30e446232654d1c0fc6f151)
2
+ * Fix for issue #66 (hopefully without regressing on issue #63) - Mocha::Mock has Mocha::Mockery as a dependency. Stop trying to pretend otherwise. Thanks to @kennyj for reporting.
3
+ * Fix a bunch of warnings in Ruby 1.9. There are still the 6 test failures mentioned in issue #41 which I suspect are due to the introspection gem not being Ruby 1.9-compatible.
4
+ * Add links to README for source code & issue tracker.
5
+ * Fix for issue #67 - Make the travis-ci badge visible in the README. Thanks to Diego Plentz for pull request.
6
+ * Fix for issue #70 - Rename Mock#expectations to Mock#__expectations__ to avoid conflicts. Thanks to Jeremy Stephens for pull request.
7
+
8
+ = 0.10.4 (babdd656c361ac65f25948104adf612e59174a5e)
9
+ * Fix for issue #65 - expectations not being verified in subsequent tests.
3
10
  * Fix for issue #63 - require Mocha::Mockery at Mocha::Mock class load time and not on invocation of Mock#method_missing.
4
11
  * Fix for issue #45 - raise ArgumentError if Mocha::ParameterMatchers#has_entry is given
5
12
  Hash with wrong number of entries.
data/lib/mocha/mock.rb CHANGED
@@ -6,7 +6,6 @@ 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'
10
9
 
11
10
  module Mocha # :nodoc:
12
11
 
@@ -134,7 +133,8 @@ module Mocha # :nodoc:
134
133
 
135
134
  # :stopdoc:
136
135
 
137
- def initialize(name = nil, &block)
136
+ def initialize(mockery, name = nil, &block)
137
+ @mockery = mockery
138
138
  @name = name || DefaultName.new(self)
139
139
  @expectations = ExpectationList.new
140
140
  @everything_stubbed = false
@@ -142,7 +142,7 @@ module Mocha # :nodoc:
142
142
  instance_eval(&block) if block
143
143
  end
144
144
 
145
- attr_reader :everything_stubbed, :expectations
145
+ attr_reader :everything_stubbed
146
146
 
147
147
  alias_method :__expects__, :expects
148
148
 
@@ -150,6 +150,10 @@ module Mocha # :nodoc:
150
150
 
151
151
  alias_method :quacks_like, :responds_like
152
152
 
153
+ def __expectations__
154
+ @expectations
155
+ end
156
+
153
157
  def stub_everything
154
158
  @everything_stubbed = true
155
159
  end
@@ -164,7 +168,7 @@ module Mocha # :nodoc:
164
168
  if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
165
169
  matching_expectation.invoke(&block) if matching_expectation
166
170
  message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
167
- message << Mockery.instance.mocha_inspect
171
+ message << @mockery.mocha_inspect
168
172
  raise ExpectationError.new(message, caller)
169
173
  end
170
174
  end
data/lib/mocha/mockery.rb CHANGED
@@ -23,19 +23,19 @@ module Mocha
23
23
  end
24
24
 
25
25
  def named_mock(name, &block)
26
- add_mock(Mock.new(Name.new(name), &block))
26
+ add_mock(Mock.new(self, Name.new(name), &block))
27
27
  end
28
28
 
29
29
  def unnamed_mock(&block)
30
- add_mock(Mock.new(&block))
30
+ add_mock(Mock.new(self, &block))
31
31
  end
32
32
 
33
33
  def mock_impersonating(object, &block)
34
- add_mock(Mock.new(ImpersonatingName.new(object), &block))
34
+ add_mock(Mock.new(self, ImpersonatingName.new(object), &block))
35
35
  end
36
36
 
37
37
  def mock_impersonating_any_instance_of(klass, &block)
38
- add_mock(Mock.new(ImpersonatingAnyInstanceName.new(klass), &block))
38
+ add_mock(Mock.new(self, ImpersonatingAnyInstanceName.new(klass), &block))
39
39
  end
40
40
 
41
41
  def new_state_machine(name)
@@ -149,7 +149,7 @@ module Mocha
149
149
  private
150
150
 
151
151
  def expectations
152
- mocks.map { |mock| mock.expectations.to_a }.flatten
152
+ mocks.map { |mock| mock.__expectations__.to_a }.flatten
153
153
  end
154
154
 
155
155
  def unsatisfied_expectations
data/lib/mocha/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = "0.10.4"
2
+ VERSION = "0.10.5"
3
3
  end
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../acceptance_test_helper', __FILE__)
2
+ require 'mocha'
3
+
4
+ class Issue70Test < 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_should_stub_expectations_instance_method
17
+ instance = Class.new do
18
+ def expectations
19
+ :original_return_value
20
+ end
21
+ end.new
22
+ test_result = run_as_test do
23
+ instance.stubs(:expectations).returns(:stubbed_return_value)
24
+ assert_equal :stubbed_return_value, instance.expectations
25
+ end
26
+ assert_passed(test_result)
27
+ end
28
+
29
+ def test_should_stub_expectations_class_method
30
+ klass = Class.new do
31
+ def self.expectations
32
+ :original_return_value
33
+ end
34
+ end
35
+ test_result = run_as_test do
36
+ klass.stubs(:expectations).returns(:stubbed_return_value)
37
+ assert_equal :stubbed_return_value, klass.expectations
38
+ end
39
+ assert_passed(test_result)
40
+ end
41
+
42
+ def test_should_stub_expectations_any_instance_method
43
+ klass = Class.new do
44
+ def expectations
45
+ :original_return_value
46
+ end
47
+ end
48
+ instance = klass.new
49
+ test_result = run_as_test do
50
+ klass.any_instance.stubs(:expectations).returns(:stubbed_return_value)
51
+ assert_equal :stubbed_return_value, instance.expectations
52
+ end
53
+ assert_passed(test_result)
54
+ end
55
+ end
@@ -80,12 +80,11 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
80
80
  :original_return_value
81
81
  end
82
82
  end
83
- instance = klass.new
84
83
  run_as_test do
85
84
  klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
86
85
  end
87
86
 
88
- assert_equal 0, klass.any_instance.mocha.expectations.length
87
+ assert_equal 0, klass.any_instance.mocha.__expectations__.length
89
88
  end
90
89
 
91
90
  def test_should_be_able_to_stub_a_superclass_method
@@ -54,7 +54,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
54
54
  run_as_test do
55
55
  mod.stubs(:my_module_method)
56
56
  end
57
- assert_equal 0, mod.mocha.expectations.length
57
+ assert_equal 0, mod.mocha.__expectations__.length
58
58
  end
59
59
 
60
60
  def test_should_be_able_to_stub_a_superclass_method
@@ -160,4 +160,4 @@ class StubModuleMethodTest < Test::Unit::TestCase
160
160
  assert_passed(test_result)
161
161
  end
162
162
 
163
- end
163
+ end
@@ -30,7 +30,7 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
30
30
  def test_should_define_a_new_method
31
31
  klass = Class.new { def method_x; end }
32
32
  method = AnyInstanceMethod.new(klass, :method_x)
33
- mocha = Mock.new
33
+ mocha = build_mock
34
34
  mocha.expects(:method_x).with(:param1, :param2).returns(:result)
35
35
  any_instance = Object.new
36
36
  any_instance.define_instance_method(:mocha) { mocha }
@@ -72,8 +72,8 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
72
72
 
73
73
  def test_should_call_remove_new_method
74
74
  klass = Class.new { def method_x; end }
75
- any_instance = Mock.new
76
- any_instance_mocha = Mock.new
75
+ any_instance = build_mock
76
+ any_instance_mocha = build_mock
77
77
  any_instance.stubs(:mocha).returns(any_instance_mocha)
78
78
  klass.define_instance_method(:any_instance) { any_instance }
79
79
  method = AnyInstanceMethod.new(klass, :method_x)
@@ -88,8 +88,8 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
88
88
 
89
89
  def test_should_call_restore_original_method
90
90
  klass = Class.new { def method_x; end }
91
- any_instance = Mock.new
92
- any_instance_mocha = Mock.new
91
+ any_instance = build_mock
92
+ any_instance_mocha = build_mock
93
93
  any_instance.stubs(:mocha).returns(any_instance_mocha)
94
94
  klass.define_instance_method(:any_instance) { any_instance }
95
95
  method = AnyInstanceMethod.new(klass, :method_x)
@@ -128,4 +128,9 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
128
128
  assert_equal stubbee.any_instance.mocha, method.mock
129
129
  end
130
130
 
131
+ private
132
+
133
+ def build_mock
134
+ Mock.new(nil)
135
+ end
131
136
  end
@@ -15,7 +15,7 @@ class CentralTest < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_should_stub_method_if_not_already_stubbed
18
- method = Mock.new
18
+ method = build_mock
19
19
  method.expects(:stub)
20
20
  stubba = Central.new
21
21
 
@@ -25,7 +25,7 @@ class CentralTest < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_should_not_stub_method_if_already_stubbed
28
- method = Mock.new
28
+ method = build_mock
29
29
  method.stubs(:matches?).returns(true)
30
30
  method.expects(:stub).times(0)
31
31
  stubba = Central.new
@@ -37,7 +37,7 @@ class CentralTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  def test_should_record_method
40
- method = Mock.new
40
+ method = build_mock
41
41
  method.expects(:stub)
42
42
  stubba = Central.new
43
43
 
@@ -48,9 +48,9 @@ class CentralTest < Test::Unit::TestCase
48
48
 
49
49
  def test_should_unstub_specified_method
50
50
  stubba = Central.new
51
- method_1 = Mock.new
51
+ method_1 = build_mock
52
52
  method_1.stubs(:matches?).returns(false)
53
- method_2 = Mock.new
53
+ method_2 = build_mock
54
54
  method_2.stubs(:matches?).returns(true)
55
55
  method_2.expects(:unstub)
56
56
  stubba.stubba_methods = [method_1, method_2]
@@ -63,9 +63,9 @@ class CentralTest < Test::Unit::TestCase
63
63
 
64
64
  def test_should_not_unstub_specified_method_if_not_already_stubbed
65
65
  stubba = Central.new
66
- method_1 = Mock.new
66
+ method_1 = build_mock
67
67
  method_1.stubs(:matches?).returns(false)
68
- method_2 = Mock.new
68
+ method_2 = build_mock
69
69
  method_2.expects(:unstub).never
70
70
  stubba.stubba_methods = [method_1]
71
71
 
@@ -77,10 +77,10 @@ class CentralTest < Test::Unit::TestCase
77
77
 
78
78
  def test_should_unstub_all_methods
79
79
  stubba = Central.new
80
- method_1 = Mock.new
80
+ method_1 = build_mock
81
81
  method_1.stubs(:matches?).returns(true)
82
82
  method_1.expects(:unstub)
83
- method_2 = Mock.new
83
+ method_2 = build_mock
84
84
  method_2.stubs(:matches?).returns(true)
85
85
  method_2.expects(:unstub)
86
86
  stubba.stubba_methods = [method_1, method_2]
@@ -91,5 +91,10 @@ class CentralTest < Test::Unit::TestCase
91
91
  assert method_1.__verified__?
92
92
  assert method_2.__verified__?
93
93
  end
94
-
94
+
95
+ private
96
+
97
+ def build_mock
98
+ Mock.new(nil)
99
+ end
95
100
  end
@@ -66,7 +66,6 @@ class ClassMethodTest < Test::Unit::TestCase
66
66
  def test_should_respond_to_original_method_name_after_original_method_has_been_hidden
67
67
  klass = Class.new { def self.original_method_name; end }
68
68
  method = ClassMethod.new(klass, :original_method_name)
69
- hidden_method_x = method.hidden_method
70
69
 
71
70
  method.hide_original_method
72
71
 
@@ -85,7 +84,7 @@ class ClassMethodTest < Test::Unit::TestCase
85
84
 
86
85
  def test_should_define_a_new_method_which_should_call_mocha_method_missing
87
86
  klass = Class.new { def self.method_x; end }
88
- mocha = Mocha::Mock.new
87
+ mocha = build_mock
89
88
  klass.define_instance_method(:mocha) { mocha }
90
89
  mocha.expects(:method_x).with(:param1, :param2).returns(:result)
91
90
  method = ClassMethod.new(klass, :method_x)
@@ -155,7 +154,7 @@ class ClassMethodTest < Test::Unit::TestCase
155
154
  def test_should_call_remove_new_method
156
155
  klass = Class.new { def self.method_x; end }
157
156
  method = ClassMethod.new(klass, :method_x)
158
- mocha = Mock.new
157
+ mocha = build_mock
159
158
  klass.define_instance_method(:mocha) { mocha }
160
159
  method.define_instance_accessor(:remove_called)
161
160
  method.replace_instance_method(:remove_new_method) { self.remove_called = true }
@@ -167,7 +166,7 @@ class ClassMethodTest < Test::Unit::TestCase
167
166
 
168
167
  def test_should_call_restore_original_method
169
168
  klass = Class.new { def self.method_x; end }
170
- mocha = Mock.new
169
+ mocha = build_mock
171
170
  klass.define_instance_method(:mocha) { mocha }
172
171
  method = ClassMethod.new(klass, :method_x)
173
172
  method.define_instance_accessor(:restore_called)
@@ -196,7 +195,7 @@ class ClassMethodTest < Test::Unit::TestCase
196
195
  method.replace_instance_method(:remove_new_method) { }
197
196
  method.replace_instance_method(:restore_original_method) { }
198
197
  mocha = Class.new
199
- mocha.define_instance_method(:unstub) { }
198
+ mocha.define_instance_method(:unstub) { |method_name| }
200
199
  mocha.define_instance_method(:any_expectations?) { false }
201
200
  method.replace_instance_method(:mock) { mocha }
202
201
  stubbee = Class.new { attr_accessor :reset_mocha_called; def reset_mocha; self.reset_mocha_called = true; end; }.new
@@ -252,5 +251,10 @@ class ClassMethodTest < Test::Unit::TestCase
252
251
  class_method_2 = ClassMethod.new(stubbee, :method)
253
252
  assert class_method_1.matches?(class_method_2)
254
253
  end
255
-
254
+
255
+ private
256
+
257
+ def build_mock
258
+ Mock.new(nil)
259
+ end
256
260
  end
@@ -9,7 +9,7 @@ class MockTest < Test::Unit::TestCase
9
9
  include Mocha
10
10
 
11
11
  def test_should_set_single_expectation
12
- mock = Mock.new
12
+ mock = build_mock
13
13
  mock.expects(:method1).returns(1)
14
14
  assert_nothing_raised(ExpectationError) do
15
15
  assert_equal 1, mock.method1
@@ -17,30 +17,30 @@ class MockTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_should_build_and_store_expectations
20
- mock = Mock.new
20
+ mock = build_mock
21
21
  expectation = mock.expects(:method1)
22
22
  assert_not_nil expectation
23
- assert_equal [expectation], mock.expectations.to_a
23
+ assert_equal [expectation], mock.__expectations__.to_a
24
24
  end
25
25
 
26
26
  def test_should_not_stub_everything_by_default
27
- mock = Mock.new
27
+ mock = build_mock
28
28
  assert_equal false, mock.everything_stubbed
29
29
  end
30
30
 
31
31
  def test_should_stub_everything
32
- mock = Mock.new
32
+ mock = build_mock
33
33
  mock.stub_everything
34
34
  assert_equal true, mock.everything_stubbed
35
35
  end
36
36
 
37
37
  def test_should_be_able_to_extend_mock_object_with_module
38
- mock = Mock.new
38
+ mock = build_mock
39
39
  assert_nothing_raised(ExpectationError) { mock.extend(Module.new) }
40
40
  end
41
41
 
42
42
  def test_should_be_equal
43
- mock = Mock.new
43
+ mock = build_mock
44
44
  assert_equal true, mock.eql?(mock)
45
45
  end
46
46
 
@@ -51,55 +51,55 @@ class MockTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_should_be_able_to_mock_standard_object_methods
54
- mock = Mock.new
54
+ mock = build_mock
55
55
  OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) }
56
56
  OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
57
57
  assert mock.__verified__?
58
58
  end
59
59
 
60
60
  def test_should_be_able_to_stub_standard_object_methods
61
- mock = Mock.new
61
+ mock = build_mock
62
62
  OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) }
63
63
  OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
64
64
  end
65
65
 
66
66
  def test_should_create_and_add_expectations
67
- mock = Mock.new
67
+ mock = build_mock
68
68
  expectation1 = mock.expects(:method1)
69
69
  expectation2 = mock.expects(:method2)
70
- assert_equal [expectation1, expectation2].to_set, mock.expectations.to_set
70
+ assert_equal [expectation1, expectation2].to_set, mock.__expectations__.to_set
71
71
  end
72
72
 
73
73
  def test_should_pass_backtrace_into_expectation
74
- mock = Mock.new
74
+ mock = build_mock
75
75
  backtrace = Object.new
76
76
  expectation = mock.expects(:method1, backtrace)
77
77
  assert_equal backtrace, expectation.backtrace
78
78
  end
79
79
 
80
80
  def test_should_pass_backtrace_into_stub
81
- mock = Mock.new
81
+ mock = build_mock
82
82
  backtrace = Object.new
83
83
  stub = mock.stubs(:method1, backtrace)
84
84
  assert_equal backtrace, stub.backtrace
85
85
  end
86
86
 
87
87
  def test_should_create_and_add_stubs
88
- mock = Mock.new
88
+ mock = build_mock
89
89
  stub1 = mock.stubs(:method1)
90
90
  stub2 = mock.stubs(:method2)
91
- assert_equal [stub1, stub2].to_set, mock.expectations.to_set
91
+ assert_equal [stub1, stub2].to_set, mock.__expectations__.to_set
92
92
  end
93
93
 
94
94
  def test_should_invoke_expectation_and_return_result
95
- mock = Mock.new
95
+ mock = build_mock
96
96
  mock.expects(:my_method).returns(:result)
97
97
  result = mock.my_method
98
98
  assert_equal :result, result
99
99
  end
100
100
 
101
101
  def test_should_not_raise_error_if_stubbing_everything
102
- mock = Mock.new
102
+ mock = build_mock
103
103
  mock.stub_everything
104
104
  result = nil
105
105
  assert_nothing_raised(ExpectationError) do
@@ -109,7 +109,7 @@ class MockTest < Test::Unit::TestCase
109
109
  end
110
110
 
111
111
  def test_should_raise_assertion_error_for_unexpected_method_call
112
- mock = Mock.new
112
+ mock = build_mock
113
113
  error = assert_raise(ExpectationError) do
114
114
  mock.unexpected_method_called(:my_method, :argument1, :argument2)
115
115
  end
@@ -120,7 +120,7 @@ class MockTest < Test::Unit::TestCase
120
120
  end
121
121
 
122
122
  def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied
123
- mock = Mock.new
123
+ mock = build_mock
124
124
  mock.expects(:method1)
125
125
  mock.expects(:method2)
126
126
  mock.method1
@@ -128,7 +128,7 @@ class MockTest < Test::Unit::TestCase
128
128
  end
129
129
 
130
130
  def test_should_increment_assertion_counter_for_every_verified_expectation
131
- mock = Mock.new
131
+ mock = build_mock
132
132
 
133
133
  mock.expects(:method1)
134
134
  mock.method1
@@ -144,7 +144,7 @@ class MockTest < Test::Unit::TestCase
144
144
  end
145
145
 
146
146
  def test_should_yield_supplied_parameters_to_block
147
- mock = Mock.new
147
+ mock = build_mock
148
148
  parameters_for_yield = [1, 2, 3]
149
149
  mock.expects(:method1).yields(*parameters_for_yield)
150
150
  yielded_parameters = nil
@@ -153,69 +153,69 @@ class MockTest < Test::Unit::TestCase
153
153
  end
154
154
 
155
155
  def test_should_set_up_multiple_expectations_with_return_values
156
- mock = Mock.new
156
+ mock = build_mock
157
157
  mock.expects(:method1 => :result1, :method2 => :result2)
158
158
  assert_equal :result1, mock.method1
159
159
  assert_equal :result2, mock.method2
160
160
  end
161
161
 
162
162
  def test_should_set_up_multiple_stubs_with_return_values
163
- mock = Mock.new
163
+ mock = build_mock
164
164
  mock.stubs(:method1 => :result1, :method2 => :result2)
165
165
  assert_equal :result1, mock.method1
166
166
  assert_equal :result2, mock.method2
167
167
  end
168
168
 
169
169
  def test_should_keep_returning_specified_value_for_stubs
170
- mock = Mock.new
170
+ mock = build_mock
171
171
  mock.stubs(:method1).returns(1)
172
172
  assert_equal 1, mock.method1
173
173
  assert_equal 1, mock.method1
174
174
  end
175
175
 
176
176
  def test_should_keep_returning_specified_value_for_expects
177
- mock = Mock.new
177
+ mock = build_mock
178
178
  mock.expects(:method1).times(2).returns(1)
179
179
  assert_equal 1, mock.method1
180
180
  assert_equal 1, mock.method1
181
181
  end
182
182
 
183
183
  def test_should_match_most_recent_call_to_expects
184
- mock = Mock.new
184
+ mock = build_mock
185
185
  mock.expects(:method1).returns(0)
186
186
  mock.expects(:method1).returns(1)
187
187
  assert_equal 1, mock.method1
188
188
  end
189
189
 
190
190
  def test_should_match_most_recent_call_to_stubs
191
- mock = Mock.new
191
+ mock = build_mock
192
192
  mock.stubs(:method1).returns(0)
193
193
  mock.stubs(:method1).returns(1)
194
194
  assert_equal 1, mock.method1
195
195
  end
196
196
 
197
197
  def test_should_match_most_recent_call_to_stubs_or_expects
198
- mock = Mock.new
198
+ mock = build_mock
199
199
  mock.stubs(:method1).returns(0)
200
200
  mock.expects(:method1).returns(1)
201
201
  assert_equal 1, mock.method1
202
202
  end
203
203
 
204
204
  def test_should_match_most_recent_call_to_expects_or_stubs
205
- mock = Mock.new
205
+ mock = build_mock
206
206
  mock.expects(:method1).returns(0)
207
207
  mock.stubs(:method1).returns(1)
208
208
  assert_equal 1, mock.method1
209
209
  end
210
210
 
211
211
  def test_should_respond_to_expected_method
212
- mock = Mock.new
212
+ mock = build_mock
213
213
  mock.expects(:method1)
214
214
  assert_equal true, mock.respond_to?(:method1)
215
215
  end
216
216
 
217
217
  def test_should_not_respond_to_unexpected_method
218
- mock = Mock.new
218
+ mock = build_mock
219
219
  assert_equal false, mock.respond_to?(:method1)
220
220
  end
221
221
 
@@ -223,7 +223,7 @@ class MockTest < Test::Unit::TestCase
223
223
  instance = Class.new do
224
224
  define_method(:respond_to?) { |symbol| true }
225
225
  end.new
226
- mock = Mock.new
226
+ mock = build_mock
227
227
  mock.responds_like(instance)
228
228
  assert_equal true, mock.respond_to?(:invoked_method)
229
229
  end
@@ -232,21 +232,18 @@ class MockTest < Test::Unit::TestCase
232
232
  instance = Class.new do
233
233
  define_method(:respond_to?) { |symbol| false }
234
234
  end.new
235
- mock = Mock.new
235
+ mock = build_mock
236
236
  mock.responds_like(instance)
237
237
  assert_equal false, mock.respond_to?(:invoked_method)
238
238
  end
239
239
 
240
240
  def test_should_return_itself_to_allow_method_chaining
241
- mock = Mock.new
241
+ mock = build_mock
242
242
  assert_same mock.responds_like(Object.new), mock
243
243
  end
244
244
 
245
245
  def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder
246
- instance = Class.new do
247
- define_method(:respond_to?) { true }
248
- end.new
249
- mock = Mock.new
246
+ mock = build_mock
250
247
  mock.stubs(:invoked_method)
251
248
  assert_nothing_raised(NoMethodError) { mock.invoked_method }
252
249
  end
@@ -255,7 +252,7 @@ class MockTest < Test::Unit::TestCase
255
252
  instance = Class.new do
256
253
  define_method(:respond_to?) { |symbol| true }
257
254
  end.new
258
- mock = Mock.new
255
+ mock = build_mock
259
256
  mock.responds_like(instance)
260
257
  mock.stubs(:invoked_method)
261
258
  assert_nothing_raised(NoMethodError) { mock.invoked_method }
@@ -266,7 +263,7 @@ class MockTest < Test::Unit::TestCase
266
263
  define_method(:respond_to?) { |symbol| false }
267
264
  define_method(:mocha_inspect) { 'mocha_inspect' }
268
265
  end.new
269
- mock = Mock.new
266
+ mock = build_mock
270
267
  mock.responds_like(instance)
271
268
  mock.stubs(:invoked_method)
272
269
  assert_raises(NoMethodError) { mock.invoked_method }
@@ -277,7 +274,7 @@ class MockTest < Test::Unit::TestCase
277
274
  define_method(:respond_to?) { |symbol| false }
278
275
  define_method(:mocha_inspect) { 'mocha_inspect' }
279
276
  end.new
280
- mock = Mock.new
277
+ mock = build_mock
281
278
  mock.responds_like(instance)
282
279
  mock.stubs(:invoked_method)
283
280
  begin
@@ -288,22 +285,28 @@ class MockTest < Test::Unit::TestCase
288
285
  end
289
286
 
290
287
  def test_should_handle_respond_to_with_private_methods_param_without_error
291
- mock = Mock.new
288
+ mock = build_mock
292
289
  assert_nothing_raised{ mock.respond_to?(:object_id, false) }
293
290
  end
294
291
 
295
292
  def test_should_respond_to_any_method_if_stubbing_everything
296
- mock = Mock.new
293
+ mock = build_mock
297
294
  mock.stub_everything
298
295
  assert mock.respond_to?(:abc)
299
296
  assert mock.respond_to?(:xyz)
300
297
  end
301
298
 
302
299
  def test_should_remove_expectation_for_unstubbed_method
303
- mock = Mock.new
300
+ mock = build_mock
304
301
  mock.expects(:method1)
305
302
  mock.unstub(:method1)
306
303
  e = assert_raises(ExpectationError) { mock.method1 }
307
304
  assert_match(/unexpected invocation/, e.message)
308
305
  end
306
+
307
+ private
308
+
309
+ def build_mock
310
+ Mock.new(nil)
311
+ end
309
312
  end
@@ -36,7 +36,7 @@ class MockeryTest < Test::Unit::TestCase
36
36
 
37
37
  def test_should_reset_list_of_mocks_on_teardown
38
38
  mockery = Mockery.new
39
- mock = mockery.unnamed_mock { expects(:my_method) }
39
+ mockery.unnamed_mock { expects(:my_method) }
40
40
  mockery.teardown
41
41
  assert_nothing_raised(ExpectationError) { mockery.verify }
42
42
  end
@@ -7,85 +7,85 @@ class ParametersMatcherTest < Test::Unit::TestCase
7
7
 
8
8
  def test_should_match_any_actual_parameters_if_no_expected_parameters_specified
9
9
  parameters_matcher = ParametersMatcher.new
10
- assert parameters_matcher.match?(actual_parameters = [1, 2, 3])
10
+ assert parameters_matcher.match?([1, 2, 3])
11
11
  end
12
12
 
13
13
  def test_should_match_if_actual_parameters_are_same_as_expected_parameters
14
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
15
- assert parameters_matcher.match?(actual_parameters = [4, 5, 6])
14
+ parameters_matcher = ParametersMatcher.new([4, 5, 6])
15
+ assert parameters_matcher.match?([4, 5, 6])
16
16
  end
17
17
 
18
18
  def test_should_not_match_if_actual_parameters_are_different_from_expected_parameters
19
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
20
- assert !parameters_matcher.match?(actual_parameters = [1, 2, 3])
19
+ parameters_matcher = ParametersMatcher.new([4, 5, 6])
20
+ assert !parameters_matcher.match?([1, 2, 3])
21
21
  end
22
22
 
23
23
  def test_should_not_match_if_there_are_less_actual_parameters_than_expected_parameters
24
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
25
- assert !parameters_matcher.match?(actual_parameters = [4, 5])
24
+ parameters_matcher = ParametersMatcher.new([4, 5, 6])
25
+ assert !parameters_matcher.match?([4, 5])
26
26
  end
27
27
 
28
28
  def test_should_not_match_if_there_are_more_actual_parameters_than_expected_parameters
29
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5])
30
- assert !parameters_matcher.match?(actual_parameters = [4, 5, 6])
29
+ parameters_matcher = ParametersMatcher.new([4, 5])
30
+ assert !parameters_matcher.match?([4, 5, 6])
31
31
  end
32
32
 
33
33
  def test_should_not_match_if_not_all_required_parameters_are_supplied
34
34
  optionals = ParameterMatchers::Optionally.new(6, 7)
35
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
36
- assert !parameters_matcher.match?(actual_parameters = [4])
35
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
36
+ assert !parameters_matcher.match?([4])
37
37
  end
38
38
 
39
39
  def test_should_match_if_all_required_parameters_match_and_no_optional_parameters_are_supplied
40
40
  optionals = ParameterMatchers::Optionally.new(6, 7)
41
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
42
- assert parameters_matcher.match?(actual_parameters = [4, 5])
41
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
42
+ assert parameters_matcher.match?([4, 5])
43
43
  end
44
44
 
45
45
  def test_should_match_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied
46
46
  optionals = ParameterMatchers::Optionally.new(6, 7)
47
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
48
- assert parameters_matcher.match?(actual_parameters = [4, 5, 6])
47
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
48
+ assert parameters_matcher.match?([4, 5, 6])
49
49
  end
50
50
 
51
51
  def test_should_match_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied
52
52
  optionals = ParameterMatchers::Optionally.new(6, 7)
53
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
54
- assert parameters_matcher.match?(actual_parameters = [4, 5, 6, 7])
53
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
54
+ assert parameters_matcher.match?([4, 5, 6, 7])
55
55
  end
56
56
 
57
57
  def test_should_not_match_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied
58
58
  optionals = ParameterMatchers::Optionally.new(6, 7)
59
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
60
- assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 7, 8])
59
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
60
+ assert !parameters_matcher.match?([4, 5, 6, 7, 8])
61
61
  end
62
62
 
63
63
  def test_should_not_match_if_all_required_parameters_match_but_some_optional_parameters_do_not_match
64
64
  optionals = ParameterMatchers::Optionally.new(6, 7)
65
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
66
- assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 0])
65
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
66
+ assert !parameters_matcher.match?([4, 5, 6, 0])
67
67
  end
68
68
 
69
69
  def test_should_not_match_if_some_required_parameters_do_not_match_although_all_optional_parameters_do_match
70
70
  optionals = ParameterMatchers::Optionally.new(6, 7)
71
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
72
- assert !parameters_matcher.match?(actual_parameters = [4, 0, 6])
71
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
72
+ assert !parameters_matcher.match?([4, 0, 6])
73
73
  end
74
74
 
75
75
  def test_should_not_match_if_all_required_parameters_match_but_no_optional_parameters_match
76
76
  optionals = ParameterMatchers::Optionally.new(6, 7)
77
- parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
78
- assert !parameters_matcher.match?(actual_parameters = [4, 5, 0, 0])
77
+ parameters_matcher = ParametersMatcher.new([4, 5, optionals])
78
+ assert !parameters_matcher.match?([4, 5, 0, 0])
79
79
  end
80
80
 
81
81
  def test_should_match_if_actual_parameters_satisfy_matching_block
82
82
  parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 }
83
- assert parameters_matcher.match?(actual_parameters = [1, 2])
83
+ assert parameters_matcher.match?([1, 2])
84
84
  end
85
85
 
86
86
  def test_should_not_match_if_actual_parameters_do_not_satisfy_matching_block
87
87
  parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 }
88
- assert !parameters_matcher.match?(actual_parameters = [2, 3])
88
+ assert !parameters_matcher.match?([2, 3])
89
89
  end
90
90
 
91
91
  def test_should_remove_outer_array_braces
@@ -32,29 +32,29 @@ class SequenceTest < Test::Unit::TestCase
32
32
 
33
33
  def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index
34
34
  sequence = Sequence.new('name')
35
- expectation = FakeExpectation.new(satisfied = false)
35
+ expectation = FakeExpectation.new(false)
36
36
  sequence.constrain_as_next_in_sequence(expectation)
37
37
  assert sequence.satisfied_to_index?(0)
38
38
  end
39
39
 
40
40
  def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index
41
41
  sequence = Sequence.new('name')
42
- expectation = FakeExpectation.new(satisfied = false)
42
+ expectation = FakeExpectation.new(false)
43
43
  sequence.constrain_as_next_in_sequence(expectation)
44
44
  assert !sequence.satisfied_to_index?(1)
45
45
  end
46
46
 
47
47
  def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index
48
48
  sequence = Sequence.new('name')
49
- expectation = FakeExpectation.new(satisfied = true)
49
+ expectation = FakeExpectation.new(true)
50
50
  sequence.constrain_as_next_in_sequence(expectation)
51
51
  assert sequence.satisfied_to_index?(1)
52
52
  end
53
53
 
54
54
  def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index
55
55
  sequence = Sequence.new('name')
56
- expectation_one = FakeExpectation.new(satisfied = true)
57
- expectation_two = FakeExpectation.new(satisfied = false)
56
+ expectation_one = FakeExpectation.new(true)
57
+ expectation_two = FakeExpectation.new(false)
58
58
  sequence.constrain_as_next_in_sequence(expectation_one)
59
59
  sequence.constrain_as_next_in_sequence(expectation_two)
60
60
  assert !sequence.satisfied_to_index?(2)
@@ -62,8 +62,8 @@ class SequenceTest < Test::Unit::TestCase
62
62
 
63
63
  def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index
64
64
  sequence = Sequence.new('name')
65
- expectation_one = FakeExpectation.new(satisfied = true)
66
- expectation_two = FakeExpectation.new(satisfied = true)
65
+ expectation_one = FakeExpectation.new(true)
66
+ expectation_two = FakeExpectation.new(true)
67
67
  sequence.constrain_as_next_in_sequence(expectation_one)
68
68
  sequence.constrain_as_next_in_sequence(expectation_two)
69
69
  assert sequence.satisfied_to_index?(2)
@@ -78,8 +78,8 @@ class SequenceTest < Test::Unit::TestCase
78
78
 
79
79
  def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked
80
80
  sequence = Sequence.new('name')
81
- expectation_one = FakeExpectation.new(satisfied = false)
82
- expectation_two = FakeExpectation.new(satisfied = false)
81
+ expectation_one = FakeExpectation.new(false)
82
+ expectation_two = FakeExpectation.new(false)
83
83
  sequence.constrain_as_next_in_sequence(expectation_one)
84
84
  sequence.constrain_as_next_in_sequence(expectation_two)
85
85
  assert !expectation_two.ordering_constraints[0].allows_invocation_now?
@@ -87,8 +87,8 @@ class SequenceTest < Test::Unit::TestCase
87
87
 
88
88
  def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked
89
89
  sequence = Sequence.new('name')
90
- expectation_one = FakeExpectation.new(satisfied = true)
91
- expectation_two = FakeExpectation.new(satisfied = false)
90
+ expectation_one = FakeExpectation.new(true)
91
+ expectation_two = FakeExpectation.new(false)
92
92
  sequence.constrain_as_next_in_sequence(expectation_one)
93
93
  sequence.constrain_as_next_in_sequence(expectation_two)
94
94
  assert expectation_two.ordering_constraints[0].allows_invocation_now?
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: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 4
10
- version: 0.10.4
9
+ - 5
10
+ version: 0.10.5
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-02-10 00:00:00 +00:00
18
+ date: 2012-02-29 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -223,6 +223,7 @@ files:
223
223
  - test/acceptance/expected_invocation_count_test.rb
224
224
  - test/acceptance/failure_messages_test.rb
225
225
  - test/acceptance/issue_65_test.rb
226
+ - test/acceptance/issue_70_test.rb
226
227
  - test/acceptance/minitest_test.rb
227
228
  - test/acceptance/mocha_example_test.rb
228
229
  - test/acceptance/mocha_test_result_test.rb