Sha256: a168332985bed6d4d11567d33a8b3cc765c3f04fb4971ca64a7b1b1ca8709564

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Nav::Group do
  before :each do
    @group = Nav::Group.new
    @item = mock('Nav::Item')
  end
  
  describe "#items" do
    it "read @items var" do
      @group.instance_variable_set(:@items, "Hello world")
      @group.items.should == "Hello world"
    end
    
    it "default is empty array" do
      @group.instance_variable_get(:@items).should == []
    end
  end
  
  describe "#add" do
    context "when arg is Hash" do
      it "create new item" do
        Nav::Item.should_receive(:new).with(:name => "New item")
        @group.add({:name => "New item"})
      end
        
      it "add created item to @items" do
        Nav::Item.stub(:new).and_return(@item)
        @group.add({:name => "New item"})
        @group.instance_variable_get(:@items).should == [@item]
      end
    end
    
    context "when arg is not Hash" do
      it "add item to @items" do
        @group.add(@item)      
        @group.instance_variable_get(:@items).should == [@item]
      end
    end
    
    context "when multi-params given" do
      it "add or create items" do
        [@item, @item_2].each {|i| i = mock('Nav::Item') }
      
        Nav::Item.should_receive(:new).with(:name => "New item").and_return(@item_2)
        @group.add(@item, {:name => "New item"}, @item_3)
      
        @group.instance_variable_get(:@items).should == [@item, @item_2, @item_3]
      end
    end
  end
  
  describe "#to_s" do
    it "render joined items" do
      @group.instance_variable_set(:@items, ["item", "item_2"])
      @group.to_s.should == "itemitem_2"
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
constructor-core-0.3.2 spec/lib/nav/group_spec.rb
constructor-core-0.3.1 spec/lib/nav/group_spec.rb
constructor-core-0.3.0 spec/lib/nav/group_spec.rb
constructor-core-0.2.14 spec/lib/nav/group_spec.rb
constructor-core-0.2.12 spec/lib/nav/group_spec.rb
constructor-core-0.2.11 spec/lib/nav/group_spec.rb
constructor-core-0.2.10 spec/lib/nav/group_spec.rb
constructor-core-0.2.9 spec/lib/nav/group_spec.rb
constructor-core-0.2.8 spec/lib/nav/group_spec.rb
constructor-core-0.2.6 spec/lib/nav/group_spec.rb
constructor-core-0.2.5 spec/lib/nav/group_spec.rb
constructor-core-0.2.4 spec/lib/nav/group_spec.rb
constructor-core-0.2.1 spec/lib/nav/group_spec.rb
constructor-cms-0.2.1 core/spec/lib/nav/group_spec.rb