Skip to content

Commit

Permalink
Merge space reset spec into space spec.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/pivotalrb/rr/trunk@1638 af276e61-6b34-4dac-905b-574b5f35ef33
  • Loading branch information
btakita committed Jun 19, 2008
1 parent 9dc67a7 commit c71510c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 141 deletions.
131 changes: 0 additions & 131 deletions spec/rr/space/space_reset_spec.rb

This file was deleted.

126 changes: 116 additions & 10 deletions spec/rr/space/space_spec.rb
Expand Up @@ -5,16 +5,6 @@ module RR
it_should_behave_like "Swapped Space"

describe ".method_missing" do
before(:each) do
@original_space = Space.instance
@space = Space.new
Space.instance = @space
end

after(:each) do
Space.instance = @original_space
end

it "proxies to a singleton instance of Space" do
create_double_args = nil
(class << @space; self; end).class_eval do
Expand Down Expand Up @@ -96,5 +86,121 @@ def @object.foobar(*args)
end
end
end

describe "#reset" do
before do
@space = Space.instance
@object1 = Object.new
@object2 = Object.new
@method_name = :foobar
end

it "removes the ordered doubles" do
double1 = @space.double_injection(@object1, :foobar1)
double2 = @space.double_injection(@object1, :foobar2)

double1 = Double.new(double1)
double2 = Double.new(double2)

double1.ordered
double2.ordered

@space.ordered_doubles.should_not be_empty

@space.reset
@space.ordered_doubles.should be_empty
end

it "resets all double_injections" do
double1 = @space.double_injection(@object1, @method_name)
double1_reset_calls = 0
(
class << double1;
self;
end).class_eval do
define_method(:reset) do ||
double1_reset_calls += 1
end
end
double2 = @space.double_injection(@object2, @method_name)
double2_reset_calls = 0
(
class << double2;
self;
end).class_eval do
define_method(:reset) do ||
double2_reset_calls += 1
end
end

@space.reset
double1_reset_calls.should == 1
double2_reset_calls.should == 1
end
end

describe "#reset_double" do
before do
@space = Space.new
@object = Object.new
@method_name = :foobar
end

it "resets the double_injections" do
double_injection = @space.double_injection(@object, @method_name)
@space.double_injections[@object][@method_name].should === double_injection
@object.methods.should include("__rr__#{@method_name}")

@space.reset_double(@object, @method_name)
@space.double_injections[@object][@method_name].should be_nil
@object.methods.should_not include("__rr__#{@method_name}")
end

it "removes the object from the double_injections map when it has no double_injections" do
double1 = @space.double_injection(@object, :foobar1)
double2 = @space.double_injection(@object, :foobar2)

@space.double_injections.include?(@object).should == true
@space.double_injections[@object][:foobar1].should_not be_nil
@space.double_injections[@object][:foobar2].should_not be_nil

@space.reset_double(@object, :foobar1)
@space.double_injections.include?(@object).should == true
@space.double_injections[@object][:foobar1].should be_nil
@space.double_injections[@object][:foobar2].should_not be_nil

@space.reset_double(@object, :foobar2)
@space.double_injections.include?(@object).should == false
end
end

describe "#reset_double_injections" do
before do
@object1 = Object.new
@object2 = Object.new
@method_name = :foobar
end

it "resets the double_injection and removes it from the double_injections list" do
double1 = @space.double_injection(@object1, @method_name)
double1_reset_calls = 0
(class << double1; self; end).class_eval do
define_method(:reset) do ||
double1_reset_calls += 1
end
end
double2 = @space.double_injection(@object2, @method_name)
double2_reset_calls = 0
(class << double2; self; end).class_eval do
define_method(:reset) do ||
double2_reset_calls += 1
end
end

@space.__send__(:reset_double_injections)
double1_reset_calls.should == 1
double2_reset_calls.should == 1
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -12,6 +12,7 @@
before do
@original_space = RR::Space.instance
RR::Space.instance = RR::Space.new
@space = RR::Space.instance
end

after(:each) do
Expand Down

0 comments on commit c71510c

Please sign in to comment.