Sha256: 3a2d1871e0f61da7db0fc4a447a8bba14b797ded928b41601f15cc91df752579

Contents?: true

Size: 955 Bytes

Versions: 2

Compression:

Stored size: 955 Bytes

Contents

require 'RubyExt/require_base'
require 'spec'

module RubyExt
	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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
RubyExt-0.1.1 spec/open_constructor_spec.rb
RubyExt-0.1.2 spec/open_constructor_spec.rb