[DRE-commits] [ruby-rspec-mocks] 01/04: Imported Upstream version 2.14.5
Cédric Boutillier
boutil at moszumanska.debian.org
Sat Feb 15 23:36:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
boutil pushed a commit to annotated tag debian/2.14.5-1
in repository ruby-rspec-mocks.
commit 0144979f47ecc9079d8754e2be01642399f134a1
Author: Cédric Boutillier <boutil at debian.org>
Date: Sun Feb 16 00:11:06 2014 +0100
Imported Upstream version 2.14.5
---
Changelog.md | 20 ++++
checksums.yaml.gz | Bin 0 -> 271 bytes
lib/rspec/mocks.rb | 4 +
lib/rspec/mocks/any_instance/chain.rb | 3 +-
lib/rspec/mocks/any_instance/recorder.rb | 13 ++-
lib/rspec/mocks/any_instance/stub_chain.rb | 4 +-
lib/rspec/mocks/matchers/receive.rb | 1 +
lib/rspec/mocks/message_expectation.rb | 25 ++++-
lib/rspec/mocks/method_double.rb | 6 ++
lib/rspec/mocks/proxy.rb | 7 ++
lib/rspec/mocks/space.rb | 8 +-
lib/rspec/mocks/version.rb | 2 +-
metadata.yml | 115 +++++++++------------
.../mocks/any_instance/message_chains_spec.rb | 9 +-
spec/rspec/mocks/any_instance_spec.rb | 24 +++++
spec/rspec/mocks/block_return_value_spec.rb | 11 ++
spec/rspec/mocks/matchers/receive_spec.rb | 8 ++
spec/rspec/mocks/space_spec.rb | 32 ++++++
spec/rspec/mocks/stub_chain_spec.rb | 12 +++
19 files changed, 220 insertions(+), 84 deletions(-)
diff --git a/Changelog.md b/Changelog.md
index 55ad5a6..fbce905 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,3 +1,23 @@
+### 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)
+
+Bug Fixes:
+
+* Fix issue where unstubing methods on "any instances" would not
+ remove stubs on existing instances (Jon Rowe)
+* Fix issue with receive(:message) do ... end precedence preventing
+ the usage of modifications (`and_return` etc) (Jon Rowe)
+
### 2.14.3 / 2013-08-08
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.2...v2.14.3)
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
new file mode 100644
index 0000000..87877c7
Binary files /dev/null and b/checksums.yaml.gz differ
diff --git a/lib/rspec/mocks.rb b/lib/rspec/mocks.rb
index ba724ea..76de8f1 100644
--- a/lib/rspec/mocks.rb
+++ b/lib/rspec/mocks.rb
@@ -26,6 +26,10 @@ module RSpec
space.proxy_for(object)
end
+ def proxies_of(klass)
+ space.proxies_of(klass)
+ end
+
def any_instance_recorder_for(klass)
space.any_instance_recorder_for(klass)
end
diff --git a/lib/rspec/mocks/any_instance/chain.rb b/lib/rspec/mocks/any_instance/chain.rb
index 04b985a..a9c9265 100644
--- a/lib/rspec/mocks/any_instance/chain.rb
+++ b/lib/rspec/mocks/any_instance/chain.rb
@@ -2,7 +2,8 @@ module RSpec
module Mocks
module AnyInstance
class Chain
- def initialize(*args, &block)
+ def initialize(recorder, *args, &block)
+ @recorder = recorder
@expectation_args = args
@expectation_block = block
end
diff --git a/lib/rspec/mocks/any_instance/recorder.rb b/lib/rspec/mocks/any_instance/recorder.rb
index 64b0a8f..6786db6 100644
--- a/lib/rspec/mocks/any_instance/recorder.rb
+++ b/lib/rspec/mocks/any_instance/recorder.rb
@@ -11,10 +11,11 @@ module RSpec
# @see Chain
class Recorder
# @private
- attr_reader :message_chains
+ attr_reader :message_chains, :stubs
def initialize(klass)
@message_chains = MessageChains.new
+ @stubs = Hash.new { |hash,key| hash[key] = [] }
@observed_methods = []
@played_methods = {}
@klass = klass
@@ -32,7 +33,7 @@ module RSpec
end
else
observe!(method_name_or_method_map)
- message_chains.add(method_name_or_method_map, StubChain.new(method_name_or_method_map, &block))
+ message_chains.add(method_name_or_method_map, StubChain.new(self, method_name_or_method_map, &block))
end
end
@@ -44,7 +45,7 @@ module RSpec
def stub_chain(*method_names_and_optional_return_values, &block)
normalize_chain(*method_names_and_optional_return_values) do |method_name, args|
observe!(method_name)
- message_chains.add(method_name, StubChainChain.new(*args, &block))
+ message_chains.add(method_name, StubChainChain.new(self, *args, &block))
end
end
@@ -56,7 +57,7 @@ module RSpec
def should_receive(method_name, &block)
@expectation_set = true
observe!(method_name)
- message_chains.add(method_name, PositiveExpectationChain.new(method_name, &block))
+ message_chains.add(method_name, PositiveExpectationChain.new(self, method_name, &block))
end
def should_not_receive(method_name, &block)
@@ -72,6 +73,10 @@ module RSpec
raise RSpec::Mocks::MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
end
message_chains.remove_stub_chains_for!(method_name)
+ ::RSpec::Mocks.proxies_of(@klass).each do |proxy|
+ stubs[method_name].each { |stub| proxy.remove_single_stub(method_name, stub) }
+ end
+ stubs[method_name].clear
stop_observing!(method_name) unless message_chains.has_expectation?(method_name)
end
diff --git a/lib/rspec/mocks/any_instance/stub_chain.rb b/lib/rspec/mocks/any_instance/stub_chain.rb
index 9b1712a..b1368f5 100644
--- a/lib/rspec/mocks/any_instance/stub_chain.rb
+++ b/lib/rspec/mocks/any_instance/stub_chain.rb
@@ -14,7 +14,9 @@ module RSpec
def create_message_expectation_on(instance)
proxy = ::RSpec::Mocks.proxy_for(instance)
expected_from = IGNORED_BACKTRACE_LINE
- proxy.add_stub(expected_from, *@expectation_args, &@expectation_block)
+ stub = proxy.add_stub(expected_from, *@expectation_args, &@expectation_block)
+ @recorder.stubs[stub.message] << stub
+ stub
end
def invocation_order
diff --git a/lib/rspec/mocks/matchers/receive.rb b/lib/rspec/mocks/matchers/receive.rb
index 824d815..c403cce 100644
--- a/lib/rspec/mocks/matchers/receive.rb
+++ b/lib/rspec/mocks/matchers/receive.rb
@@ -76,6 +76,7 @@ module RSpec
@recorded_customizations.each do |customization|
customization.playback_onto(expectation)
end
+ expectation
end
class Customization
diff --git a/lib/rspec/mocks/message_expectation.rb b/lib/rspec/mocks/message_expectation.rb
index 99be4c9..db3c641 100644
--- a/lib/rspec/mocks/message_expectation.rb
+++ b/lib/rspec/mocks/message_expectation.rb
@@ -520,10 +520,27 @@ module RSpec
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
diff --git a/lib/rspec/mocks/method_double.rb b/lib/rspec/mocks/method_double.rb
index 268e77b..e8ccaa8 100644
--- a/lib/rspec/mocks/method_double.rb
+++ b/lib/rspec/mocks/method_double.rb
@@ -254,6 +254,12 @@ module RSpec
end
# @private
+ def remove_single_stub(stub)
+ stubs.delete(stub)
+ restore_original_method if stubs.empty? && expectations.empty?
+ end
+
+ # @private
def raise_method_not_stubbed_error
raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
end
diff --git a/lib/rspec/mocks/proxy.rb b/lib/rspec/mocks/proxy.rb
index 5dc63b4..8960d3e 100644
--- a/lib/rspec/mocks/proxy.rb
+++ b/lib/rspec/mocks/proxy.rb
@@ -16,6 +16,9 @@ module RSpec
end
# @private
+ attr_reader :object
+
+ # @private
def null_object?
@null_object
end
@@ -100,6 +103,10 @@ module RSpec
method_double[method_name].remove_stub
end
+ def remove_single_stub(method_name, stub)
+ method_double[method_name].remove_single_stub(stub)
+ end
+
# @private
def verify
method_doubles.each {|d| d.verify}
diff --git a/lib/rspec/mocks/space.rb b/lib/rspec/mocks/space.rb
index d8fdf20..c6a057a 100644
--- a/lib/rspec/mocks/space.rb
+++ b/lib/rspec/mocks/space.rb
@@ -5,8 +5,8 @@ module RSpec
attr_reader :proxies, :any_instance_recorders
def initialize
- @proxies = {}
- @any_instance_recorders = {}
+ @proxies = {}
+ @any_instance_recorders = {}
end
def verify_all
@@ -46,6 +46,10 @@ module RSpec
any_instance_recorders.delete(klass.__id__)
end
+ def proxies_of(klass)
+ proxies.values.select { |proxy| klass === proxy.object }
+ end
+
def proxy_for(object)
id = id_for(object)
proxies.fetch(id) do
diff --git a/lib/rspec/mocks/version.rb b/lib/rspec/mocks/version.rb
index efeffa2..762e214 100644
--- a/lib/rspec/mocks/version.rb
+++ b/lib/rspec/mocks/version.rb
@@ -1,7 +1,7 @@
module RSpec
module Mocks
module Version
- STRING = '2.14.3'
+ STRING = '2.14.5'
end
end
end
diff --git a/metadata.yml b/metadata.yml
index 8706671..738ceb2 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,71 +1,56 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
name: rspec-mocks
-version: !ruby/object:Gem::Version
- prerelease:
- version: 2.14.3
+version: !ruby/object:Gem::Version
+ version: 2.14.5
platform: ruby
-authors:
+authors:
- Steven Baker
- David Chelimsky
autorequire:
bindir: bin
cert_chain: []
-date: 2013-08-09 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
+
+date: 2014-02-01 00:00:00 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+ version_requirements: &id001 !ruby/object:Gem::Requirement
+ requirements:
- - ~>
- - !ruby/object:Gem::Version
+ - !ruby/object:Gem::Version
version: 10.0.0
- none: false
prerelease: false
name: rake
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 10.0.0
- none: false
type: :development
-- !ruby/object:Gem::Dependency
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
+ requirement: *id001
+- !ruby/object:Gem::Dependency
+ version_requirements: &id002 !ruby/object:Gem::Requirement
+ requirements:
- - ~>
- - !ruby/object:Gem::Version
+ - !ruby/object:Gem::Version
version: 1.1.9
- none: false
prerelease: false
name: cucumber
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 1.1.9
- none: false
type: :development
-- !ruby/object:Gem::Dependency
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
+ requirement: *id002
+- !ruby/object:Gem::Dependency
+ version_requirements: &id003 !ruby/object:Gem::Requirement
+ requirements:
- - ~>
- - !ruby/object:Gem::Version
- version: '0.5'
- none: false
+ - !ruby/object:Gem::Version
+ version: "0.5"
prerelease: false
name: aruba
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: '0.5'
- none: false
type: :development
+ requirement: *id003
description: RSpec's 'test double' framework, with support for stubbing and mocking
email: rspec-users at rubyforge.org
executables: []
+
extensions: []
+
extra_rdoc_files: []
-files:
+
+files:
- lib/rspec/mocks.rb
- lib/rspec/mocks/any_instance/chain.rb
- lib/rspec/mocks/any_instance/expectation_chain.rb
@@ -188,6 +173,7 @@ files:
- spec/rspec/mocks/precise_counts_spec.rb
- spec/rspec/mocks/record_messages_spec.rb
- spec/rspec/mocks/serialization_spec.rb
+- spec/rspec/mocks/space_spec.rb
- spec/rspec/mocks/stash_spec.rb
- spec/rspec/mocks/stub_chain_spec.rb
- spec/rspec/mocks/stub_implementation_spec.rb
@@ -200,38 +186,32 @@ files:
- spec/rspec/mocks_spec.rb
- spec/spec_helper.rb
homepage: http://github.com/rspec/rspec-mocks
-licenses:
+licenses:
- MIT
+metadata: {}
+
post_install_message:
-rdoc_options:
+rdoc_options:
- --charset=UTF-8
-require_paths:
+require_paths:
- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - ! '>='
- - !ruby/object:Gem::Version
- version: '0'
- segments:
- - 0
- hash: -4603029701728341322
- none: false
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - ! '>='
- - !ruby/object:Gem::Version
- version: '0'
- segments:
- - 0
- hash: -4603029701728341322
- none: false
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - &id004
+ - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - *id004
requirements: []
+
rubyforge_project: rspec
-rubygems_version: 1.8.24
+rubygems_version: 2.0.3
signing_key:
-specification_version: 3
-summary: rspec-mocks-2.14.3
-test_files:
+specification_version: 4
+summary: rspec-mocks-2.14.5
+test_files:
- features/README.md
- features/Scope.md
- features/Upgrade.md
@@ -314,6 +294,7 @@ test_files:
- spec/rspec/mocks/precise_counts_spec.rb
- spec/rspec/mocks/record_messages_spec.rb
- spec/rspec/mocks/serialization_spec.rb
+- spec/rspec/mocks/space_spec.rb
- spec/rspec/mocks/stash_spec.rb
- spec/rspec/mocks/stub_chain_spec.rb
- spec/rspec/mocks/stub_implementation_spec.rb
diff --git a/spec/rspec/mocks/any_instance/message_chains_spec.rb b/spec/rspec/mocks/any_instance/message_chains_spec.rb
index 398d4db..b8f1a0e 100644
--- a/spec/rspec/mocks/any_instance/message_chains_spec.rb
+++ b/spec/rspec/mocks/any_instance/message_chains_spec.rb
@@ -1,9 +1,10 @@
require 'spec_helper'
describe RSpec::Mocks::AnyInstance::MessageChains do
+ let(:recorder) { double }
let(:chains) { RSpec::Mocks::AnyInstance::MessageChains.new }
- let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new }
- let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new }
+ let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new recorder }
+ let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new recorder }
it "knows if a method does not have an expectation set on it" do
chains.add(:method_name, stub_chain)
@@ -19,7 +20,7 @@ describe RSpec::Mocks::AnyInstance::MessageChains do
it "can remove all stub chains" do
chains.add(:method_name, stub_chain)
chains.add(:method_name, expectation_chain)
- chains.add(:method_name, RSpec::Mocks::AnyInstance::StubChain.new)
+ chains.add(:method_name, RSpec::Mocks::AnyInstance::StubChain.new(recorder))
chains.remove_stub_chains_for!(:method_name)
expect(chains[:method_name]).to eq([expectation_chain])
@@ -33,7 +34,7 @@ describe RSpec::Mocks::AnyInstance::MessageChains do
it "allows multiple stub chains for a method" do
chains.add(:method_name, stub_chain)
- chains.add(:method_name, another_stub_chain = RSpec::Mocks::AnyInstance::StubChain.new)
+ chains.add(:method_name, another_stub_chain = RSpec::Mocks::AnyInstance::StubChain.new(recorder))
expect(chains[:method_name]).to eq([stub_chain, another_stub_chain])
end
end
diff --git a/spec/rspec/mocks/any_instance_spec.rb b/spec/rspec/mocks/any_instance_spec.rb
index d476866..886b29d 100644
--- a/spec/rspec/mocks/any_instance_spec.rb
+++ b/spec/rspec/mocks/any_instance_spec.rb
@@ -295,6 +295,30 @@ module RSpec
expect(klass.new.existing_method).to eq(:existing_method_return_value)
end
+ it "removes stubs even if they have already been invoked" do
+ klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
+ obj = klass.new
+ obj.existing_method
+ klass.any_instance.unstub(:existing_method)
+ expect(obj.existing_method).to eq(:existing_method_return_value)
+ end
+
+ it "removes stubs from sub class after invokation when super class was originally stubbed" do
+ klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
+ obj = Class.new(klass).new
+ expect(obj.existing_method).to eq(:any_instance_value)
+ klass.any_instance.unstub(:existing_method)
+ expect(obj.existing_method).to eq(:existing_method_return_value)
+ end
+
+ it "does not remove any stubs set directly on an instance" do
+ klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
+ obj = klass.new
+ obj.stub(:existing_method).and_return(:local_method)
+ klass.any_instance.unstub(:existing_method)
+ expect(obj.existing_method).to eq(:local_method)
+ end
+
it "does not remove any expectations with the same method name" do
klass.any_instance.should_receive(:existing_method_with_arguments).with(3).and_return(:three)
klass.any_instance.stub(:existing_method_with_arguments).with(1)
diff --git a/spec/rspec/mocks/block_return_value_spec.rb b/spec/rspec/mocks/block_return_value_spec.rb
index 65a1ad2..fa61f6a 100644
--- a/spec/rspec/mocks/block_return_value_spec.rb
+++ b/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
diff --git a/spec/rspec/mocks/matchers/receive_spec.rb b/spec/rspec/mocks/matchers/receive_spec.rb
index 9e4a504..69ef988 100644
--- a/spec/rspec/mocks/matchers/receive_spec.rb
+++ b/spec/rspec/mocks/matchers/receive_spec.rb
@@ -32,6 +32,14 @@ module RSpec
expect(receiver.foo).to eq(4)
end
+ it 'allows chaining off a `do...end` block implementation to be provided' do
+ wrapped.to receive(:foo) do
+ 4
+ end.and_return(6)
+
+ expect(receiver.foo).to eq(6)
+ end
+
it 'allows a `{ ... }` block implementation to be provided' do
wrapped.to receive(:foo) { 5 }
expect(receiver.foo).to eq(5)
diff --git a/spec/rspec/mocks/space_spec.rb b/spec/rspec/mocks/space_spec.rb
new file mode 100644
index 0000000..7930614
--- /dev/null
+++ b/spec/rspec/mocks/space_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+module RSpec::Mocks
+ describe Space do
+
+ describe "#proxies_of(klass)" do
+ let(:space) { Space.new }
+
+ it 'returns proxies' do
+ space.proxy_for("")
+ expect(space.proxies_of(String).map(&:class)).to eq([Proxy])
+ end
+
+ it 'returns only the proxies whose object is an instance of the given class' do
+ grandparent_class = Class.new
+ parent_class = Class.new(grandparent_class)
+ child_class = Class.new(parent_class)
+
+ grandparent = grandparent_class.new
+ parent = parent_class.new
+ child = child_class.new
+
+ grandparent_proxy = space.proxy_for(grandparent)
+ parent_proxy = space.proxy_for(parent)
+ child_proxy = space.proxy_for(child)
+
+ expect(space.proxies_of(parent_class)).to match_array([parent_proxy, child_proxy])
+ end
+ end
+
+ end
+end
diff --git a/spec/rspec/mocks/stub_chain_spec.rb b/spec/rspec/mocks/stub_chain_spec.rb
index 4399fd7..f3c9a62 100644
--- a/spec/rspec/mocks/stub_chain_spec.rb
+++ b/spec/rspec/mocks/stub_chain_spec.rb
@@ -29,6 +29,18 @@ module RSpec
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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-rspec-mocks.git
More information about the Pkg-ruby-extras-commits
mailing list