Sha256: d019283f7ed25a693400b04ca4bb28713370481926f19cd8945d9a7fa7a0c242

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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 correctly handle an array of hashes" do
    mo = MoStash.new
    mo.foo = [{:hey => 'you'}, {:oh => 'hai'}]

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

  it "should create method when new method called" do
    mo = MoStash.new
    mo.foo = "bar"

    mo.methods.should include("foo")
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mostash-0.0.2 spec/mostash_spec.rb
mostash-0.0.1 spec/mostash_spec.rb