Sha256: 181514304308319e990d61b5389ddca125dbd19ddf27cc4f8794e3e7409775f5

Contents?: true

Size: 1.84 KB

Versions: 18

Compression:

Stored size: 1.84 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe SimpleNavigation::ItemsProvider do
  
  before(:each) do
    @provider = stub(:provider)
    @items_provider = SimpleNavigation::ItemsProvider.new(@provider)
  end
  
  describe 'initialize' do
    it "should set the provider" do
      @items_provider.provider.should == @provider
    end
  end
  
  describe 'items' do
    before(:each) do
      @items = stub(:items)
    end
    context 'provider is symbol' do
      before(:each) do
        @items_provider.instance_variable_set(:@provider, :provider_method)
        @context = stub(:context, :provider_method => @items)
        SimpleNavigation::Configuration.stub!(:context_for_eval => @context)
      end
      it "should call the method specified by symbol on the context" do
        @context.should_receive(:provider_method)
        @items_provider.items
      end
      it "should return the items returned by the helper method" do
        @items_provider.items.should == @items
      end
    end
    context 'provider responds to items' do
      before(:each) do
        @provider.stub!(:items => @items)
      end
      it "should get the items from the items_provider" do
        @provider.should_receive(:items)
        @items_provider.items
      end
      it "should return the items of the provider" do
        @items_provider.items.should == @items
      end
    end
    context 'provider is a collection' do
      before(:each) do
        @items_collection = []
        @items_provider.instance_variable_set(:@provider, @items_collection)      
      end
      it "should return the collection itsself" do
        @items_provider.items.should == @items_collection
      end
    end
    context 'neither symbol nor items_provider.items nor collection' do
      it {lambda {@items_provider.items}.should raise_error}
    end
  end
  
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
simple-navigation-2.7.3 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.7.2 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.7.1 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.7.0 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.6.0 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.5.4 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.5.3 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.5.2 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.5.1 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.5.0 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.4.2 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.4.1 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.4.0 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.2.3 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.2.2 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.2.1 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.2.0 spec/lib/simple_navigation/items_provider_spec.rb
simple-navigation-2.1.0 spec/lib/simple_navigation/items_provider_spec.rb