Sha256: e33bdc3d8967b642d8b7845d9238d3eb4791eb592600548802eb7f01bffabe6f

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe MoStash do

  it "should act like basic OpenStruct" do
    mo = MoStash.new
    mo.foo = "bar"

    mo.foo.should == "bar"
  end

  it "should allow basic Hash methods" do
    mo = MoStash.new
    mo.foo = "bar"
    mo[:baz] = "foo"

    mo[:foo].should == "bar"
    mo.baz.should == "foo"
  end

  it "should be initializable via a Hash" do
    mo = MoStash.new(:foo => "bar")

    mo.foo.should == "bar"
  end

  it "should be initializable via nested Hash" do
    h = {:foo => {:bar => "baz"}, :oh => "hai"}
    mo = MoStash.new h

    mo.foo.bar.should == "baz"
    mo.oh.should == "hai"
  end

  it "should allow values to be arrays" do
    mo = MoStash.new
    mo.foo = ['hello']

    mo.foo.first.should == "hello"
  end

  it "should automatically make a hash a MoStash" do
    mo = MoStash.new
    mo.foo = {:bar => 'baz'}

    mo.foo.bar.should == 'baz'
  end

  it "should automatically make a hash a Mostash if key already exist" do
    mo = MoStash.new( {:foo => {:bar => 'baz' } } )

    mo.foo = { :bar => 'new_baz' }
    mo.foo.bar.should == 'new_baz'
  end

  it "should correctly handle an array of hashes" do
    mo = MoStash.new
    mo.foo = [{:hey => 'you'}, {:oh => 'hai'}]

    mo.foo[1].oh.should == 'hai'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mostash-0.1.1 spec/mostash_spec.rb
mostash-0.1.0 spec/mostash_spec.rb