Sha256: f3d94c65916642b928bf2f5a494f33316f44402f64eeba1461a406605f640c40

Contents?: true

Size: 1.46 KB

Versions: 24

Compression:

Stored size: 1.46 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 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

24 entries across 24 versions & 1 rubygems

Version Path
awestruct-0.5.6.beta9 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta8 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta7 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta6 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta5 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta4 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta3 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta2 spec/awestruct/astruct_spec.rb
awestruct-0.5.6.beta spec/awestruct/astruct_spec.rb
awestruct-0.5.5 spec/awestruct/astruct_spec.rb
awestruct-0.5.4.2 spec/awestruct/astruct_spec.rb
awestruct-0.5.4.1 spec/awestruct/astruct_spec.rb
awestruct-0.5.4 spec/awestruct/astruct_spec.rb
awestruct-0.5.4.rc3 spec/astruct_spec.rb
awestruct-0.5.4.rc2 spec/astruct_spec.rb
awestruct-0.5.4.rc spec/astruct_spec.rb
awestruct-0.5.4.beta1 spec/astruct_spec.rb
awestruct-0.5.3 spec/astruct_spec.rb
awestruct-0.5.2.1 spec/astruct_spec.rb
awestruct-0.5.2 spec/astruct_spec.rb