Sha256: cb336ff00cca499b0073264c15acc9128f74177ddd9063da837809e7fec35ea5

Contents?: true

Size: 1.62 KB

Versions: 16

Compression:

Stored size: 1.62 KB

Contents

require 'awestruct/astruct'
require 'awestruct/page'

describe Awestruct::AStruct do 

  it "should initialize from hash provided in constructor" do
    s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
    s[:foo].should == 'bar'
    s['taco'].should == 'tasty'
  end

  it "should not have org, com, java defined" do
    s = Awestruct::AStruct.new
    s.java.should be_nil
    s.com.should be_nil
    s.org.should be_nil
  end

  it "should allow access to members through indifferent hash access" do
    s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
    s['foo'].should == 'bar'
    s[:foo].should == 'bar'

    s['taco'].should == 'tasty'
    s[:taco].should == 'tasty'
  end

  it "should allow method access to members" do
    s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
    s.foo.should == 'bar'
    s.taco.should == 'tasty'
  end

  it "should cascade AStructs to inner array members" do 
    s = Awestruct::AStruct.new( :foo=>[ { 'taco'=>'tasty' } ] )
    s.foo.first.taco.should == 'tasty'
  end

  it "should preserve the actual array instance holding any inner structs" do
    inner_hash = { 'taco'=>'tasty' }
    array = [ inner_hash ]
    s = Awestruct::AStruct.new( :foo=>array )
    s.foo.first.taco.should == 'tasty'
    s.foo.object_id.should == array.object_id
  end

  it "should cascade AStruct to inner hash value structs" do
    s = Awestruct::AStruct.new( :foo=>{ 'taco'=>'tasty' } ) 
    s.foo.taco.should == 'tasty'
  end

  it "should allow any method to be called, resulting in nil" do
    s = Awestruct::AStruct.new( :foo=>'bar' )
    s.foo.should == 'bar'
    s.taco.should be_nil
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
awestruct-0.6.7 spec/awestruct/astruct_spec.rb
awestruct-0.6.6 spec/awestruct/astruct_spec.rb
awestruct-0.6.5 spec/awestruct/astruct_spec.rb
awestruct-0.6.4 spec/awestruct/astruct_spec.rb
awestruct-0.6.3 spec/awestruct/astruct_spec.rb
awestruct-0.6.2 spec/awestruct/astruct_spec.rb
awestruct-0.6.1 spec/awestruct/astruct_spec.rb
awestruct-0.6.0 spec/awestruct/astruct_spec.rb
awestruct-0.6.0.RC1 spec/awestruct/astruct_spec.rb
awestruct-0.6.0.alpha4 spec/awestruct/astruct_spec.rb
awestruct-0.6.0.alpha3 spec/awestruct/astruct_spec.rb
awestruct-0.6.0.alpha1 spec/awestruct/astruct_spec.rb
awestruct-0.5.7 spec/awestruct/astruct_spec.rb
awestruct-0.5.7.RC2 spec/awestruct/astruct_spec.rb
awestruct-0.5.7.RC1 spec/awestruct/astruct_spec.rb
awestruct-0.5.6 spec/awestruct/astruct_spec.rb