File: items_provider_spec.rb

package info (click to toggle)
ruby-simple-navigation 4.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 488 kB
  • ctags: 255
  • sloc: ruby: 3,693; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module SimpleNavigation
  describe ItemsProvider do
    let(:items_provider) { ItemsProvider.new(provider) }

    describe '#items' do
      let(:items) { double(:items) }

      context 'when provider is a symbol' do
        let(:context) { double(:context, provider_method: items) }
        let(:provider) { :provider_method }

        before { allow(SimpleNavigation).to receive_messages(context_for_eval: context) }

        it 'retrieves the items from the evaluation context' do
          expect(items_provider.items).to eq items
        end
      end

      context 'when provider responds to :items' do
        let(:provider) { double(:provider, items: items) }

        it 'retrieves the items from the provider object' do
          expect(items_provider.items).to eq items
        end
      end

      context 'provider is a collection' do
        let(:provider) { [] }

        it 'retrieves the items by returning the provider' do
          expect(items_provider.items).to eq provider
        end
      end

      context 'when provider is something else' do
        let(:provider) { double(:provider) }

        it 'raises an exception' do
          expect{ items_provider.items }.to raise_error
        end
      end
    end
  end
end