1 require File.dirname(__FILE__) + '/../spec_helper'
2 require File.dirname(__FILE__) + '/subtend_helper'
4 compile_extension('subtend_struct_define')
5 require File.dirname(__FILE__) + '/ext/subtend_struct_define'
7 describe "SubtendStructDefine" do
9 @s = SubtendStructDefine.new
12 it "rb_struct_define defines a structure" do
13 @s.rb_struct_define("MyStruct", "attr1", "attr2", "attr3")
14 instance = Struct::MyStruct.new
15 instance.members.sort.should == ["attr1", "attr2", "attr3"].sort
16 (instance.attr1 = 1).should == 1
17 (instance.attr2 = 2).should == 2
18 (instance.attr3 = 3).should == 3
19 # Verify that attributes are on an instance basis
20 Struct::MyStruct.new.attr1.should == nil
23 it "rb_struct_define allows for anonymous structures" do
24 klass = @s.rb_struct_define(nil, "attr1", "attr2", "attr3")
25 instance = klass.new()
26 instance.members.sort.should == ["attr1", "attr2", "attr3"].sort
27 (instance.attr1 = 1).should == 1
28 (instance.attr2 = 2).should == 2
29 (instance.attr3 = 3).should == 3