Sha256: 987211aebf9e1bc38d157f7a3668e3666452a2e0e08b3f67d7f96cd6e870baa2

Contents?: true

Size: 1.93 KB

Versions: 17

Compression:

Stored size: 1.93 KB

Contents

require "examples/example_helper"

module RR
describe Double, "#bind with an existing method" do
  before do
    @space = Space.new
    @object = Object.new
    @method_name = :foobar
    def @object.foobar; :original_foobar; end
    @original_method = @object.method(:foobar)
    @object.methods.should include(@method_name.to_s)
    @double = Double.new(@space, @object, @method_name)
  end

  it "overrides the original method with the double's dispatching methods" do
    @object.respond_to?(:__rr__foobar).should == false
    @double.bind
    @object.respond_to?(:__rr__foobar).should == true

    rr_foobar_called = false
    (class << @object; self; end).class_eval do
      define_method :__rr__foobar do
        rr_foobar_called = true
      end
    end

    rr_foobar_called.should == false
    @object.foobar
    rr_foobar_called.should == true
  end

  it "stores original method in __rr__original_method_name" do
    @double.bind
    @object.respond_to?(:__rr__original_foobar).should == true
    @object.method(:__rr__original_foobar).should == @original_method
  end
end

describe Double, "#bind without an existing method" do
  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 "overrides the original method with the double's dispatching methods" do
    @object.respond_to?(:__rr__foobar).should == false
    @double.bind
    @object.respond_to?(:__rr__foobar).should == true

    rr_foobar_called = false
    (class << @object; self; end).class_eval do
      define_method :__rr__foobar do
        rr_foobar_called = true
      end
    end

    rr_foobar_called.should == false
    @object.foobar
    rr_foobar_called.should == true
  end

  it "stores original method in __rr__original_method_name" do
    @double.bind
    @object.respond_to?(:__rr__original_foobar).should == false
  end
end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rr-0.1.15 examples/rr/double/double_bind_example.rb
rr-0.2.5 examples/rr/double/double_bind_example.rb
rr-0.3.10 examples/rr/double/double_bind_example.rb
rr-0.3.2 examples/rr/double/double_bind_example.rb
rr-0.2.3 examples/rr/double/double_bind_example.rb
rr-0.3.0 examples/rr/double/double_bind_example.rb
rr-0.2.4 examples/rr/double/double_bind_example.rb
rr-0.3.11 examples/rr/double/double_bind_example.rb
rr-0.3.3 examples/rr/double/double_bind_example.rb
rr-0.3.4 examples/rr/double/double_bind_example.rb
rr-0.2.2 examples/rr/double/double_bind_example.rb
rr-0.3.1 examples/rr/double/double_bind_example.rb
rr-0.3.5 examples/rr/double/double_bind_example.rb
rr-0.3.7 examples/rr/double/double_bind_example.rb
rr-0.3.9 examples/rr/double/double_bind_example.rb
rr-0.3.6 examples/rr/double/double_bind_example.rb
rr-0.3.8 examples/rr/double/double_bind_example.rb