Sha256: d6a0421ada6e8416f568b28cf4d75d49290142b33bc0b99b29fde62d4d076bcb

Contents?: true

Size: 981 Bytes

Versions: 16

Compression:

Stored size: 981 Bytes

Contents

require 'spec'

dir = File.dirname __FILE__
require "#{dir}/spec_require"
require "#{dir}/../lib/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

16 entries across 16 versions & 1 rubygems

Version Path
ruby-ext-0.2.16 spec/open_constructor_spec.rb
ruby-ext-0.2.15 spec/open_constructor_spec.rb
ruby-ext-0.2.13 spec/open_constructor_spec.rb
ruby-ext-0.2.12 spec/open_constructor_spec.rb
ruby-ext-0.2.11 spec/open_constructor_spec.rb
ruby-ext-0.2.10 spec/open_constructor_spec.rb
ruby-ext-0.2.9 spec/open_constructor_spec.rb
ruby-ext-0.2.8 spec/open_constructor_spec.rb
ruby-ext-0.2.7 spec/open_constructor_spec.rb
ruby-ext-0.2.6 spec/open_constructor_spec.rb
ruby-ext-0.2.5 spec/open_constructor_spec.rb
ruby-ext-0.2.4 spec/open_constructor_spec.rb
ruby-ext-0.2.3 spec/open_constructor_spec.rb
ruby-ext-0.2.2 spec/open_constructor_spec.rb
ruby-ext-0.2.1 spec/open_constructor_spec.rb
ruby-ext-0.2.0 spec/open_constructor_spec.rb