Sha256: 80f49adbf134ee1cafec876958980ba0b3ef10373339069d473cffced52adff3

Contents?: true

Size: 900 Bytes

Versions: 14

Compression:

Stored size: 900 Bytes

Contents

require "more/spec_helper"

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

14 entries across 14 versions & 1 rubygems

Version Path
ruby_ext-0.4.25 spec/more/open_constructor_spec.rb
ruby_ext-0.4.24 spec/more/open_constructor_spec.rb
ruby_ext-0.4.23 spec/more/open_constructor_spec.rb
ruby_ext-0.4.22 spec/more/open_constructor_spec.rb
ruby_ext-0.4.21 spec/more/open_constructor_spec.rb
ruby_ext-0.4.20 spec/more/open_constructor_spec.rb
ruby_ext-0.4.19 spec/more/open_constructor_spec.rb
ruby_ext-0.4.18 spec/more/open_constructor_spec.rb
ruby_ext-0.4.17 spec/more/open_constructor_spec.rb
ruby_ext-0.4.16 spec/more/open_constructor_spec.rb
ruby_ext-0.4.15 spec/more/open_constructor_spec.rb
ruby_ext-0.4.14 spec/more/open_constructor_spec.rb
ruby_ext-0.4.13 spec/more/open_constructor_spec.rb
ruby_ext-0.4.12 spec/more/open_constructor_spec.rb