Skip to content

Commit

Permalink
Improve space spec.
Browse files Browse the repository at this point in the history
- The old spec only checked the number of proxies returned,
  and didn't actually check that it returned the right ones.
- The old spec only tested who were instances of the given
  class, and did not check instances of subclasses.
  • Loading branch information
myronmarston committed Aug 21, 2013
1 parent 6df516a commit 41217bf
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions spec/rspec/mocks/space_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ module RSpec::Mocks
describe "#proxies_of(klass)" do
let(:space) { Space.new }

before do
space.proxy_for(Object.new)
space.proxy_for(Object.new)
space.proxy_for(Array.new)
space.proxy_for(String.new)
it 'returns proxies' do
space.proxy_for("")
expect(space.proxies_of(String).map(&:class)).to eq([PartialMockProxy])
end

it 'returns the proxies for objects of the same type as klass' do
expect(space.proxies_of(String).size).to eq 1
expect(space.proxies_of(String)).to be_all { |obj| obj.is_a? RSpec::Mocks::PartialMockProxy }
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

Expand Down

0 comments on commit 41217bf

Please sign in to comment.