Sha256: eeb6e59c43e9ca6dd0ef7f0d96c357f6e57f6dc545a3551bc481ce648a8a3a09

Contents?: true

Size: 862 Bytes

Versions: 4

Compression:

Stored size: 862 Bytes

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')
require 'simply_useful/core_ext/module/property_delegation'

class Pair
  attr_accessor :left, :right

  def initialize(left = nil, right = nil)
    self.left = left
    self.right = right
  end
end

class PairWrapper

  delegate_property :left, :right, :to => :backing_pair

  def initialize(backing_pair)
    @backing_pair = backing_pair
  end

  protected
  def backing_pair
    @backing_pair
  end
end

describe "property delegation" do
  it "should delegate property getters to the backing object" do
    pair = Pair.new(1,2)
    wrapper = PairWrapper.new(pair)

    wrapper.left.should eq(1)
    wrapper.right.should eq(2)
  end

  it "should delegate property setters to backing object" do
    wrapper = PairWrapper.new(Pair.new)

    wrapper.left = 2

    wrapper.left.should eq(2)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simply_useful-0.2.3 spec/core_ext/property_delegation_spec.rb
simply_useful-0.2.2 spec/core_ext/property_delegation_spec.rb
simply_useful-0.2.1 spec/core_ext/property_delegation_spec.rb
simply_useful-0.2.0 spec/core_ext/property_delegation_spec.rb