Skip to content

Commit

Permalink
some mocks are not mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Feb 8, 2012
1 parent c8b9948 commit 17c259e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions lib/rspec/mocks/space.rb
Expand Up @@ -3,20 +3,20 @@ module Mocks
# @api private
class Space
def add(obj)
mocks << obj unless mocks.detect {|m| m.equal? obj}
receivers << obj unless receivers.detect {|m| m.equal? obj}
end

def verify_all
mocks.each do |mock|
receivers.each do |mock|
mock.rspec_verify
end
end

def reset_all
mocks.each do |mock|
receivers.each do |mock|
mock.rspec_reset
end
mocks.clear
receivers.clear
expectation_ordering.clear
end

Expand All @@ -26,10 +26,9 @@ def expectation_ordering

private

def mocks
@mocks ||= []
def receivers
@receivers ||= []
end

end
end
end
4 changes: 2 additions & 2 deletions spec/rspec/mocks/any_instance_spec.rb
Expand Up @@ -769,14 +769,14 @@ class RSpec::SampleRspecTestClass;end

it "adds an class to the current space when #any_instance is invoked" do
klass.any_instance
RSpec::Mocks::space.send(:mocks).should include(klass)
RSpec::Mocks::space.send(:receivers).should include(klass)
end

it "adds an instance to the current space when stubbed method is invoked" do
klass.any_instance.stub(:foo)
instance = klass.new
instance.foo
RSpec::Mocks::space.send(:mocks).should include(instance)
RSpec::Mocks::space.send(:receivers).should include(instance)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/mock_space_spec.rb
Expand Up @@ -40,7 +40,7 @@ def reset?
it "clears internal mocks on reset_all" do
@space.add(double("mock"))
@space.reset_all
@space.instance_eval { mocks.empty? }.should be_true
@space.instance_eval { receivers.empty? }.should be_true
end
it "resets the ordering" do
@space.reset_all
Expand Down

0 comments on commit 17c259e

Please sign in to comment.