Sha256: 2636c189ce3ec8e5648a3549f24c9a703f683db34f4b1d0e42403f88070be554

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

require 'ronin/code/reference'

require 'spec_helper'

describe Code::Reference do
  before(:all) do
    class Thing

      def exposed
        1
      end

      protected

      def not_exposed
        2
      end

    end

    @object = Thing.new
    @ref = Code::Reference.new(@object)
  end

  it "should provide direct access to the referenced object" do
    @ref.value.should == @object
  end

  it "should be a kind of Reference" do
    @ref.kind_of?(Code::Reference).should == true
    @ref.is_a?(Code::Reference).should == true
    @ref.instance_of?(Code::Reference).should == true
  end

  it "should have the class of the referenced object" do
    @ref.class.should == Thing
  end

  it "should be a kind of the referenced object type" do
    @ref.kind_of?(Thing).should == true
    @ref.is_a?(Thing).should == true
    @ref.instance_of?(Thing).should == true
  end

  it "should be equal to itself" do
    @ref.eql?(@ref).should == true
    @ref.should == @ref
    @ref.should === @ref
  end

  it "should be equal to the referenced object" do
    @ref.eql?(@object).should == true
    @ref.should == @object
    @ref.should === @object
  end

  it "should respond to Reference methods" do
    @ref.respond_to?(:value).should == true
  end

  it "should respond to the methods of the referenced object" do
    @ref.respond_to?(:exposed).should == true
  end

  it "should relay method calls to the referenced object" do
    @ref.exposed.should == 1
  end

  it "should raise a NoMethodError when trying to call a protected or private method" do
    lambda { @ref.not_exposed }.should raise_error(NoMethodError)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ronin-0.1.1 spec/code/reference_spec.rb
ronin-0.1.2 spec/code/reference_spec.rb
ronin-0.1.4 spec/code/reference_spec.rb
ronin-0.1.3 spec/code/reference_spec.rb
ronin-0.2.2 spec/code/reference_spec.rb
ronin-0.2.1 spec/code/reference_spec.rb
ronin-0.2.0 spec/code/reference_spec.rb