spec/lib/simple_navigation/configuration_spec.rb in simple-navigation-2.0.1 vs spec/lib/simple_navigation/configuration_spec.rb in simple-navigation-2.1.0

- old
+ new

@@ -127,24 +127,64 @@ @config.autogenerate_item_ids.should be_true end it "should set auto_highlight to true as default" do @config.auto_highlight.should be_true end + it "should set the id_generator" do + @config.id_generator.should_not be_nil + end end describe 'items' do before(:each) do @container = stub(:items_container) SimpleNavigation::ItemContainer.stub!(:new).and_return(@container) end - it "should should yield an new ItemContainer" do - @config.items do |container| - container.should == @container + context 'block given' do + context 'items_provider specified' do + it {lambda {@config.items(stub(:provider)) {}}.should raise_error} end + context 'no items_provider specified' do + it "should should yield an new ItemContainer" do + @config.items do |container| + container.should == @container + end + end + it "should assign the ItemContainer to an instance-var" do + @config.items {} + @config.primary_navigation.should == @container + end + it "should not set the items on the container" do + @container.should_not_receive(:items=) + @config.items {} + end + end end - it "should assign the ItemContainer to an instance-var" do - @config.items {} - @config.primary_navigation.should == @container + context 'no block given' do + context 'items_provider specified' do + before(:each) do + @external_provider = stub(:external_provider) + @items = stub(:items) + @items_provider = stub(:items_provider, :items => @items) + SimpleNavigation::ItemsProvider.stub!(:new => @items_provider) + @container.stub!(:items=) + end + it "should create an new Provider object for the specified provider" do + SimpleNavigation::ItemsProvider.should_receive(:new).with(@external_provider) + @config.items(@external_provider) + end + it "should call items on the provider object" do + @items_provider.should_receive(:items) + @config.items(@external_provider) + end + it "should set the items on the container" do + @container.should_receive(:items=).with(@items) + @config.items(@external_provider) + end + end + context 'items_provider not specified' do + it {lambda {@config.items}.should raise_error} + end end end describe 'loaded?' do it "should return true if primary_nav is set" do @@ -152,9 +192,16 @@ @config.should be_loaded end it "should return false if no primary_nav is set" do @config.instance_variable_set(:@primary_navigation, nil) @config.should_not be_loaded + end + end + + describe 'context_for_eval' do + it "should delegate to the Configuration class" do + @config.class.should_receive(:context_for_eval) + @config.context_for_eval end end end