-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
generator_spec.rb
92 lines (73 loc) · 2.51 KB
/
generator_spec.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
RSpec.describe JekyllTitlesFromHeadings::Generator do
let(:site) { fixture_site("site") }
let(:post) { site.posts.first }
let(:page) { page_by_path(site, "page.md") }
let(:page_with_title) { page_by_path(site, "page-with-title.md") }
let(:html_page) { page_by_path(site, "html-page.html") }
let(:page_with_h2) { page_by_path(site, "page-with-h2.md") }
let(:page_with_h3) { page_by_path(site, "page-with-h3.md") }
subject { described_class.new(site) }
before(:each) do
site.reset
site.read
end
it "saves the site" do
expect(subject.site).to eql(site)
end
context "detecting titles" do
it "knows when a page has a title" do
expect(subject.title?(page_with_title)).to eql(true)
end
it "knows when a page doesn't have a title" do
expect(subject.title?(page)).to eql(false)
end
end
context "detecting markdown" do
it "knows when a page is markdown" do
expect(subject.markdown?(page)).to eql(true)
end
it "knows when a page isn't markdown" do
expect(subject.markdown?(html_page)).to eql(false)
end
it "knows the markdown converter" do
expect(subject.markdown_converter).to be_a(Jekyll::Converters::Markdown)
end
end
context "detecting when to add a title" do
it "knows not to add a title for pages with titles" do
expect(subject.should_add_title?(page_with_title)).to eql(false)
end
it "knows not to add a title for HTML pages" do
expect(subject.should_add_title?(html_page)).to eql(false)
end
it "knows not add a title to non-HTML pages without titles" do
expect(subject.should_add_title?(page)).to eql(true)
end
end
context "extracting title" do
it "pulls title with an H1" do
expect(subject.title_for(page)).to eql("Just an H1")
end
it "pulls title with an H2" do
expect(subject.title_for(page_with_h2)).to eql("Just an H2")
end
it "pulls title with an H3" do
expect(subject.title_for(page_with_h3)).to eql("Just an H3")
end
it "respects YAML titles" do
expect(subject.title_for(page_with_title)).to eql("Page with title")
end
end
context "generating" do
before { subject.generate(site) }
it "sets titles for pages" do
expect(page.data["title"]).to eql("Just an H1")
end
it "respect a document's auto-generated title" do
expect(post.data["title"]).to eql("Test")
end
it "respects a document's YAML title" do
expect(page_with_title.data["title"]).to eql("Page with title")
end
end
end