Skip to content
Browse files

move structur behaviors into structure_spec

  • Loading branch information...
1 parent 4fc13d7 commit 56acce42754ed3680e119311fdfced32a7579ee5 @emonti committed
Showing with 44 additions and 43 deletions.
  1. +44 −0 spec/structure_spec.rb
  2. +0 −43 spec/type_behaviors.rb
View
44 spec/structure_spec.rb
@@ -1,6 +1,50 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'type_behaviors'
+# Applies to structures
+shared_examples_for "a structure" do
+
+ it "should return a value instance with a reference back to itself" do
+ s = @struct.instance()
+ s.rstruct_type.should == @struct
+ end
+
+ context "struct instance" do
+ it "should expose the same fields as the struct they belong to" do
+ @struct.field_names.each do |name|
+ name = name.to_s if RUBY_VERSION < '1.9'
+ @instance.members.should include(name)
+ end
+ end
+
+ it "should allow struct field values to be set and retrieved with accessors" do
+ @values.each do |k,v|
+ @instance.__send__(k).should be_nil
+ @instance.__send__("#{k}=", v).should == v
+ @instance.__send__(k).should == v
+ end
+ end
+
+ it "should allow field values to be set with arguments to instance creation" do
+ s=@struct.instance(@values)
+ s.rstruct_type.should == @struct
+ @values.each { |k,v| s.__send__(k).should == v }
+ end
+
+ it "should yield itself to a block on instance creation" do
+ i=@struct.instance do |s|
+ @values.each do |k,v|
+ s.__send__(k).should be_nil
+ s.__send__("#{k}=", v).should == v
+ s.__send__(k).should == v
+ end
+ end
+
+ @values.each { |k,v| i.__send__(k).should == v }
+ end
+ end
+end
+
describe Rstruct::Structure do
context "initialization" do
it "requires a block" do
View
43 spec/type_behaviors.rb
@@ -115,47 +115,4 @@
end
end
-# Applies to structures
-shared_examples_for "a structure" do
-
- it "should return a value instance with a reference back to itself" do
- s = @struct.instance()
- s.rstruct_type.should == @struct
- end
-
- context "struct instance" do
- it "should expose the same fields as the struct they belong to" do
- @struct.field_names.each do |name|
- name = name.to_s if RUBY_VERSION < '1.9'
- @instance.members.should include(name)
- end
- end
-
- it "should allow struct field values to be set and retrieved with accessors" do
- @values.each do |k,v|
- @instance.__send__(k).should be_nil
- @instance.__send__("#{k}=", v).should == v
- @instance.__send__(k).should == v
- end
- end
-
- it "should allow field values to be set with arguments to instance creation" do
- s=@struct.instance(@values)
- s.rstruct_type.should == @struct
- @values.each { |k,v| s.__send__(k).should == v }
- end
-
- it "should yield itself to a block on instance creation" do
- i=@struct.instance do |s|
- @values.each do |k,v|
- s.__send__(k).should be_nil
- s.__send__("#{k}=", v).should == v
- s.__send__(k).should == v
- end
- end
-
- @values.each { |k,v| i.__send__(k).should == v }
- end
- end
-end

0 comments on commit 56acce4

Please sign in to comment.
Something went wrong with that request. Please try again.