Skip to content

Commit bd83447

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

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# frozen_string_literal: true
2+
3+
# NOTE: This adapter is deprecated. It supports Nanoc3 (circa 2011-2012) which is obsolete.
4+
# These tests are maintained for backward compatibility only.
5+
RSpec.describe SimpleNavigation::Adapters::Nanoc do
6+
let(:adapter) { described_class.new(context) }
7+
let(:context) { double(:context, item: item) }
8+
let(:item) { double(:item, path: '/test/path/') }
9+
10+
describe '.register' do
11+
let(:nanoc_context) { double(:nanoc_context) }
12+
13+
before do
14+
stub_const('Nanoc3::Context', nanoc_context)
15+
allow(SimpleNavigation).to receive(:set_env)
16+
allow(nanoc_context).to receive(:include)
17+
end
18+
19+
it 'calls SimpleNavigation.set_env with root and development environment' do
20+
expect(SimpleNavigation).to receive(:set_env).with('/root/path', 'development')
21+
described_class.register('/root/path')
22+
end
23+
24+
it 'includes SimpleNavigation::Helpers in Nanoc3::Context' do
25+
expect(nanoc_context).to receive(:include).with(SimpleNavigation::Helpers)
26+
described_class.register('/root/path')
27+
end
28+
end
29+
30+
describe '#initialize' do
31+
it 'sets the context' do
32+
expect(adapter.instance_variable_get(:@context)).to eq context
33+
end
34+
end
35+
36+
describe '#context_for_eval' do
37+
it 'returns the context' do
38+
expect(adapter.context_for_eval).to eq context
39+
end
40+
end
41+
42+
describe '#current_page?' do
43+
context 'when the path matches the url (after chomping the trailing slash)' do
44+
it 'returns true' do
45+
expect(adapter.current_page?('/test/path')).to be true
46+
end
47+
end
48+
49+
context 'when the path does not match the url' do
50+
it 'returns false' do
51+
expect(adapter.current_page?('/other/path')).to be false
52+
end
53+
end
54+
55+
context 'when path is nil' do
56+
let(:item) { double(:item, path: nil) }
57+
58+
it 'returns nil' do
59+
expect(adapter.current_page?('/test/path')).to be_nil
60+
end
61+
end
62+
end
63+
64+
describe '#link_to' do
65+
it 'returns a link with the correct attributes' do
66+
link = adapter.link_to('Test Link', '/url', class: 'nav-link', id: 'link1')
67+
expect(link).to eq "<a href='/url' class='nav-link' id='link1'>Test Link</a>"
68+
end
69+
70+
it 'handles options without values' do
71+
link = adapter.link_to('Test', '/url', {})
72+
expect(link).to eq "<a href='/url' >Test</a>"
73+
end
74+
75+
it 'filters out nil values' do
76+
link = adapter.link_to('Test', '/url', class: 'nav', id: nil)
77+
expect(link).to eq "<a href='/url' class='nav'>Test</a>"
78+
end
79+
end
80+
81+
describe '#content_tag' do
82+
it 'returns a tag with the correct type, content and attributes' do
83+
tag = adapter.content_tag(:div, 'Content', class: 'container', id: 'main')
84+
expect(tag).to eq "<div class='container' id='main'>Content</div>"
85+
end
86+
87+
it 'handles tags without attributes' do
88+
tag = adapter.content_tag(:span, 'Text', {})
89+
expect(tag).to eq '<span >Text</span>'
90+
end
91+
92+
it 'filters out nil values from attributes' do
93+
tag = adapter.content_tag(:p, 'Paragraph', class: 'text', id: nil)
94+
expect(tag).to eq "<p class='text'>Paragraph</p>"
95+
end
96+
end
97+
end

0 commit comments

Comments
 (0)