Skip to content

Commit c52d078

Browse files
committed
fixed most rubocop todos, increased coverage
1 parent bd83447 commit c52d078

20 files changed

Lines changed: 245 additions & 243 deletions

.rubocop_todo.yml

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,24 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 4
10-
# This cop supports safe autocorrection (--autocorrect).
11-
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
12-
# URISchemes: http, https
13-
Layout/LineLength:
14-
Exclude:
15-
- 'generators/navigation_config/templates/config/navigation.rb'
16-
- 'spec/simple_navigation/helpers_spec.rb'
17-
18-
# Offense count: 1
19-
# Configuration parameters: MaxRangeSize.
20-
Lint/MissingCopEnableDirective:
21-
Exclude:
22-
- 'spec/simple_navigation/configuration_spec.rb'
23-
24-
# Offense count: 11
25-
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
26-
# SupportedStyles: snake_case, normalcase, non_integer
27-
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
28-
Naming/VariableNumber:
29-
Exclude:
30-
- 'generators/navigation_config/templates/config/navigation.rb'
31-
- 'spec/fake_app/config/navigation.rb'
32-
- 'spec/simple_navigation/item_container_spec.rb'
33-
34-
# Offense count: 122
35-
# Configuration parameters: Prefixes, AllowedPatterns.
36-
# Prefixes: when, with, without
37-
RSpec/ContextWording:
38-
Exclude:
39-
- 'spec/simple_navigation/adapters/rails_spec.rb'
40-
- 'spec/simple_navigation/config_file_finder_spec.rb'
41-
- 'spec/simple_navigation/configuration_spec.rb'
42-
- 'spec/simple_navigation/helpers_spec.rb'
43-
- 'spec/simple_navigation/item_adapter_spec.rb'
44-
- 'spec/simple_navigation/item_container_spec.rb'
45-
- 'spec/simple_navigation/item_spec.rb'
46-
- 'spec/simple_navigation/items_provider_spec.rb'
47-
- 'spec/simple_navigation/renderer/base_spec.rb'
48-
- 'spec/simple_navigation/renderer/breadcrumbs_spec.rb'
49-
- 'spec/simple_navigation/renderer/text_spec.rb'
50-
- 'spec/simple_navigation_spec.rb'
51-
52-
# Offense count: 4
53-
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
54-
RSpec/IndexedLet:
55-
Exclude:
56-
- 'spec/simple_navigation/item_container_spec.rb'
57-
589
# Offense count: 46
5910
# Configuration parameters: .
6011
# SupportedStyles: have_received, receive
6112
RSpec/MessageSpies:
6213
EnforcedStyle: receive
6314

64-
# Offense count: 38
65-
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
66-
# SupportedStyles: always, named_only
67-
RSpec/NamedSubject:
68-
Exclude:
69-
- 'spec/simple_navigation_spec.rb'
70-
7115
# Offense count: 24
7216
RSpec/SubjectStub:
7317
Exclude:
7418
- 'spec/simple_navigation/item_container_spec.rb'
7519
- 'spec/simple_navigation/renderer/base_spec.rb'
7620
- 'spec/simple_navigation_spec.rb'
7721

78-
# Offense count: 65
22+
# Offense count: 69
7923
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
8024
RSpec/VerifiedDoubles:
8125
Exclude:
26+
- 'spec/simple_navigation/adapters/nanoc_spec.rb'
8227
- 'spec/simple_navigation/adapters/padrino_spec.rb'
8328
- 'spec/simple_navigation/adapters/rails_spec.rb'
8429
- 'spec/simple_navigation/adapters/sinatra_spec.rb'

generators/navigation_config/templates/config/navigation.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@
3535
# navigation.ignore_query_params_on_auto_highlight = true
3636
# navigation.ignore_anchors_on_auto_highlight = true
3737

38-
# If this option is set to true, all item names will be considered as safe (passed through html_safe). Defaults to false.
38+
# If this option is set to true, all item names will be considered as safe
39+
# (passed through html_safe). Defaults to false.
3940
# navigation.consider_item_names_as_safe = false
4041

4142
# Define the primary navigation
4243
navigation.items do |primary|
4344
# Add an item to the primary navigation. The following params apply:
4445
# key - a symbol which uniquely defines your navigation item in the scope of the primary_navigation
4546
# name - will be displayed in the rendered navigation. This can also be a call to your I18n-framework.
46-
# url - the address that the generated item links to. You can also use url_helpers (named routes, restful routes helper, url_for etc.)
47-
# options - can be used to specify attributes that will be included in the rendered navigation item (e.g. id, class etc.)
47+
# url - the address that the generated item links to. You can also use url_helpers
48+
# (named routes, restful routes helper, url_for etc.)
49+
# options - can be used to specify attributes that will be included in the rendered
50+
# navigation item (e.g. id, class etc.)
4851
# some special options that can be set:
4952
# :html - Specifies html attributes that will be included in the rendered navigation item
5053
# :if - Specifies a proc to call to determine if the item should
@@ -58,19 +61,19 @@
5861
# when the item should be highlighted, you can set a regexp which is matched
5962
# against the current URI. You may also use a proc, or the symbol <tt>:subpath</tt>.
6063
#
61-
primary.item :key_1, 'name', url, options
64+
primary.item :key1, 'name', url, options
6265

6366
# Add an item which has a sub navigation (same params, but with block)
64-
primary.item :key_2, 'name', url, options do |sub_nav|
67+
primary.item :key2, 'name', url, options do |sub_nav|
6568
# Add an item to the sub navigation (same params again)
66-
sub_nav.item :key_2_1, 'name', url, options
69+
sub_nav.item :key21, 'name', url, options
6770
end
6871

6972
# You can also specify a condition-proc that needs to be fullfilled to display an item.
7073
# Conditions are part of the options. They are evaluated in the context of the views,
7174
# thus you can use all the methods and vars you have available in the views.
72-
primary.item :key_3, 'Admin', url, html: { class: 'special' }, if: -> { current_user.admin? }
73-
primary.item :key_4, 'Account', url, unless: -> { logged_in? }
75+
primary.item :key3, 'Admin', url, html: { class: 'special' }, if: -> { current_user.admin? }
76+
primary.item :key4, 'Account', url, unless: -> { logged_in? }
7477

7578
# you can also specify html attributes to attach to this particular level
7679
# works for all levels of the menu

lib/simple_navigation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ def set_env(root, environment)
7373
# Returns the current framework in which the plugin is running.
7474
def framework
7575
return :rails if defined?(Rails)
76+
# :nocov:
7677
return :padrino if defined?(Padrino)
7778
return :sinatra if defined?(Sinatra)
7879
return :nanoc if defined?(Nanoc3)
7980

8081
raise 'simple_navigation currently only works for Rails, Sinatra and Padrino apps'
82+
# :nocov:
8183
end
8284

8385
# Loads the adapter for the current framework

lib/simple_navigation/adapters/nanoc.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
module SimpleNavigation
44
module Adapters
5+
# @deprecated This adapter is for Nanoc3 (circa 2011-2012) and is no longer actively maintained.
6+
# Nanoc3 is obsolete and has been replaced by Nanoc 4+. This adapter is kept for
7+
# backward compatibility but should not be used for new projects.
58
class Nanoc < Base
69
class << self
710
def register(root)

spec/fake_app/config/navigation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SimpleNavigation::Configuration.run do |navigation|
44
navigation.items do |nav|
5-
nav.item :item_1, 'Item 1', '/item_1', html: { class: 'item_1' }, link_html: { id: 'link_1' }
6-
nav.item :item_2, 'Item 2', '/item_2', html: { class: 'item_2' }, link_html: { id: 'link_2' }
5+
nav.item :item1, 'Item 1', '/item_1', html: { class: 'item_1' }, link_html: { id: 'link_1' }
6+
nav.item :item2, 'Item 2', '/item_2', html: { class: 'item_2' }, link_html: { id: 'link_2' }
77
end
88
end

spec/simple_navigation/adapters/padrino_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66
let(:context) { double(:context, request: request) }
77
let(:request) { double(:request) }
88

9+
describe '.register' do
10+
let(:padrino_module) { Module.new }
11+
let(:padrino_application) { Module.new }
12+
13+
before do
14+
stub_const('Padrino', padrino_module)
15+
stub_const('Padrino::Application', padrino_application)
16+
allow(padrino_module).to receive_messages(root: '/padrino/root', env: 'production')
17+
allow(SimpleNavigation).to receive(:set_env)
18+
allow(padrino_application).to receive(:send)
19+
end
20+
21+
it 'calls SimpleNavigation.set_env with Padrino root and env' do
22+
expect(SimpleNavigation).to receive(:set_env).with('/padrino/root', 'production')
23+
described_class.register(nil)
24+
end
25+
26+
it 'includes SimpleNavigation::Helpers in Padrino::Application' do
27+
expect(padrino_application).to receive(:send).with(:helpers, SimpleNavigation::Helpers)
28+
described_class.register(nil)
29+
end
30+
end
31+
932
describe '#link_to' do
1033
it 'delegates to context' do
1134
expect(context).to receive(:link_to).with('name', 'url', { my_option: true })

spec/simple_navigation/adapters/rails_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@
7979
end
8080

8181
context "when the controller's template is stored as view_context (Rails3)" do
82-
context 'and the template is set' do
82+
context 'when the template is set' do
8383
before { allow(controller).to receive_messages(view_context: template) }
8484

8585
it "sets the adapter's template accordingly" do
8686
expect(adapter.template).to be template
8787
end
8888
end
8989

90-
context 'and the template is not set' do
90+
context 'when the template is not set' do
9191
before { allow(controller).to receive_messages(view_context: nil) }
9292

9393
it "sets the adapter's template to nil" do
@@ -101,15 +101,15 @@
101101
context "when the adapter's request is set" do
102102
before { allow(adapter).to receive_messages(request: request) }
103103

104-
context 'and request.fullpath is defined' do
104+
context 'when request.fullpath is defined' do
105105
let(:request) { double(:request, fullpath: '/fullpath') }
106106

107107
it "sets the adapter's request_uri to the request.fullpath" do
108108
expect(adapter.request_uri).to eq '/fullpath'
109109
end
110110
end
111111

112-
context 'and request.fullpath is not defined' do
112+
context 'when request.fullpath is not defined' do
113113
let(:request) { double(:request, request_uri: '/request_uri') }
114114

115115
before { allow(adapter).to receive_messages(request: request) }
@@ -153,15 +153,15 @@
153153
context "when the adapter's controller is set" do
154154
before { adapter.instance_variable_set(:@controller, controller) }
155155

156-
context "and the adapter's template is set" do
156+
context "when the adapter's template is set" do
157157
before { adapter.instance_variable_set(:@template, template) }
158158

159159
it "sets the adapter's context_for_eval to the template" do
160160
expect(adapter.context_for_eval).to be template
161161
end
162162
end
163163

164-
context "and the adapter's template is not set" do
164+
context "when the adapter's template is not set" do
165165
before { adapter.instance_variable_set(:@template, nil) }
166166

167167
it "sets the adapter's context_for_eval to the controller" do
@@ -173,15 +173,15 @@
173173
context "when the adapter's controller is not set" do
174174
before { adapter.instance_variable_set(:@controller, nil) }
175175

176-
context "and the adapter's template is set" do
176+
context "when the adapter's template is set" do
177177
before { adapter.instance_variable_set(:@template, template) }
178178

179179
it "sets the adapter's context_for_eval to the template" do
180180
expect(adapter.context_for_eval).to be template
181181
end
182182
end
183183

184-
context "and the adapter's template is not set" do
184+
context "when the adapter's template is not set" do
185185
before { adapter.instance_variable_set(:@template, nil) }
186186

187187
it 'raises an exception' do

spec/simple_navigation/adapters/sinatra_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

88
before { allow(context).to receive_messages(request: request) }
99

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+
1023
describe '#context_for_eval' do
1124
context "when adapter's context is not set" do
1225
it 'raises an exception' do

spec/simple_navigation/config_file_finder_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
context 'when the context is :default' do
1515
let(:context) { :default }
1616

17-
context 'and a navigation.rb file is found in one of the paths' do
17+
context 'when a navigation.rb file is found in one of the paths' do
1818
before { FileUtils.touch('/path/one/navigation.rb') }
1919

2020
it 'returns its full path' do
2121
expect(finder.find(context)).to eq '/path/one/navigation.rb'
2222
end
2323
end
2424

25-
context 'and no navigation.rb file is found in the paths' do
25+
context 'when no navigation.rb file is found in the paths' do
2626
it 'raises an exception' do
2727
expect do
2828
finder.find(context)
@@ -34,15 +34,15 @@
3434
context 'when the context is :other' do
3535
let(:context) { :other }
3636

37-
context 'and a other_navigation.rb file is found in one of the paths' do
37+
context 'when a other_navigation.rb file is found in one of the paths' do
3838
before { FileUtils.touch('/path/two/other_navigation.rb') }
3939

4040
it 'returns its full path' do
4141
expect(finder.find(context)).to eq '/path/two/other_navigation.rb'
4242
end
4343
end
4444

45-
context 'and no other_navigation.rb file is found in the paths' do
45+
context 'when no other_navigation.rb file is found in the paths' do
4646
it 'raise an exception' do
4747
expect do
4848
finder.find(context)

spec/simple_navigation/configuration_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
before { allow(SimpleNavigation::ItemContainer).to receive_messages(new: container) }
8787

8888
context 'when a block is given' do
89-
context 'and items_provider is specified' do
89+
context 'when items_provider is specified' do
9090
let(:provider) { double(:provider) }
9191

9292
it 'raises an exception' do
@@ -95,6 +95,7 @@
9595
config.items(provider) do
9696
end
9797
end.to raise_error(RuntimeError, 'please specify either items_provider or block, but not both')
98+
# rubocop:enable Lint/EmptyBlock
9899
end
99100
end
100101

@@ -116,7 +117,7 @@
116117
end
117118

118119
context 'when no block is given' do
119-
context 'and items_provider is specified' do
120+
context 'when items_provider is specified' do
120121
let(:external_provider) { double(:external_provider) }
121122
let(:items) { double(:items) }
122123
let(:items_provider) { double(:items_provider, items: items) }

0 commit comments

Comments
 (0)