Sha256: b6df1f7d59b473ba65dfcee0c03689dbe30cc0c6146ef1fcc31657465f701b86

Contents?: true

Size: 961 Bytes

Versions: 3

Compression:

Stored size: 961 Bytes

Contents

require "spec_helper"
require "ruby_ext/open_constructor"

describe 'OpenConstructor' do
  class Test
    include OpenConstructor
    attr_accessor :name, :value
  end

  it 'should initialize atributes from Hash' do
    t = Test.new.set(:name => 'name', :value => 'value')
    [t.name, t.value].should == ['name', 'value']
  end
  
  it 'should initialize atributes from any Object' do
    t = Test.new.set(:name => 'name', :value => 'value')
    t2 = Test.new.set t
    [t2.name, t2.value].should == ['name', 'value']
  end
  
  it 'restrict copied values' do
    t = Test.new.set(:name => 'name', :value => 'value')
    t2 = Test.new.set t, [:name]
    [t2.name, t2.value].should == ['name', nil]
    
    t = {:name => 'name', :value => 'value'}
    t2 = Test.new.set t, [:name]
    [t2.name, t2.value].should == ['name', nil]
  end
  
  it 'to_hash' do
    h = {:name => 'name', :value => 'value'}
    t = Test.new.set h
    t.to_hash.should == h
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_ext-0.4.11 spec/open_constructor_spec.rb
ruby_ext-0.4.10 spec/open_constructor_spec.rb
ruby_ext-0.4.9 spec/open_constructor_spec.rb