mocha 0.9.1 → 0.9.2

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/RELEASE CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.9.2 (r355)
2
+ * Improved documentation to address [#22530] 'Mock methods with multiple return values not possible?'
3
+ * respond_with parameter matcher was not available in tests.
4
+ * Patch [#22630] Fix for a bug in running Rails tests with Ruby 1.8.7. Array#flatten was being called which in turn was checking whether each element responded to #to_ary. This check was using the two parameter version of #respond_to?, but Mock was only defining a one parameter version.
5
+
1
6
  = 0.9.1 (r349)
2
7
 
3
8
  * Fixed bug #21465 - expects & stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require 'rake/contrib/sshpublisher'
6
6
 
7
7
  module Mocha
8
- VERSION = "0.9.1"
8
+ VERSION = "0.9.2"
9
9
  end
10
10
 
11
11
  desc "Run all tests"
@@ -129,7 +129,7 @@ task 'examples' do
129
129
  end
130
130
  end
131
131
 
132
- Gem::manage_gems
132
+ Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0'
133
133
 
134
134
  specification = Gem::Specification.new do |s|
135
135
  s.name = "mocha"
@@ -249,6 +249,12 @@ module Mocha # :nodoc:
249
249
  # object.expected_method # => 1
250
250
  # object.expected_method # => 2
251
251
  # object.expected_method # => raises exception of class Exception1
252
+ # Note that in Ruby a method returning multiple values is exactly equivalent to a method returning an Array of those values.
253
+ # object = mock()
254
+ # object.stubs(:expected_method).returns([1, 2])
255
+ # x, y = object.expected_method
256
+ # x # => 1
257
+ # y # => 2
252
258
  def returns(*values)
253
259
  @return_values += ReturnValues.build(*values)
254
260
  self
@@ -165,9 +165,13 @@ module Mocha # :nodoc:
165
165
  end
166
166
  end
167
167
 
168
- def respond_to?(symbol)
168
+ def respond_to?(symbol, include_private = false)
169
169
  if @responder then
170
- @responder.respond_to?(symbol)
170
+ if @responder.method(:respond_to?).arity > 1
171
+ @responder.respond_to?(symbol, include_private)
172
+ else
173
+ @responder.respond_to?(symbol)
174
+ end
171
175
  else
172
176
  @expectations.matches_method?(symbol)
173
177
  end
@@ -23,4 +23,5 @@ require 'mocha/parameter_matchers/kind_of'
23
23
  require 'mocha/parameter_matchers/not'
24
24
  require 'mocha/parameter_matchers/optionally'
25
25
  require 'mocha/parameter_matchers/regexp_matches'
26
+ require 'mocha/parameter_matchers/responds_with'
26
27
  require 'mocha/parameter_matchers/yaml_equivalent'
@@ -176,4 +176,34 @@ class ParameterMatcherTest < Test::Unit::TestCase
176
176
  assert_failed(test_result)
177
177
  end
178
178
 
179
- end
179
+ def test_should_match_parameter_that_responds_with_specified_value
180
+ klass = Class.new do
181
+ def quack
182
+ 'quack'
183
+ end
184
+ end
185
+ duck = klass.new
186
+ test_result = run_test do
187
+ mock = mock()
188
+ mock.expects(:method).with(responds_with(:quack, 'quack'))
189
+ mock.method(duck)
190
+ end
191
+ assert_passed(test_result)
192
+ end
193
+
194
+ def test_should_not_match_parameter_that_does_not_respond_with_specified_value
195
+ klass = Class.new do
196
+ def quack
197
+ 'woof'
198
+ end
199
+ end
200
+ duck = klass.new
201
+ test_result = run_test do
202
+ mock = mock()
203
+ mock.expects(:method).with(responds_with(:quack, 'quack'))
204
+ mock.method(duck)
205
+ end
206
+ assert_failed(test_result)
207
+ end
208
+
209
+ end
@@ -287,4 +287,9 @@ class MockTest < Test::Unit::TestCase
287
287
  end
288
288
  end
289
289
 
290
+ def test_should_handle_respond_to_with_private_methods_param_without_error
291
+ mock = Mock.new
292
+ assert_nothing_raised{ mock.respond_to?(:object_id, false) }
293
+ end
294
+
290
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
@@ -9,11 +9,12 @@ autorequire: mocha
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-30 00:00:00 +01:00
12
+ date: 2008-11-03 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -216,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  requirements: []
217
218
 
218
219
  rubyforge_project: mocha
219
- rubygems_version: 1.1.1
220
+ rubygems_version: 1.3.0
220
221
  signing_key:
221
222
  specification_version: 2
222
223
  summary: Mocking and stubbing library