Sha256: ca71cc596b9cc9402f3bab708ba29e51e2f6f8114f4258246d54ba66912cfced

Contents?: true

Size: 870 Bytes

Versions: 3

Compression:

Stored size: 870 Bytes

Contents

dir = File.dirname(__FILE__)
require "#{dir}/../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
    @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__rr__).should == false
    @double.bind
    @object.respond_to?(:__rr__foobar__rr__).should == true

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rr-0.1.0 examples/rr/double_bind_example.rb
rr-0.1.1 examples/rr/double_bind_example.rb
rr-0.1.2 examples/rr/double_bind_example.rb