simple-navigation 4.4.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +84 -0
  3. data/.rspec +1 -2
  4. data/.rubocop.yml +49 -0
  5. data/.rubocop_todo.yml +38 -0
  6. data/Appraisals +55 -0
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +21 -0
  9. data/Guardfile +4 -2
  10. data/README.md +11 -23
  11. data/Rakefile +2 -27
  12. data/bin/_guard-core +16 -0
  13. data/bin/appraisal +16 -0
  14. data/bin/guard +16 -0
  15. data/bin/rake +16 -0
  16. data/bin/rspec +16 -0
  17. data/bin/rubocop +16 -0
  18. data/gemfiles/rails_6.1.gemfile +35 -0
  19. data/gemfiles/rails_7.0.gemfile +23 -0
  20. data/gemfiles/rails_7.1.gemfile +23 -0
  21. data/gemfiles/rails_7.2.gemfile +23 -0
  22. data/gemfiles/rails_8.0.gemfile +23 -0
  23. data/gemfiles/rails_8.1.gemfile +23 -0
  24. data/generators/navigation_config/navigation_config_generator.rb +2 -0
  25. data/generators/navigation_config/templates/config/navigation.rb +30 -26
  26. data/lib/generators/navigation_config/navigation_config_generator.rb +2 -0
  27. data/lib/simple-navigation.rb +3 -1
  28. data/lib/simple_navigation/adapters/base.rb +2 -0
  29. data/lib/simple_navigation/adapters/nanoc.rb +8 -3
  30. data/lib/simple_navigation/adapters/padrino.rb +3 -1
  31. data/lib/simple_navigation/adapters/rails.rb +12 -14
  32. data/lib/simple_navigation/adapters/sinatra.rb +4 -6
  33. data/lib/simple_navigation/config_file.rb +1 -1
  34. data/lib/simple_navigation/config_file_finder.rb +3 -3
  35. data/lib/simple_navigation/configuration.rb +5 -5
  36. data/lib/simple_navigation/helpers.rb +9 -11
  37. data/lib/simple_navigation/item.rb +26 -20
  38. data/lib/simple_navigation/item_adapter.rb +16 -5
  39. data/lib/simple_navigation/item_container.rb +13 -7
  40. data/lib/simple_navigation/items_provider.rb +6 -4
  41. data/lib/simple_navigation/railtie.rb +3 -1
  42. data/lib/simple_navigation/renderer/base.rb +5 -5
  43. data/lib/simple_navigation/renderer/breadcrumbs.rb +4 -3
  44. data/lib/simple_navigation/renderer/json.rb +1 -1
  45. data/lib/simple_navigation/renderer/links.rb +2 -0
  46. data/lib/simple_navigation/renderer/list.rb +5 -5
  47. data/lib/simple_navigation/renderer/text.rb +3 -1
  48. data/lib/simple_navigation/version.rb +3 -1
  49. data/lib/simple_navigation.rb +32 -24
  50. data/simple-navigation.gemspec +16 -27
  51. data/spec/fake_app/config/navigation.rb +4 -2
  52. data/spec/fake_app/rails_app.rb +5 -3
  53. data/spec/integration/rendering_navigation_spec.rb +7 -5
  54. data/spec/simple_navigation/adapters/nanoc_spec.rb +97 -0
  55. data/spec/simple_navigation/adapters/padrino_spec.rb +41 -22
  56. data/spec/simple_navigation/adapters/rails_spec.rb +199 -206
  57. data/spec/simple_navigation/adapters/sinatra_spec.rb +21 -5
  58. data/spec/simple_navigation/config_file_finder_spec.rb +32 -28
  59. data/spec/simple_navigation/config_file_spec.rb +14 -14
  60. data/spec/simple_navigation/configuration_spec.rb +128 -121
  61. data/spec/simple_navigation/helpers_spec.rb +282 -284
  62. data/spec/simple_navigation/item_adapter_spec.rb +109 -122
  63. data/spec/simple_navigation/item_container_spec.rb +407 -408
  64. data/spec/simple_navigation/item_spec.rb +333 -301
  65. data/spec/simple_navigation/items_provider_spec.rb +30 -27
  66. data/spec/simple_navigation/renderer/base_spec.rb +166 -168
  67. data/spec/simple_navigation/renderer/breadcrumbs_spec.rb +81 -83
  68. data/spec/simple_navigation/renderer/json_spec.rb +49 -56
  69. data/spec/simple_navigation/renderer/links_spec.rb +81 -83
  70. data/spec/simple_navigation/renderer/list_spec.rb +111 -91
  71. data/spec/simple_navigation/renderer/text_spec.rb +37 -39
  72. data/spec/simple_navigation_spec.rb +54 -47
  73. data/spec/spec_helper.rb +146 -53
  74. metadata +25 -164
  75. data/.travis.yml +0 -23
  76. data/gemfiles/rails-3-2-stable.gemfile +0 -11
  77. data/gemfiles/rails-4-1-stable.gemfile +0 -7
  78. data/gemfiles/rails-4-2-stable.gemfile +0 -7
  79. data/gemfiles/rails-5-2-stable.gemfile +0 -7
  80. data/gemfiles/rails-6-0-stable.gemfile +0 -9
  81. data/gemfiles/rails-6-1-stable.gemfile +0 -9
  82. data/init.rb +0 -1
  83. data/install.rb +0 -5
  84. data/lib/simple_navigation/adapters.rb +0 -10
  85. data/lib/simple_navigation/renderer.rb +0 -12
  86. data/spec/initializers/coveralls.rb +0 -3
  87. data/spec/initializers/have_css_matcher.rb +0 -19
  88. data/spec/initializers/memfs.rb +0 -7
  89. data/spec/initializers/rails.rb +0 -4
  90. data/spec/initializers/rspec.rb +0 -7
  91. data/uninstall.rb +0 -1
@@ -1,94 +1,114 @@
1
- module SimpleNavigation
2
- module Renderer
3
- describe List do
4
- let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
5
-
6
- let(:item) { nil }
7
- let(:options) { { level: :all } }
8
- let(:output) { renderer.render(navigation) }
9
- let(:renderer) { List.new(options) }
10
-
11
- before { select_an_item(navigation[item]) if item }
12
-
13
- describe '#render' do
14
- it "renders an 'ul' tag for the navigation" do
15
- expect(output).to have_css('ul')
16
- end
17
-
18
- it "sets the right html id on the rendered 'ul' tag" do
19
- expect(output).to have_css('ul#nav_id')
20
- end
21
-
22
- it "sets the right html classes on the rendered 'ul' tag" do
23
- expect(output).to have_css('ul.nav_class')
24
- end
25
-
26
- context 'when an item has no specified id' do
27
- it "renders the item's 'li' tag with the item's stingified key as id" do
28
- expect(output).to have_css('li#invoices')
29
- end
30
- end
31
-
32
- context 'when an item has a specified id' do
33
- it "renders the item's 'li' tag with the specified id" do
34
- expect(output).to have_css('li#users_id')
35
- end
36
- end
37
-
38
- context 'when no item is selected' do
39
- it "renders each item as 'li' tag without any selected class" do
40
- expect(output).not_to have_css('ul li.selected')
41
- end
42
-
43
- it "renders each item as 'a' tag without any selected class" do
44
- expect(output).not_to have_css('ul li a.selected')
45
- end
46
- end
47
-
48
- context 'when an item is selected' do
49
- let(:item) { :invoices }
50
-
51
- it "renders the item's 'li' tag with its id and selected classes" do
52
- expect(output).to have_css('li#invoices.selected')
53
- end
54
-
55
- it "renders the item's 'a' tag with the selected classes" do
56
- expect(output).to have_css('li#invoices a.selected')
57
- end
58
- end
59
-
60
- context 'when the :ordered option is true' do
61
- let(:options) {{ level: :all, ordered: true }}
62
-
63
- it "renders an 'ol' tag for the navigation" do
64
- expect(output).to have_css('ol')
65
- end
66
-
67
- it "sets the right html id on the rendered 'ol' tag" do
68
- expect(output).to have_css('ol#nav_id')
69
- end
70
-
71
- it "sets the right html classes on the rendered 'ol' tag" do
72
- expect(output).to have_css('ol.nav_class')
73
- end
74
- end
75
-
76
- context 'when a sub navigation item is selected' do
77
- before do
78
- allow(navigation[:invoices]).to receive_messages(selected?: true)
79
-
80
- allow(navigation[:invoices].sub_navigation[:unpaid]).to \
81
- receive_messages(selected?: true, selected_by_condition?: true)
82
- end
83
-
84
- it 'renders the parent items as selected' do
85
- expect(output).to have_css('li#invoices.selected')
86
- end
87
-
88
- it "renders the selected nested item's link as selected" do
89
- expect(output).to have_css('li#unpaid.selected')
90
- end
91
- end
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SimpleNavigation::Renderer::List do
4
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
5
+
6
+ let(:options) { { level: :all } }
7
+ let(:output) { renderer.render(navigation) }
8
+ let(:renderer) { described_class.new(options) }
9
+
10
+ describe '#render' do
11
+ it "renders an 'ul' tag for the navigation" do
12
+ expect(output).to have_css('ul')
13
+ end
14
+
15
+ it "sets the right html id on the rendered 'ul' tag" do
16
+ expect(output).to have_css('ul#nav_id')
17
+ end
18
+
19
+ it "sets the right html classes on the rendered 'ul' tag" do
20
+ expect(output).to have_css('ul.nav_class')
21
+ end
22
+
23
+ context 'when an item has no specified id' do
24
+ it "renders the item's 'li' tag with the item's stingified key as id" do
25
+ expect(output).to have_css('li#invoices')
26
+ end
27
+ end
28
+
29
+ context 'when an item has a specified id' do
30
+ it "renders the item's 'li' tag with the specified id" do
31
+ expect(output).to have_css('li#users_id')
32
+ end
33
+ end
34
+
35
+ context 'when no item is selected' do
36
+ it "renders each item as 'li' tag without any selected class" do
37
+ expect(output).to have_no_css('ul li.selected')
38
+ end
39
+
40
+ it "renders each item as 'a' tag without any selected class" do
41
+ expect(output).to have_no_css('ul li a.selected')
42
+ end
43
+ end
44
+
45
+ context 'when an item is selected' do
46
+ before do
47
+ allow(navigation[:invoices]).to \
48
+ receive_messages(selected?: true, selected_by_condition?: true)
49
+ end
50
+
51
+ it "renders the item's 'li' tag with its id and selected classes" do
52
+ expect(output).to have_css('li#invoices.selected')
53
+ end
54
+
55
+ it "renders the item's 'a' tag with the selected classes" do
56
+ expect(output).to have_css('li#invoices a.selected')
57
+ end
58
+
59
+ it "renders the item's 'a' tag with with an 'aria-current' attribute" do
60
+ expect(output).to have_css('li#invoices a[aria-current=page]')
61
+ end
62
+ end
63
+
64
+ context 'when the :ordered option is true' do
65
+ let(:options) { { level: :all, ordered: true } }
66
+
67
+ it "renders an 'ol' tag for the navigation" do
68
+ expect(output).to have_css('ol')
69
+ end
70
+
71
+ it "sets the right html id on the rendered 'ol' tag" do
72
+ expect(output).to have_css('ol#nav_id')
73
+ end
74
+
75
+ it "sets the right html classes on the rendered 'ol' tag" do
76
+ expect(output).to have_css('ol.nav_class')
77
+ end
78
+ end
79
+
80
+ context 'when a sub navigation item is selected' do
81
+ before do
82
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
83
+
84
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
85
+ receive_messages(selected?: true, selected_by_condition?: true)
86
+ end
87
+
88
+ it 'renders the parent items as selected' do
89
+ expect(output).to have_css('li#invoices.selected')
90
+ end
91
+
92
+ it "renders the selected nested item's link as selected" do
93
+ expect(output).to have_css('li#unpaid.selected')
94
+ end
95
+
96
+ it "renders the selected nested item's 'a' tag with with an 'aria-current' attribute" do
97
+ expect(output).to have_css('li#unpaid a[aria-current=page]')
98
+ end
99
+
100
+ it "does not 'aria-current' to the parent item's link" do
101
+ expect(output).to have_no_css('li#invoices > a[aria-current=page]')
102
+ end
103
+ end
104
+
105
+ context 'when skip_if_empty is true and container is empty' do
106
+ let(:empty_navigation) { SimpleNavigation::ItemContainer.new(1) }
107
+ let(:options) { { skip_if_empty: true } }
108
+ let(:output) { renderer.render(empty_navigation) }
109
+
110
+ it 'returns an empty string' do
111
+ expect(output).to eq ''
92
112
  end
93
113
  end
94
114
  end
@@ -1,49 +1,47 @@
1
- module SimpleNavigation
2
- module Renderer
3
- describe Text do
4
- let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
5
-
6
- let(:item) { nil }
7
- let(:options) {{ level: :all }}
8
- let(:output) { renderer.render(navigation) }
9
- let(:renderer) { Text.new(options) }
10
-
11
- before { select_an_item(navigation[item]) if item }
12
-
13
- describe '#render' do
14
- context 'when no item is selected' do
15
- it 'renders an empty string' do
16
- expect(output).to eq ''
17
- end
18
- end
1
+ # frozen_string_literal: true
19
2
 
20
- context 'when an item is selected' do
21
- let(:item) { :invoices }
3
+ RSpec.describe SimpleNavigation::Renderer::Text do
4
+ let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
22
5
 
23
- it "renders the selected item's name" do
24
- expect(output).to eq 'Invoices'
25
- end
26
- end
6
+ let(:item) { nil }
7
+ let(:options) { { level: :all } }
8
+ let(:output) { renderer.render(navigation) }
9
+ let(:renderer) { described_class.new(options) }
10
+
11
+ before { select_an_item(navigation[item]) if item }
12
+
13
+ describe '#render' do
14
+ context 'when no item is selected' do
15
+ it 'renders an empty string' do
16
+ expect(output).to eq ''
17
+ end
18
+ end
27
19
 
28
- context 'when a sub navigation item is selected' do
29
- before do
30
- allow(navigation[:invoices]).to receive_messages(selected?: true)
20
+ context 'when an item is selected' do
21
+ let(:item) { :invoices }
31
22
 
32
- allow(navigation[:invoices].sub_navigation[:unpaid]).to \
33
- receive_messages(selected?: true, selected_by_condition?: true)
34
- end
23
+ it "renders the selected item's name" do
24
+ expect(output).to eq 'Invoices'
25
+ end
26
+ end
27
+
28
+ context 'when a sub navigation item is selected' do
29
+ before do
30
+ allow(navigation[:invoices]).to receive_messages(selected?: true)
35
31
 
36
- it 'separates the items with a space' do
37
- expect(output).to eq 'Invoices Unpaid'
38
- end
32
+ allow(navigation[:invoices].sub_navigation[:unpaid]).to \
33
+ receive_messages(selected?: true, selected_by_condition?: true)
34
+ end
35
+
36
+ it 'separates the items with a space' do
37
+ expect(output).to eq 'Invoices Unpaid'
38
+ end
39
39
 
40
- context "and the :join_with option is set" do
41
- let(:options) {{ level: :all, join_with: ' | ' }}
40
+ context 'when the :join_with option is set' do
41
+ let(:options) { { level: :all, join_with: ' | ' } }
42
42
 
43
- it 'separates the items with the specified separator' do
44
- expect(output).to eq 'Invoices | Unpaid'
45
- end
46
- end
43
+ it 'separates the items with the specified separator' do
44
+ expect(output).to eq 'Invoices | Unpaid'
47
45
  end
48
46
  end
49
47
  end
@@ -1,64 +1,68 @@
1
- describe SimpleNavigation do
2
- before { subject.config_file_path = 'path_to_config' }
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SimpleNavigation do
4
+ subject(:simple_navigation) { described_class }
5
+
6
+ before { simple_navigation.config_file_path = 'path_to_config' }
3
7
 
4
8
  describe 'config_file_path=' do
5
- before { subject.config_file_paths = ['existing_path'] }
9
+ before { simple_navigation.config_file_paths = ['existing_path'] }
6
10
 
7
11
  it 'overrides the config_file_paths' do
8
- subject.config_file_path = 'new_path'
9
- expect(subject.config_file_paths).to eq ['new_path']
12
+ simple_navigation.config_file_path = 'new_path'
13
+ expect(simple_navigation.config_file_paths).to eq ['new_path']
10
14
  end
11
15
  end
12
16
 
13
17
  describe '.default_config_file_path' do
14
- before { allow(subject).to receive_messages(root: 'root') }
18
+ before { allow(simple_navigation).to receive_messages(root: 'root') }
15
19
 
16
20
  it 'returns the config file path according to :root setting' do
17
- expect(subject.default_config_file_path).to eq 'root/config'
21
+ expect(simple_navigation.default_config_file_path).to eq 'root/config'
18
22
  end
19
23
  end
20
24
 
21
25
  describe 'Regarding renderers' do
22
26
  it 'registers the builtin renderers by default' do
23
- expect(subject.registered_renderers).not_to be_empty
27
+ expect(simple_navigation.registered_renderers).not_to be_empty
24
28
  end
25
29
 
26
30
  describe '.register_renderer' do
27
31
  let(:renderer) { double(:renderer) }
28
32
 
29
33
  it 'adds the specified renderer to the list of renderers' do
30
- subject.register_renderer(my_renderer: renderer)
31
- expect(subject.registered_renderers[:my_renderer]).to be renderer
34
+ simple_navigation.register_renderer(my_renderer: renderer)
35
+ expect(simple_navigation.registered_renderers[:my_renderer]).to be renderer
32
36
  end
33
37
  end
34
38
  end
35
39
 
36
40
  describe '.set_env' do
37
41
  before do
38
- subject.config_file_paths = []
39
- allow(subject).to receive_messages(default_config_file_path: 'default_path')
40
- subject.set_env('root', 'my_env')
42
+ simple_navigation.config_file_paths = []
43
+ allow(simple_navigation).to receive_messages(default_config_file_path: 'default_path')
44
+ simple_navigation.set_env('root', 'my_env')
41
45
  end
42
46
 
43
47
  it 'sets the root' do
44
- expect(subject.root).to eq 'root'
48
+ expect(simple_navigation.root).to eq 'root'
45
49
  end
46
50
 
47
51
  it 'sets the environment' do
48
- expect(subject.environment).to eq 'my_env'
52
+ expect(simple_navigation.environment).to eq 'my_env'
49
53
  end
50
54
 
51
55
  it 'adds the default-config path to the list of config_file_paths' do
52
- expect(subject.config_file_paths).to eq ['default_path']
56
+ expect(simple_navigation.config_file_paths).to eq ['default_path']
53
57
  end
54
58
  end
55
59
 
56
- describe '.load_config', memfs: true do
60
+ describe '.load_config', :memfs do
57
61
  let(:paths) { ['/path/one', '/path/two'] }
58
62
 
59
63
  before do
60
64
  FileUtils.mkdir_p(paths)
61
- allow(subject).to receive_messages(config_file_paths: paths)
65
+ allow(simple_navigation).to receive_messages(config_file_paths: paths)
62
66
  end
63
67
 
64
68
  context 'when the config file for the context exists' do
@@ -69,60 +73,62 @@ describe SimpleNavigation do
69
73
 
70
74
  context 'when no context is provided' do
71
75
  it 'stores the configuration in config_files for the default context' do
72
- subject.load_config
73
- expect(subject.config_files[:default]).to eq "default content\n"
76
+ simple_navigation.load_config
77
+ expect(simple_navigation.config_files[:default]).to eq "default content\n"
74
78
  end
75
79
  end
76
80
 
77
81
  context 'when a context is provided' do
78
82
  it 'stores the configuration in config_files for the given context' do
79
- subject.load_config(:other)
80
- expect(subject.config_files[:other]).to eq "other content\n"
83
+ simple_navigation.load_config(:other)
84
+ expect(simple_navigation.config_files[:other]).to eq "other content\n"
81
85
  end
82
86
  end
83
87
 
84
- context 'and environment is production' do
85
- before { allow(subject).to receive_messages(environment: 'production') }
88
+ context 'when environment is production' do
89
+ before { allow(simple_navigation).to receive_messages(environment: 'production') }
86
90
 
87
91
  it 'loads the config file only for the first call' do
88
- subject.load_config
92
+ simple_navigation.load_config
89
93
  File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
90
- subject.load_config
91
- expect(subject.config_files[:default]).to eq "default content\n"
94
+ simple_navigation.load_config
95
+ expect(simple_navigation.config_files[:default]).to eq "default content\n"
92
96
  end
93
97
  end
94
98
 
95
- context "and environment isn't production" do
99
+ context "when environment isn't production" do
96
100
  it 'loads the config file for every call' do
97
- subject.load_config
101
+ simple_navigation.load_config
98
102
  File.open('/path/two/navigation.rb', 'w') { |f| f.puts 'new content' }
99
- subject.load_config
100
- expect(subject.config_files[:default]).to eq "new content\n"
103
+ simple_navigation.load_config
104
+ expect(simple_navigation.config_files[:default]).to eq "new content\n"
101
105
  end
102
106
  end
103
107
  end
104
108
 
105
109
  context "when the config file for the context doesn't exists" do
106
110
  it 'raises an exception' do
107
- expect{ subject.load_config }.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
111
+ expect do
112
+ simple_navigation.load_config
113
+ end.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
108
114
  end
109
115
  end
110
116
  end
111
117
 
112
118
  describe '.config' do
113
119
  it 'returns the Configuration singleton instance' do
114
- expect(subject.config).to be SimpleNavigation::Configuration.instance
120
+ expect(simple_navigation.config).to be SimpleNavigation::Configuration.instance
115
121
  end
116
122
  end
117
123
 
118
124
  describe '.active_item_container_for' do
119
125
  let(:primary) { double(:primary) }
120
126
 
121
- before { allow(subject.config).to receive_messages(primary_navigation: primary) }
127
+ before { allow(simple_navigation.config).to receive_messages(primary_navigation: primary) }
122
128
 
123
129
  context 'when level is :all' do
124
130
  it 'returns the primary_navigation' do
125
- nav = subject.active_item_container_for(:all)
131
+ nav = simple_navigation.active_item_container_for(:all)
126
132
  expect(nav).to be primary
127
133
  end
128
134
  end
@@ -130,29 +136,29 @@ describe SimpleNavigation do
130
136
  context 'when level is :leaves' do
131
137
  it 'returns the currently active leaf-container' do
132
138
  expect(primary).to receive(:active_leaf_container)
133
- subject.active_item_container_for(:leaves)
139
+ simple_navigation.active_item_container_for(:leaves)
134
140
  end
135
141
  end
136
142
 
137
143
  context 'when level is a Range' do
138
144
  it 'takes the min of the range to lookup the active container' do
139
145
  expect(primary).to receive(:active_item_container_for).with(2)
140
- subject.active_item_container_for(2..3)
146
+ simple_navigation.active_item_container_for(2..3)
141
147
  end
142
148
  end
143
149
 
144
150
  context 'when level is an Integer' do
145
151
  it 'considers the Integer to lookup the active container' do
146
152
  expect(primary).to receive(:active_item_container_for).with(1)
147
- subject.active_item_container_for(1)
153
+ simple_navigation.active_item_container_for(1)
148
154
  end
149
155
  end
150
156
 
151
157
  context 'when level is something else' do
152
158
  it 'raises an exception' do
153
- expect{
154
- subject.active_item_container_for('something else')
155
- }.to raise_error(ArgumentError, 'Invalid navigation level: something else')
159
+ expect do
160
+ simple_navigation.active_item_container_for('something else')
161
+ end.to raise_error(ArgumentError, 'Invalid navigation level: something else')
156
162
  end
157
163
  end
158
164
  end
@@ -161,13 +167,13 @@ describe SimpleNavigation do
161
167
  shared_examples 'loading the right adapter' do |framework, adapter|
162
168
  context "when the context is #{framework}" do
163
169
  before do
164
- allow(subject).to receive_messages(framework: framework)
165
- subject.load_adapter
170
+ allow(simple_navigation).to receive_messages(framework: framework)
171
+ simple_navigation.load_adapter
166
172
  end
167
173
 
168
174
  it "returns the #{framework} adapter" do
169
175
  adapter_class = SimpleNavigation::Adapters.const_get(adapter)
170
- expect(subject.adapter_class).to be adapter_class
176
+ expect(simple_navigation.adapter_class).to be adapter_class
171
177
  end
172
178
  end
173
179
  end
@@ -175,6 +181,7 @@ describe SimpleNavigation do
175
181
  it_behaves_like 'loading the right adapter', :rails, :Rails
176
182
  it_behaves_like 'loading the right adapter', :padrino, :Padrino
177
183
  it_behaves_like 'loading the right adapter', :sinatra, :Sinatra
184
+ it_behaves_like 'loading the right adapter', :nanoc, :Nanoc
178
185
  end
179
186
 
180
187
  describe '.init_adapter_from' do
@@ -182,9 +189,9 @@ describe SimpleNavigation do
182
189
  let(:adapter_class) { double(:adapter_class, new: adapter) }
183
190
 
184
191
  it 'sets the adapter to a new instance of adapter_class' do
185
- subject.adapter_class = adapter_class
186
- subject.init_adapter_from(:default)
187
- expect(subject.adapter).to be adapter
192
+ simple_navigation.adapter_class = adapter_class
193
+ simple_navigation.init_adapter_from(:default)
194
+ expect(simple_navigation.adapter).to be adapter
188
195
  end
189
196
  end
190
197
  end