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,281 +1,274 @@
1
- module SimpleNavigation
2
- module Adapters
3
- describe Rails do
4
- let(:action_controller) { ActionController::Base }
5
- let(:adapter) { Rails.new(context) }
6
- let(:context) { double(:context, controller: controller) }
7
- let(:controller) { double(:controller) }
8
- let(:request) { double(:request) }
9
- let(:simple_navigation) { SimpleNavigation }
10
- let(:template) { double(:template, request: request) }
11
-
12
- describe '.register' do
13
- before { allow(action_controller).to receive(:include) }
14
-
15
- it 'calls set_env' do
16
- app_path = RailsApp::Application.root
17
- expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
18
- simple_navigation.register
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SimpleNavigation::Adapters::Rails do
4
+ let(:action_controller) { ActionController::Base }
5
+ let(:adapter) { described_class.new(context) }
6
+ let(:context) { double(:context, controller: controller) }
7
+ let(:controller) { double(:controller) }
8
+ let(:request) { double(:request) }
9
+ let(:simple_navigation) { SimpleNavigation }
10
+ let(:template) { double(:template, request: request) }
11
+
12
+ describe '.register' do
13
+ before { allow(action_controller).to receive(:include) }
14
+
15
+ it 'calls set_env' do
16
+ app_path = RailsApp::Application.root
17
+ expect(simple_navigation).to receive(:set_env).with(app_path, 'test')
18
+ simple_navigation.register
19
+ end
20
20
 
21
- it 'extends the ActionController::Base with the Helpers' do
22
- expect(action_controller).to receive(:include)
23
- .with(SimpleNavigation::Helpers)
24
- simple_navigation.register
25
- end
21
+ it 'extends the ActionController::Base with the Helpers' do
22
+ expect(action_controller).to receive(:include).with(SimpleNavigation::Helpers)
23
+ simple_navigation.register
24
+ end
26
25
 
27
- shared_examples 'installing helper method' do |method|
28
- it "installs the #{method} method as helper method" do
29
- simple_navigation.register
26
+ shared_examples 'installing helper method' do |method|
27
+ it "installs the #{method} method as helper method" do
28
+ simple_navigation.register
30
29
 
31
- helper_methods = action_controller.send(:_helper_methods)
32
- expect(helper_methods).to include(method)
33
- end
34
- end
35
-
36
- it_behaves_like 'installing helper method', :render_navigation
37
- it_behaves_like 'installing helper method', :active_navigation_item_name
38
- it_behaves_like 'installing helper method', :active_navigation_item_key
39
- it_behaves_like 'installing helper method', :active_navigation_item
40
- it_behaves_like 'installing helper method', :active_navigation_item_container
30
+ helper_methods = action_controller.send(:_helper_methods)
31
+ expect(helper_methods).to include(method)
41
32
  end
33
+ end
42
34
 
43
- describe '#initialize' do
44
- context "when the controller's template is set" do
45
- before { allow(controller).to receive_messages(instance_variable_get: template) }
46
-
47
- it "sets the adapter's request accordingly" do
48
- expect(adapter.request).to be request
49
- end
50
- end
35
+ it_behaves_like 'installing helper method', :render_navigation
36
+ it_behaves_like 'installing helper method', :active_navigation_item_name
37
+ it_behaves_like 'installing helper method', :active_navigation_item_key
38
+ it_behaves_like 'installing helper method', :active_navigation_item
39
+ it_behaves_like 'installing helper method', :active_navigation_item_container
40
+ end
51
41
 
52
- context "when the controller's template is not set" do
53
- before { allow(controller).to receive_messages(instance_variable_get: nil) }
42
+ describe '#initialize' do
43
+ context "when the controller's template is set" do
44
+ before { allow(controller).to receive_messages(instance_variable_get: template) }
54
45
 
55
- it "sets the adapter's request to nil" do
56
- expect(adapter.request).to be_nil
57
- end
58
- end
46
+ it "sets the adapter's request accordingly" do
47
+ expect(adapter.request).to be request
48
+ end
49
+ end
59
50
 
60
- it "sets the adapter's controller to the context's controller" do
61
- expect(adapter.controller).to be controller
62
- end
51
+ context "when the controller's template is not set" do
52
+ before { allow(controller).to receive_messages(instance_variable_get: nil) }
63
53
 
64
- context "when the controller's template is stored as instance var (Rails2)" do
65
- context "when the controller's template is set" do
66
- before { allow(controller).to receive_messages(instance_variable_get: template) }
54
+ it "sets the adapter's request to nil" do
55
+ expect(adapter.request).to be_nil
56
+ end
57
+ end
67
58
 
68
- it "sets the adapter's template accordingly" do
69
- expect(adapter.template).to be template
70
- end
71
- end
59
+ it "sets the adapter's controller to the context's controller" do
60
+ expect(adapter.controller).to be controller
61
+ end
72
62
 
73
- context "when the controller's template is not set" do
74
- before { allow(controller).to receive_messages(instance_variable_get: nil) }
63
+ context "when the controller's template is stored as instance var (Rails2)" do
64
+ context "when the controller's template is set" do
65
+ before { allow(controller).to receive_messages(instance_variable_get: template) }
75
66
 
76
- it "set the adapter's template to nil" do
77
- expect(adapter.template).to be_nil
78
- end
79
- end
67
+ it "sets the adapter's template accordingly" do
68
+ expect(adapter.template).to be template
80
69
  end
70
+ end
81
71
 
82
- context "when the controller's template is stored as view_context (Rails3)" do
83
- context 'and the template is set' do
84
- before { allow(controller).to receive_messages(view_context: template) }
72
+ context "when the controller's template is not set" do
73
+ before { allow(controller).to receive_messages(instance_variable_get: nil) }
85
74
 
86
- it "sets the adapter's template accordingly" do
87
- expect(adapter.template).to be template
88
- end
89
- end
75
+ it "set the adapter's template to nil" do
76
+ expect(adapter.template).to be_nil
77
+ end
78
+ end
79
+ end
90
80
 
91
- context 'and the template is not set' do
92
- before { allow(controller).to receive_messages(view_context: nil) }
81
+ context "when the controller's template is stored as view_context (Rails3)" do
82
+ context 'when the template is set' do
83
+ before { allow(controller).to receive_messages(view_context: template) }
93
84
 
94
- it "sets the adapter's template to nil" do
95
- expect(adapter.template).to be_nil
96
- end
97
- end
85
+ it "sets the adapter's template accordingly" do
86
+ expect(adapter.template).to be template
98
87
  end
99
88
  end
100
89
 
101
- describe '#request_uri' do
102
- context "when the adapter's request is set" do
103
- before { allow(adapter).to receive_messages(request: request) }
90
+ context 'when the template is not set' do
91
+ before { allow(controller).to receive_messages(view_context: nil) }
104
92
 
105
- context 'and request.fullpath is defined' do
106
- let(:request) { double(:request, fullpath: '/fullpath') }
107
-
108
- it "sets the adapter's request_uri to the request.fullpath" do
109
- expect(adapter.request_uri).to eq '/fullpath'
110
- end
111
- end
93
+ it "sets the adapter's template to nil" do
94
+ expect(adapter.template).to be_nil
95
+ end
96
+ end
97
+ end
98
+ end
112
99
 
113
- context 'and request.fullpath is not defined' do
114
- let(:request) { double(:request, request_uri: '/request_uri') }
100
+ describe '#request_uri' do
101
+ context "when the adapter's request is set" do
102
+ before { allow(adapter).to receive_messages(request: request) }
115
103
 
116
- before { allow(adapter).to receive_messages(request: request) }
104
+ context 'when request.fullpath is defined' do
105
+ let(:request) { double(:request, fullpath: '/fullpath') }
117
106
 
118
- it "sets the adapter's request_uri to the request.request_uri" do
119
- expect(adapter.request_uri).to eq '/request_uri'
120
- end
121
- end
107
+ it "sets the adapter's request_uri to the request.fullpath" do
108
+ expect(adapter.request_uri).to eq '/fullpath'
122
109
  end
110
+ end
123
111
 
124
- context "when the adapter's request is not set" do
125
- before { allow(adapter).to receive_messages(request: nil) }
112
+ context 'when request.fullpath is not defined' do
113
+ let(:request) { double(:request, request_uri: '/request_uri') }
126
114
 
127
- it "sets the adapter's request_uri to an empty string" do
128
- expect(adapter.request_uri).to eq ''
129
- end
115
+ before { allow(adapter).to receive_messages(request: request) }
116
+
117
+ it "sets the adapter's request_uri to the request.request_uri" do
118
+ expect(adapter.request_uri).to eq '/request_uri'
130
119
  end
131
120
  end
121
+ end
132
122
 
133
- describe '#request_path' do
134
- context "when the adapter's request is set" do
135
- let(:request) { double(:request, path: '/request_path') }
123
+ context "when the adapter's request is not set" do
124
+ before { allow(adapter).to receive_messages(request: nil) }
136
125
 
137
- before { allow(adapter).to receive_messages(request: request) }
126
+ it "sets the adapter's request_uri to an empty string" do
127
+ expect(adapter.request_uri).to eq ''
128
+ end
129
+ end
130
+ end
138
131
 
139
- it "sets the adapter's request_path to the request.path" do
140
- expect(adapter.request_path).to eq '/request_path'
141
- end
142
- end
132
+ describe '#request_path' do
133
+ context "when the adapter's request is set" do
134
+ let(:request) { double(:request, path: '/request_path') }
143
135
 
144
- context "when the adapter's request is not set" do
145
- before { allow(adapter).to receive_messages(request: nil) }
136
+ before { allow(adapter).to receive_messages(request: request) }
146
137
 
147
- it "sets the adapter's request_path to an empty string" do
148
- expect(adapter.request_path).to eq ''
149
- end
150
- end
138
+ it "sets the adapter's request_path to the request.path" do
139
+ expect(adapter.request_path).to eq '/request_path'
151
140
  end
141
+ end
152
142
 
153
- describe '#context_for_eval' do
154
- context "when the adapter's controller is set" do
155
- before { adapter.instance_variable_set(:@controller, controller) }
143
+ context "when the adapter's request is not set" do
144
+ before { allow(adapter).to receive_messages(request: nil) }
156
145
 
157
- context "and the adapter's template is set" do
158
- before { adapter.instance_variable_set(:@template, template) }
146
+ it "sets the adapter's request_path to an empty string" do
147
+ expect(adapter.request_path).to eq ''
148
+ end
149
+ end
150
+ end
159
151
 
160
- it "sets the adapter's context_for_eval to the template" do
161
- expect(adapter.context_for_eval).to be template
162
- end
163
- end
152
+ describe '#context_for_eval' do
153
+ context "when the adapter's controller is set" do
154
+ before { adapter.instance_variable_set(:@controller, controller) }
164
155
 
165
- context "and the adapter's template is not set" do
166
- before { adapter.instance_variable_set(:@template, nil) }
156
+ context "when the adapter's template is set" do
157
+ before { adapter.instance_variable_set(:@template, template) }
167
158
 
168
- it "sets the adapter's context_for_eval to the controller" do
169
- expect(adapter.context_for_eval).to be controller
170
- end
171
- end
159
+ it "sets the adapter's context_for_eval to the template" do
160
+ expect(adapter.context_for_eval).to be template
172
161
  end
162
+ end
173
163
 
174
- context "when the adapter's controller is not set" do
175
- before { adapter.instance_variable_set(:@controller, nil) }
164
+ context "when the adapter's template is not set" do
165
+ before { adapter.instance_variable_set(:@template, nil) }
176
166
 
177
- context "and the adapter's template is set" do
178
- before { adapter.instance_variable_set(:@template, template) }
167
+ it "sets the adapter's context_for_eval to the controller" do
168
+ expect(adapter.context_for_eval).to be controller
169
+ end
170
+ end
171
+ end
179
172
 
180
- it "sets the adapter's context_for_eval to the template" do
181
- expect(adapter.context_for_eval).to be template
182
- end
183
- end
173
+ context "when the adapter's controller is not set" do
174
+ before { adapter.instance_variable_set(:@controller, nil) }
184
175
 
185
- context "and the adapter's template is not set" do
186
- before { adapter.instance_variable_set(:@template, nil) }
176
+ context "when the adapter's template is set" do
177
+ before { adapter.instance_variable_set(:@template, template) }
187
178
 
188
- it 'raises an exception' do
189
- expect{ adapter.context_for_eval }.to raise_error(RuntimeError, 'no context set for evaluation the config file')
190
- end
191
- end
179
+ it "sets the adapter's context_for_eval to the template" do
180
+ expect(adapter.context_for_eval).to be template
192
181
  end
193
182
  end
194
183
 
195
- describe '#current_page?' do
196
- context "when the adapter's template is set" do
197
- before { allow(adapter).to receive_messages(template: template) }
184
+ context "when the adapter's template is not set" do
185
+ before { adapter.instance_variable_set(:@template, nil) }
198
186
 
199
- it 'delegates the call to the template' do
200
- expect(template).to receive(:current_page?).with(:page)
201
- adapter.current_page?(:page)
202
- end
187
+ it 'raises an exception' do
188
+ expect do
189
+ adapter.context_for_eval
190
+ end.to raise_error(RuntimeError, 'no context set for evaluation the config file')
203
191
  end
192
+ end
193
+ end
194
+ end
204
195
 
205
- context "when the adapter's template is not set" do
206
- before { allow(adapter).to receive_messages(template: nil) }
207
-
208
- it 'returns false' do
209
- expect(adapter.current_page?(:page)).to be_falsey
210
- end
211
- end
196
+ describe '#current_page?' do
197
+ context "when the adapter's template is set" do
198
+ before { allow(adapter).to receive_messages(template: template) }
212
199
 
213
- context 'when the given url is nil' do
214
- it 'returns false' do
215
- expect(adapter.current_page?(nil)).to be_falsey
216
- end
217
- end
200
+ it 'delegates the call to the template' do
201
+ expect(template).to receive(:current_page?).with(:page)
202
+ adapter.current_page?(:page)
218
203
  end
204
+ end
219
205
 
220
- describe '#link_to' do
221
- let(:options) { double(:options) }
206
+ context "when the adapter's template is not set" do
207
+ before { allow(adapter).to receive_messages(template: nil) }
222
208
 
223
- context "when the adapter's template is set" do
224
- before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
209
+ it 'returns false' do
210
+ expect(adapter).not_to be_current_page(:page)
211
+ end
212
+ end
225
213
 
226
- context 'with considering item names as safe' do
227
- before { SimpleNavigation.config.consider_item_names_as_safe = true }
228
- after { SimpleNavigation.config.consider_item_names_as_safe = false }
214
+ context 'when the given url is nil' do
215
+ it 'returns false' do
216
+ expect(adapter).not_to be_current_page(nil)
217
+ end
218
+ end
219
+ end
229
220
 
230
- it 'delegates the call to the template (with html_safe text)' do
231
- expect(template).to receive(:link_to)
232
- .with('safe_text', 'url', options)
233
- adapter.link_to('text', 'url', options)
234
- end
235
- end
221
+ describe '#link_to' do
222
+ let(:options) { double(:options) }
236
223
 
237
- context 'with considering item names as UNsafe (default)' do
224
+ context "when the adapter's template is set" do
225
+ before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
238
226
 
239
- it 'delegates the call to the template (with html_safe text)' do
240
- expect(template).to receive(:link_to)
241
- .with('text', 'url', options)
242
- adapter.link_to('text', 'url', options)
243
- end
244
- end
227
+ context 'with considering item names as safe' do
228
+ before { SimpleNavigation.config.consider_item_names_as_safe = true }
229
+ after { SimpleNavigation.config.consider_item_names_as_safe = false }
245
230
 
231
+ it 'delegates the call to the template (with html_safe text)' do
232
+ expect(template).to receive(:link_to).with('safe_text', 'url', options)
233
+ adapter.link_to('text', 'url', options)
246
234
  end
235
+ end
247
236
 
248
- context "when the adapter's template is not set" do
249
- before { allow(adapter).to receive_messages(template: nil) }
250
-
251
- it 'returns nil' do
252
- expect(adapter.link_to('text', 'url', options)).to be_nil
253
- end
237
+ context 'with considering item names as UNsafe (default)' do
238
+ it 'delegates the call to the template (with html_safe text)' do
239
+ expect(template).to receive(:link_to).with('text', 'url', options)
240
+ adapter.link_to('text', 'url', options)
254
241
  end
255
242
  end
243
+ end
256
244
 
257
- describe '#content_tag' do
258
- let(:options) { double(:options) }
245
+ context "when the adapter's template is not set" do
246
+ before { allow(adapter).to receive_messages(template: nil) }
259
247
 
260
- context "when the adapter's template is set" do
261
- before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
248
+ it 'returns nil' do
249
+ expect(adapter.link_to('text', 'url', options)).to be_nil
250
+ end
251
+ end
252
+ end
262
253
 
263
- it 'delegates the call to the template (with html_safe text)' do
264
- expect(template).to receive(:content_tag)
265
- .with(:div, 'safe_text', options)
266
- adapter.content_tag(:div, 'text', options)
267
- end
268
- end
254
+ describe '#content_tag' do
255
+ let(:options) { double(:options) }
269
256
 
270
- context "when the adapter's template is not set" do
271
- before { allow(adapter).to receive_messages(template: nil) }
257
+ context "when the adapter's template is set" do
258
+ before { allow(adapter).to receive_messages(template: template, html_safe: 'safe_text') }
272
259
 
273
- it 'returns nil' do
274
- expect(adapter.content_tag(:div, 'text', options)).to be_nil
275
- end
276
- end
260
+ it 'delegates the call to the template (with html_safe text)' do
261
+ expect(template).to receive(:content_tag).with(:div, 'safe_text', options)
262
+ adapter.content_tag(:div, 'text', options)
277
263
  end
264
+ end
278
265
 
266
+ context "when the adapter's template is not set" do
267
+ before { allow(adapter).to receive_messages(template: nil) }
268
+
269
+ it 'returns nil' do
270
+ expect(adapter.content_tag(:div, 'text', options)).to be_nil
271
+ end
279
272
  end
280
273
  end
281
274
  end
@@ -1,15 +1,32 @@
1
- describe SimpleNavigation::Adapters::Sinatra do
2
- let(:adapter) { SimpleNavigation::Adapters::Sinatra.new(context) }
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe SimpleNavigation::Adapters::Sinatra do
4
+ let(:adapter) { described_class.new(context) }
3
5
  let(:context) { double(:context) }
4
6
  let(:request) { double(:request, fullpath: '/full?param=true', path: '/full') }
5
7
 
6
8
  before { allow(context).to receive_messages(request: request) }
7
9
 
10
+ describe '.register' do
11
+ let(:sinatra_app) { double(:app, root: '/sinatra/root', environment: 'test') }
12
+
13
+ before do
14
+ allow(SimpleNavigation).to receive(:set_env)
15
+ end
16
+
17
+ it 'calls SimpleNavigation.set_env with app root and environment' do
18
+ expect(SimpleNavigation).to receive(:set_env).with('/sinatra/root', 'test')
19
+ described_class.register(sinatra_app)
20
+ end
21
+ end
22
+
8
23
  describe '#context_for_eval' do
9
24
  context "when adapter's context is not set" do
10
25
  it 'raises an exception' do
11
26
  allow(adapter).to receive_messages(context: nil)
12
- expect{ adapter.context_for_eval }.to raise_error(RuntimeError, 'no context set for evaluation the config file')
27
+ expect do
28
+ adapter.context_for_eval
29
+ end.to raise_error(RuntimeError, 'no context set for evaluation the config file')
13
30
  end
14
31
  end
15
32
 
@@ -57,8 +74,7 @@ describe SimpleNavigation::Adapters::Sinatra do
57
74
 
58
75
  context 'when URL is encoded' do
59
76
  before do
60
- allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true',
61
- path: '/full%20with%20spaces')
77
+ allow(request).to receive_messages(fullpath: '/full%20with%20spaces?param=true', path: '/full%20with%20spaces')
62
78
  end
63
79
 
64
80
  it_behaves_like 'detecting current page', '/full%20with%20spaces?param=true', true
@@ -1,48 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'simple_navigation/config_file_finder'
3
5
 
4
- module SimpleNavigation
5
- describe ConfigFileFinder do
6
- subject(:finder) { ConfigFileFinder.new(paths) }
6
+ RSpec.describe SimpleNavigation::ConfigFileFinder do
7
+ subject(:finder) { described_class.new(paths) }
7
8
 
8
- let(:paths) { ['/path/one', '/path/two'] }
9
+ let(:paths) { ['/path/one', '/path/two'] }
9
10
 
10
- describe '#find', memfs: true do
11
- before { FileUtils.mkdir_p(paths) }
11
+ describe '#find', :memfs do
12
+ before { FileUtils.mkdir_p(paths) }
12
13
 
13
- context 'when the context is :default' do
14
- let(:context) { :default }
14
+ context 'when the context is :default' do
15
+ let(:context) { :default }
15
16
 
16
- context 'and a navigation.rb file is found in one of the paths' do
17
- before { FileUtils.touch('/path/one/navigation.rb') }
17
+ context 'when a navigation.rb file is found in one of the paths' do
18
+ before { FileUtils.touch('/path/one/navigation.rb') }
18
19
 
19
- it 'returns its full path' do
20
- expect(finder.find(context)).to eq '/path/one/navigation.rb'
21
- end
20
+ it 'returns its full path' do
21
+ expect(finder.find(context)).to eq '/path/one/navigation.rb'
22
22
  end
23
+ end
23
24
 
24
- context 'and no navigation.rb file is found in the paths' do
25
- it 'raises an exception' do
26
- expect { finder.find(context) }.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
27
- end
25
+ context 'when no navigation.rb file is found in the paths' do
26
+ it 'raises an exception' do
27
+ expect do
28
+ finder.find(context)
29
+ end.to raise_error(RuntimeError, /Config file 'navigation.rb' not found in path\(s\)/)
28
30
  end
29
31
  end
32
+ end
30
33
 
31
- context 'when the context is :other' do
32
- let(:context) { :other }
34
+ context 'when the context is :other' do
35
+ let(:context) { :other }
33
36
 
34
- context 'and a other_navigation.rb file is found in one of the paths' do
35
- before { FileUtils.touch('/path/two/other_navigation.rb') }
37
+ context 'when a other_navigation.rb file is found in one of the paths' do
38
+ before { FileUtils.touch('/path/two/other_navigation.rb') }
36
39
 
37
- it 'returns its full path' do
38
- expect(finder.find(context)).to eq '/path/two/other_navigation.rb'
39
- end
40
+ it 'returns its full path' do
41
+ expect(finder.find(context)).to eq '/path/two/other_navigation.rb'
40
42
  end
43
+ end
41
44
 
42
- context 'and no other_navigation.rb file is found in the paths' do
43
- it 'raise an exception' do
44
- expect{ finder.find(context) }.to raise_error(RuntimeError, /Config file 'other_navigation.rb' not found in path\(s\)/)
45
- end
45
+ context 'when no other_navigation.rb file is found in the paths' do
46
+ it 'raise an exception' do
47
+ expect do
48
+ finder.find(context)
49
+ end.to raise_error(RuntimeError, /Config file 'other_navigation.rb' not found in path\(s\)/)
46
50
  end
47
51
  end
48
52
  end