Sha256: 033a6e91318369689097d6e1731c1fd22b613051591820bc5bf0a9c851fedf8c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'minitest/spec'
require File.expand_path('../../lib/structure', __FILE__)

MiniTest::Unit.autorun

describe Structure do
  before do
    @hash = {
      :name     => "John",
      :children => [ { :name => "Jim" } ],
      :location => { :city => { :name => "London" } }
    }
  end

  describe ".new" do
    before do
      @person = Structure.new(@hash)
    end

    it "structures nested hashes" do
      @person.location.city.name.must_equal "London"
    end

    it "structures hashes in arrays" do
      @person.children.must_be_instance_of Array
      @person.children.first.name.must_equal "Jim"
    end
  end

  describe "#=" do
    before do
      @person = Structure.new
    end

    it "structures nested hashes" do
      @person.location = { :city => { :name => "London" } }
      @person.location.city.name.must_equal "London"
    end

    it "structures hashes in arrays" do
      @person.children = [ { :name => "Jim" } ]
      @person.children.must_be_instance_of Array
      @person.children.first.name.must_equal "Jim"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
structure-0.1.0 test/structure_test.rb