Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-mocks
...
head fork: rspec/rspec-mocks
Checking mergeability… Don't worry, you can still create the pull request.
  • 13 commits
  • 7 files changed
  • 0 commit comments
  • 3 contributors
View
3  .travis.yml
@@ -6,12 +6,13 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
+ - 2.0.0
+ - 2.1.0
- ree
- jruby-18mode
- jruby-19mode
- rbx-18mode
- rbx-19mode
- - 2.0.0
matrix:
allow_failures:
- rvm: rbx-18mode
View
10 Changelog.md
@@ -1,3 +1,13 @@
+### 2.14.5 / 2014-02-01
+[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.4...v2.14.5)
+
+Bug Fixes:
+
+* Fix regression that caused block implementations to not receive all
+ args on 1.8.7 if the block also receives a block, due to Proc#arity
+ reporting `1` no matter how many args the block receives if it
+ receives a block, too. (Myron Marston)
+
### 2.14.4 / 2013-10-15
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.3...v2.14.4)
View
2  Gemfile
@@ -4,7 +4,7 @@ gemspec
%w[rspec rspec-core rspec-expectations].each do |lib|
library_path = File.expand_path("../../#{lib}", __FILE__)
- if File.exist?(library_path)
+ if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
gem lib, :path => library_path
else
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => '2-14-maintenance'
View
25 lib/rspec/mocks/message_expectation.rb
@@ -520,10 +520,27 @@ def call(*args, &block)
end.last
end
- def arg_slice_for(args, arity)
- if arity >= 0
- args.slice(0, arity)
- else
+ if RUBY_VERSION.to_f > 1.8
+ def arg_slice_for(args, arity)
+ if arity >= 0
+ args.slice(0, arity)
+ else
+ args
+ end
+ end
+ else
+ # 1.8.7's `arity` lies somtimes:
+ # Given:
+ # def print_arity(&b) puts b.arity; end
+ #
+ # This prints 1:
+ # print_arity { |a, b, c, &bl| }
+ #
+ # But this prints 3:
+ # print_arity { |a, b, c| }
+ #
+ # Given that it lies, we can't trust it and we don't slice the args.
+ def arg_slice_for(args, arity)
args
end
end
View
2  lib/rspec/mocks/version.rb
@@ -1,7 +1,7 @@
module RSpec
module Mocks
module Version
- STRING = '2.14.4'
+ STRING = '2.14.5'
end
end
end
View
11 spec/rspec/mocks/block_return_value_spec.rb
@@ -1,6 +1,17 @@
require "spec_helper"
describe "a double declaration with a block handed to:" do
+ # The "receives a block" part is important: 1.8.7 has a bug that reports the
+ # wrong arity when a block receives a block.
+ it 'forwards all given args to the block, even when it receives a block', :unless => RUBY_VERSION.to_s == '1.8.6' do
+ obj = Object.new
+ yielded_args = []
+ eval("obj.stub(:foo) { |*args, &bl| yielded_args << args }")
+ obj.foo(1, 2, 3)
+
+ expect(yielded_args).to eq([[1, 2, 3]])
+ end
+
describe "should_receive" do
it "returns the value of executing the block" do
obj = Object.new
View
12 spec/rspec/mocks/stub_chain_spec.rb
@@ -29,6 +29,18 @@ module Mocks
end
context "with two methods in chain" do
+ it "accepts any number of arguments to the stubbed messages" do
+ object.stub_chain(:msg1, :msg2).and_return(:return_value)
+
+ expect(object.msg1("nonsense", :value).msg2("another", :nonsense, 3.0, "value")).to eq(:return_value)
+ end
+
+ it "accepts any number of arguments to the stubbed messages with a return value from a hash" do
+ object.stub_chain(:msg1, :msg2 => :return_value)
+
+ expect(object.msg1("nonsense", :value).msg2("another", :nonsense, 3.0, "value")).to eq(:return_value)
+ end
+
context "using and_return" do
it "returns expected value from chaining two method calls" do
object.stub_chain(:msg1, :msg2).and_return(:return_value)

No commit comments for this range

Something went wrong with that request. Please try again.