Sha256: 8caefe1fdc5b1eb3b96990e29afb3c2dd6d10c18458fa660af39f0fec284df11

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

dir = File.dirname(__FILE__)
require "#{dir}/../example_helper"

module RR
describe Double, "#reset", :shared => true do
  it "cleans up by removing the __rr__ method" do
    @double.bind
    @object.methods.should include("__rr__foobar")

    @double.reset
    @object.methods.should_not include("__rr__foobar")
  end
end

describe Double, "#reset when method does not exist" do
  it_should_behave_like "RR::Double#reset"

  before do
    @space = Space.new
    @object = Object.new
    @method_name = :foobar
    @object.methods.should_not include(@method_name.to_s)
    @double = Double.new(@space, @object, @method_name)
  end

  it "removes the method" do
    @double.bind
    @object.methods.should include(@method_name.to_s)

    @double.reset
    @object.methods.should_not include(@method_name.to_s)
    proc {@object.foobar}.should raise_error(NoMethodError)
  end
end

describe Double, "#reset when method exists" do
  it_should_behave_like "RR::Double#reset"

  before do
    @space = Space.new
    @object = Object.new
    @method_name = :foobar
    def @object.foobar
      :original_foobar
    end
    @object.methods.should include(@method_name.to_s)
    @original_method = @object.method(@method_name)
    @double = Double.new(@space, @object, @method_name)
  end

  it "removes the method" do
    @double.bind
    @object.methods.should include(@method_name.to_s)

    @double.reset
    @object.methods.should include(@method_name.to_s)
    @object.foobar.should == :original_foobar
  end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rr-0.1.3 examples/rr/double_reset_example.rb
rr-0.1.4 examples/rr/double_reset_example.rb
rr-0.1.5 examples/rr/double_reset_example.rb
rr-0.1.6 examples/rr/double_reset_example.rb