rpub 0.4.0 → 0.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 (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -1
  3. data/.rspec +0 -1
  4. data/.travis.yml +3 -4
  5. data/.yardopts +1 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +70 -46
  8. data/Guardfile +6 -0
  9. data/HISTORY.md +10 -0
  10. data/README.md +1 -1
  11. data/Rakefile +7 -2
  12. data/bin/rpub +64 -1
  13. data/doc/.gitignore +8 -0
  14. data/doc/api/Rpub.html +339 -0
  15. data/doc/api/Rpub/Book.html +983 -0
  16. data/doc/api/Rpub/Chapter.html +737 -0
  17. data/doc/api/Rpub/Command.html +356 -0
  18. data/doc/api/Rpub/Commands.html +117 -0
  19. data/doc/api/Rpub/Commands/Clean.html +216 -0
  20. data/doc/api/Rpub/Commands/Compile.html +218 -0
  21. data/doc/api/Rpub/Commands/Generate.html +242 -0
  22. data/doc/api/Rpub/Commands/Package.html +230 -0
  23. data/doc/api/Rpub/Commands/Preview.html +216 -0
  24. data/doc/api/Rpub/Commands/Stats.html +226 -0
  25. data/doc/api/Rpub/Compressor.html +687 -0
  26. data/doc/api/Rpub/Context.html +553 -0
  27. data/doc/api/Rpub/Document.html +647 -0
  28. data/doc/api/Rpub/Document/OutlineElement.html +388 -0
  29. data/doc/api/Rpub/Epub.html +465 -0
  30. data/doc/api/Rpub/Epub/Container.html +224 -0
  31. data/doc/api/Rpub/Epub/Content.html +344 -0
  32. data/doc/api/Rpub/Epub/Cover.html +236 -0
  33. data/doc/api/Rpub/Epub/HtmlToc.html +240 -0
  34. data/doc/api/Rpub/Epub/Toc.html +244 -0
  35. data/doc/api/Rpub/FilesystemSource.html +544 -0
  36. data/doc/api/Rpub/HashDelegation.html +281 -0
  37. data/doc/api/Rpub/HashDelegation/ClassMethods.html +175 -0
  38. data/doc/api/Rpub/MediaType.html +192 -0
  39. data/doc/api/Rpub/Preview.html +464 -0
  40. data/doc/api/Rpub/XmlFile.html +457 -0
  41. data/doc/api/_index.html +405 -0
  42. data/doc/api/class_list.html +54 -0
  43. data/doc/api/css/common.css +1 -0
  44. data/doc/api/css/full_list.css +57 -0
  45. data/doc/api/css/style.css +339 -0
  46. data/doc/api/file.HISTORY.html +131 -0
  47. data/doc/api/file.LICENSE.html +92 -0
  48. data/doc/api/file.README.html +337 -0
  49. data/doc/api/file_list.html +62 -0
  50. data/doc/api/frames.html +26 -0
  51. data/doc/api/index.html +337 -0
  52. data/doc/api/js/app.js +219 -0
  53. data/doc/api/js/full_list.js +178 -0
  54. data/doc/api/js/jquery.js +4 -0
  55. data/doc/api/method_list.html +533 -0
  56. data/doc/api/top-level-namespace.html +112 -0
  57. data/doc/index.html +312 -0
  58. data/doc/javascripts/scale.fix.js +17 -0
  59. data/doc/params.json +1 -0
  60. data/doc/stylesheets/pygment_trac.css +69 -0
  61. data/doc/stylesheets/styles.css +255 -0
  62. data/features/clean.feature +31 -0
  63. data/features/compile.feature +49 -0
  64. data/features/embedded_assets.feature +51 -0
  65. data/features/generate.feature +63 -0
  66. data/features/layout.feature +41 -0
  67. data/features/package.feature +30 -0
  68. data/features/previews.feature +66 -0
  69. data/features/stats.feature +18 -0
  70. data/features/step_definitions/general_steps.rb +60 -0
  71. data/features/styles.feature +33 -0
  72. data/features/support/env.rb +7 -0
  73. data/features/table_of_contents.feature +35 -0
  74. data/lib/rpub.rb +28 -31
  75. data/lib/rpub/book.rb +9 -16
  76. data/lib/rpub/chapter.rb +4 -54
  77. data/lib/rpub/command.rb +32 -0
  78. data/lib/rpub/commands/clean.rb +4 -49
  79. data/lib/rpub/commands/compile.rb +4 -49
  80. data/lib/rpub/commands/generate.rb +10 -67
  81. data/lib/rpub/commands/package.rb +9 -37
  82. data/lib/rpub/commands/preview.rb +4 -54
  83. data/lib/rpub/commands/stats.rb +6 -10
  84. data/lib/rpub/compressor.rb +3 -3
  85. data/lib/rpub/context.rb +48 -0
  86. data/lib/rpub/document.rb +68 -0
  87. data/lib/rpub/epub.rb +8 -7
  88. data/lib/rpub/epub/content.rb +9 -30
  89. data/lib/rpub/epub/cover.rb +1 -8
  90. data/lib/rpub/epub/html_toc.rb +4 -9
  91. data/lib/rpub/epub/toc.rb +16 -13
  92. data/lib/rpub/filesystem_source.rb +47 -0
  93. data/lib/rpub/media_type.rb +16 -0
  94. data/lib/rpub/preview.rb +29 -0
  95. data/lib/rpub/version.rb +1 -1
  96. data/lib/rpub/xml_file.rb +4 -1
  97. data/rpub.gemspec +6 -7
  98. data/spec/rpub/book_spec.rb +45 -45
  99. data/spec/rpub/chapter_spec.rb +87 -22
  100. data/spec/rpub/epub/container_spec.rb +3 -5
  101. data/spec/rpub/epub/content_spec.rb +62 -41
  102. data/spec/rpub/epub/cover_spec.rb +3 -5
  103. data/spec/rpub/epub/html_toc_spec.rb +8 -8
  104. data/spec/rpub/epub/toc_spec.rb +20 -22
  105. data/spec/rpub_spec.rb +1 -3
  106. data/spec/spec_helper.rb +28 -0
  107. data/support/config.yml +1 -0
  108. data/support/styles.css +3 -3
  109. metadata +131 -120
  110. data/lib/rpub/commander.rb +0 -23
  111. data/lib/rpub/commands/base.rb +0 -33
  112. data/lib/rpub/commands/help.rb +0 -37
  113. data/lib/rpub/commands/main.rb +0 -45
  114. data/lib/rpub/compilation_helpers.rb +0 -73
  115. data/lib/rpub/subclass_tracker.rb +0 -53
  116. data/spec/rpub/commands/clean_spec.rb +0 -46
  117. data/spec/rpub/commands/generate_spec.rb +0 -52
  118. data/spec/rpub/commands/main_spec.rb +0 -26
  119. data/spec/rpub/commands/package_spec.rb +0 -33
  120. data/spec/rpub/commands/preview_spec.rb +0 -43
@@ -1,81 +1,146 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Chapter do
4
2
  let(:subject) { described_class.new('foo', 1, 'document') }
5
3
 
6
- its(:content) { should == 'foo' }
7
- its(:number) { should == 1 }
8
- its(:layout) { should == 'document' }
4
+ describe '#content' do
5
+ subject { super().content }
6
+ it { is_expected.to eq('foo') }
7
+ end
8
+
9
+ describe '#number' do
10
+ subject { super().number }
11
+ it { is_expected.to eq(1) }
12
+ end
13
+
14
+ describe '#layout' do
15
+ subject { super().layout }
16
+ it { is_expected.to eq('document') }
17
+ end
9
18
 
10
19
  describe '#uid' do
11
20
  it 'should change when content changes' do
12
- subject.uid.should_not == described_class.new('bar', 1, 'bar').uid
21
+ expect(subject.uid).to_not eql(described_class.new('bar', 1, 'bar').uid)
13
22
  end
14
23
 
15
24
  it 'should change when layout changes' do
16
- subject.uid.should_not == described_class.new('foo', 1, 'qux').uid
25
+ expect(subject.uid).to_not eql(described_class.new('foo', 1, 'qux').uid)
17
26
  end
18
27
 
19
28
  it 'should change when content changes' do
20
- subject.uid.should_not == described_class.new('foo', 2, 'bar').uid
29
+ expect(subject.uid).to_not eql(described_class.new('foo', 2, 'bar').uid)
21
30
  end
22
31
  end
23
32
 
24
33
  describe '#xml_id' do
25
- its(:xml_id) { should == 'chapter-1' }
34
+ describe '#xml_id' do
35
+ subject { super().xml_id }
36
+ it { is_expected.to eq('chapter-1') }
37
+ end
26
38
  end
27
39
 
28
40
  describe '#filename' do
29
- its(:filename) { should == 'chapter-1-untitled.html' }
41
+ describe '#filename' do
42
+ subject { super().filename }
43
+ it { is_expected.to eq('chapter-1-untitled.html') }
44
+ end
30
45
  end
31
46
 
32
47
  describe '#outline' do
33
48
  context 'when there are no headings' do
34
49
  let(:subject) { described_class.new('foo', 1, 'document') }
35
- its(:outline) { should have(0).elements }
36
- its(:outline) { should be_empty }
50
+
51
+ describe '#outline' do
52
+ subject { super().outline }
53
+
54
+ it 'has no elements' do
55
+ expect(subject.size).to eq(0)
56
+ end
57
+ end
58
+
59
+ describe '#outline' do
60
+ subject { super().outline }
61
+ it { is_expected.to be_empty }
62
+ end
37
63
  end
38
64
 
39
65
  context 'when there are headings' do
40
66
  let(:subject) { described_class.new('# foo', 1, 'document') }
41
- its(:outline) { should have(1).elements }
67
+
68
+ describe '#outline' do
69
+ subject { super().outline }
70
+
71
+ it 'has 1 element' do
72
+ expect(subject.size).to eq(1)
73
+ end
74
+ end
42
75
 
43
76
  context 'a single heading entry' do
44
77
  let(:subject) { described_class.new('# foo', 1, 'document').outline.first }
45
- its(:level) { should == 1 }
46
- its(:text) { should == 'foo' }
47
- its(:html_id) { should == 'foo' }
78
+
79
+ describe '#level' do
80
+ subject { super().level }
81
+ it { is_expected.to eq(1) }
82
+ end
83
+
84
+ describe '#text' do
85
+ subject { super().text }
86
+ it { is_expected.to eq('foo') }
87
+ end
88
+
89
+ describe '#html_id' do
90
+ subject { super().html_id }
91
+ it { is_expected.to eq('foo') }
92
+ end
48
93
  end
49
94
  end
50
95
  end
51
96
 
52
97
  describe '#title' do
53
98
  context 'without a suitable markdown title' do
54
- its(:title) { should == 'untitled' }
99
+ describe '#title' do
100
+ subject { super().title }
101
+ it { is_expected.to eq('untitled') }
102
+ end
55
103
  end
56
104
 
57
105
  context 'with a markdown heading' do
58
106
  let(:subject) { described_class.new('# My Title', 1, 'bar') }
59
- its(:title) { should == 'My Title' }
107
+
108
+ describe '#title' do
109
+ subject { super().title }
110
+ it { is_expected.to eq('My Title') }
111
+ end
60
112
  end
61
113
  end
62
114
 
63
115
  describe 'markdown parsing' do
64
116
  let(:subject) { described_class.new('foo', 1, nil) }
65
- its(:to_html) { should == "<p>foo</p>\n" }
117
+
118
+ describe '#to_html' do
119
+ subject { super().to_html }
120
+ it { is_expected.to eq("<p>foo</p>\n") }
121
+ end
66
122
  end
67
123
 
68
124
  describe '#images' do
69
125
  let(:subject) { described_class.new('![alt](foo.png)', 1, 'document') }
70
126
 
71
- it { should have(1).images }
72
- its('images.first') { should == 'foo.png' }
127
+ it 'has 1 image' do
128
+ expect(subject.images.size).to eq(1)
129
+ end
130
+
131
+ describe '#images' do
132
+ subject { super().images }
133
+ describe '#first' do
134
+ subject { super().first }
135
+ it { is_expected.to eq('foo.png') }
136
+ end
137
+ end
73
138
  end
74
139
 
75
140
  describe '#outline' do
76
141
  let(:subject) { described_class.new("# foo\n\nbla bla bla \n\n## bar\n\n# baz", 1, nil) }
77
142
  it 'should list headings in order' do
78
- subject.outline.map(&:text).should == %w[foo bar baz]
143
+ expect(subject.outline.map(&:text)).to eql(%w[foo bar baz])
79
144
  end
80
145
  end
81
146
  end
@@ -1,8 +1,6 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Epub::Container do
4
2
  let(:subject) { described_class.new.render }
5
- it { should have_xpath('/xmlns:container') }
6
- it { should have_xpath('/xmlns:container[@version="1.0"]') }
7
- it { should have_xpath('/xmlns:container/xmlns:rootfiles/xmlns:rootfile[@media-type="application/oebps-package+xml"]') }
3
+ it { is_expected.to have_xpath('/xmlns:container') }
4
+ it { is_expected.to have_xpath('/xmlns:container[@version="1.0"]') }
5
+ it { is_expected.to have_xpath('/xmlns:container/xmlns:rootfiles/xmlns:rootfile[@media-type="application/oebps-package+xml"]') }
8
6
  end
@@ -1,21 +1,25 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Epub::Content do
2
+ let(:config) do
3
+ OpenStruct.new({
4
+ 'creator' => 'anonymous',
5
+ 'title' => 'title',
6
+ 'language' => 'en',
7
+ 'publisher' => 'none',
8
+ 'description' => 'foo bar',
9
+ 'subject' => 'baz qux',
10
+ 'rights' => 'copyright',
11
+ 'cover_image' => 'image.jpg'
12
+ })
13
+ end
4
14
  let(:book) do
5
15
  double('book', {
6
- :creator => 'anonymous',
7
- :title => 'title',
8
- :language => 'en',
9
- :publisher => 'none',
10
- :description => 'foo bar',
11
- :subject => 'baz qux',
12
- :rights => 'copyright',
13
- :uid => 'abcd',
14
- :has_cover? => false,
15
- :has_fonts? => false,
16
- :has_toc? => false,
17
- :images => [],
18
- :chapters => []
16
+ :config => config,
17
+ :uid => 'abcd',
18
+ :has_cover? => false,
19
+ :has_fonts? => false,
20
+ :has_toc? => false,
21
+ :images => [],
22
+ :chapters => []
19
23
  })
20
24
  end
21
25
  let(:subject) { described_class.new(book).render }
@@ -24,53 +28,70 @@ describe Rpub::Epub::Content do
24
28
  attr = options.inject('') do |str, (k, v)|
25
29
  str << "[@#{k}=\"#{v}\"]"
26
30
  end
27
- it { should have_xpath(%Q{/xmlns:package/xmlns:metadata/dc:#{name}[text()="#{value}"]#{attr}}, 'dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns' => 'http://www.idpf.org/2007/opf') }
31
+ it { is_expected.to have_xpath(%Q{/xmlns:package/xmlns:metadata/dc:#{name}[text()="#{value}"]#{attr}}, 'dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns' => 'http://www.idpf.org/2007/opf') }
28
32
  end
29
33
 
30
34
  context 'with an empty book' do
31
35
 
32
- it { should have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
33
- it { should have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
36
+ it { is_expected.to have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
37
+ it { is_expected.to have_xpath('/xmlns:package[@unique-identifier="BookId"][@version="2.0"]') }
34
38
 
35
- it_should_have_metadata 'title', "title"
36
- it_should_have_metadata 'creator', "anonymous", 'xmlns:role' => 'aut'
37
- it_should_have_metadata 'publisher', "none"
38
- it_should_have_metadata 'subject', "baz qux"
39
- it_should_have_metadata 'identifier', "abcd", :id => 'BookId'
40
- it_should_have_metadata 'rights', "copyright"
39
+ it_should_have_metadata 'title', "title"
40
+ it_should_have_metadata 'creator', "anonymous", 'xmlns:role' => 'aut'
41
+ it_should_have_metadata 'publisher', "none"
42
+ it_should_have_metadata 'subject', "baz qux"
43
+ it_should_have_metadata 'identifier', "abcd", :id => 'BookId'
44
+ it_should_have_metadata 'rights', "copyright"
41
45
  it_should_have_metadata 'description', "foo bar"
42
46
  end
43
47
 
44
48
  context 'when the book has a cover' do
45
- before { book.stub! :has_cover? => true, :cover_image => 'foo.jpg' }
46
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover"][@href="cover.html"][@media-type="application/xhtml+xml"]') }
47
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover-image"][@href="foo.jpg"][@media-type="image/jpeg"]') }
48
- it { should have_xpath('/xmlns:package/xmlns:metadata/xmlns:meta[@name="cover"][@content="cover-image"]') }
49
- it { should have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="cover"][@title="Cover"][@href="cover.html"]') }
50
- it { should have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="cover"][@linear="no"]') }
49
+ before do
50
+ allow(book).to receive(:has_cover?).and_return(true)
51
+ allow(config).to receive(:cover_image).and_return('foo.jpg')
52
+ end
53
+
54
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover"][@href="cover.html"][@media-type="application/xhtml+xml"]') }
55
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="cover-image"][@href="foo.jpg"][@media-type="image/jpeg"]') }
56
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:metadata/xmlns:meta[@name="cover"][@content="cover-image"]') }
57
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="cover"][@title="Cover"][@href="cover.html"]') }
58
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="cover"][@linear="no"]') }
51
59
  end
52
60
 
53
61
  context 'when the book has embedded fonts' do
54
- before { book.stub! :has_fonts? => true, :fonts => ['font.otf'] }
55
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="font.otf"][@href="font.otf"][@media-type="font/opentype"]') }
62
+ before do
63
+ allow(book).to receive(:has_fonts?).and_return(true)
64
+ allow(book).to receive(:fonts).and_return(['font.otf'])
65
+ end
66
+
67
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="font.otf"][@href="font.otf"][@media-type="font/opentype"]') }
56
68
  end
57
69
 
58
70
  context 'when the book has a ToC' do
59
- before { book.stub! :has_toc? => true }
60
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="toc"][@href="toc.html"][@media-type="application/xhtml+xml"]') }
61
- it { should have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="toc"][@title="Table of Contents"][@href="toc.html"]') }
71
+ before do
72
+ allow(book).to receive(:has_toc?).and_return(true)
73
+ end
74
+
75
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="toc"][@href="toc.html"][@media-type="application/xhtml+xml"]') }
76
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:guide/xmlns:reference[@type="toc"][@title="Table of Contents"][@href="toc.html"]') }
62
77
  end
63
78
 
64
79
  context 'when the book has images' do
65
- before { book.stub! :images => ['foo.png', 'bar.gif'] }
66
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="foo.png"][@href="foo.png"][@media-type="image/png"]') }
67
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="bar.gif"][@href="bar.gif"][@media-type="image/gif"]') }
80
+ before do
81
+ allow(book).to receive(:images).and_return(['foo.png', 'bar.gif'])
82
+ end
83
+
84
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="foo.png"][@href="foo.png"][@media-type="image/png"]') }
85
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="bar.gif"][@href="bar.gif"][@media-type="image/gif"]') }
68
86
  end
69
87
 
70
88
  context 'when the book has chapters' do
71
89
  let(:chapter) { double('chapter', :filename => 'chapter.html', :xml_id => 'chapter1') }
72
- before { book.stub! :chapters => [chapter] }
73
- it { should have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="chapter1"][@href="chapter.html"][@media-type="application/xhtml+xml"]') }
74
- it { should have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="chapter1"]') }
90
+ before do
91
+ allow(book).to receive(:chapters).and_return([chapter])
92
+ end
93
+
94
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:manifest/xmlns:item[@id="chapter1"][@href="chapter.html"][@media-type="application/xhtml+xml"]') }
95
+ it { is_expected.to have_xpath('/xmlns:package/xmlns:spine[@toc="ncx"]/xmlns:itemref[@idref="chapter1"]') }
75
96
  end
76
97
  end
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Epub::Cover do
4
- let(:book) { double('book', :cover_image => 'cover.jpg', :title => 'title') }
2
+ let(:book) { double('book', :config => double('config', :cover_image => 'cover.jpg', :title => 'title')) }
5
3
  let(:subject) { described_class.new(book).render }
6
4
 
7
- it { should have_xpath('/xmlns:html/xmlns:head/xmlns:title[text()="Cover"]') }
8
- it { should have_xpath('/xmlns:html/xmlns:body/xmlns:div/xmlns:img[@src="cover.jpg"][@alt="title"]') }
5
+ it { is_expected.to have_xpath('/xmlns:html/xmlns:head/xmlns:title[text()="Cover"]') }
6
+ it { is_expected.to have_xpath('/xmlns:html/xmlns:body/xmlns:div/xmlns:img[@src="cover.jpg"][@alt="title"]') }
9
7
  end
@@ -1,19 +1,19 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Epub::HtmlToc do
4
2
  let(:outline) { [] }
5
- let(:book) { double('book', :outline => outline) }
3
+ let(:book) { double('book', :outline => outline, :config => config) }
4
+ let(:config) { OpenStruct.new({ 'max_level' => 1 }) }
6
5
  let(:subject) { described_class.new(book).render }
7
6
 
8
- it { should have_xpath('/div/h1[text()="Table of Contents"]') }
9
- it { should have_xpath('/div/div[@class="toc"]') }
7
+ it { is_expected.to have_xpath('/div/h1[text()="Table of Contents"]') }
8
+ it { is_expected.to have_xpath('/div/div[@class="toc"]') }
10
9
 
11
10
  context 'without headings in the outline' do
12
- it { should_not have_xpath('//a') }
11
+ it { is_expected.not_to have_xpath('//a') }
13
12
  end
14
13
 
15
14
  context 'with heading in the outline' do
16
- let(:outline) { [['foo.html', [double('heading', :text => 'link', :html_id => 'bar', :level => 1)]]] }
17
- it { should have_xpath('/div/div/div[@class="level-1"]/a[@href="foo.html#bar"][text()="link"]') }
15
+ let(:outline) { [['foo.html', [double('heading 1', :text => 'link 1', :html_id => 'bar', :level => 1), double('heading 2', :text => 'link 2', :html_id => 'bar', :level => 2)]]] }
16
+ it { is_expected.to have_xpath('/div/div/div[@class="level-1"]/a[@href="foo.html#bar"][text()="link 1"]') }
17
+ it { is_expected.not_to have_xpath('/div/div/div[@class="level-1"]/a[@href="foo.html#bar"][text()="link 2"]') }
18
18
  end
19
19
  end
@@ -1,20 +1,18 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub::Epub::Toc do
4
2
  let(:chapters) { [] }
5
- let(:config) { {} }
6
- let(:book) { double('book', :uid => 'foo', :title => 'title', :chapters => chapters, :config => config) }
3
+ let(:config) { OpenStruct.new({ 'title' => 'title' }) }
4
+ let(:book) { double('book', :uid => 'foo', :chapters => chapters, :config => config) }
7
5
  let(:subject) { described_class.new(book).render }
8
6
 
9
- it { should have_xpath('/xmlns:ncx') }
10
- it { should have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:uid"][@content="foo"]') }
11
- it { should have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:depth"][@content="2"]') }
12
- it { should have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:totalPageCount"][@content="0"]') }
13
- it { should have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:maxPageNumber"][@content="0"]') }
14
- it { should have_xpath('/xmlns:ncx/xmlns:docTitle/xmlns:text[text()="title"]') }
7
+ it { is_expected.to have_xpath('/xmlns:ncx') }
8
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:uid"][@content="foo"]') }
9
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:depth"][@content="2"]') }
10
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:totalPageCount"][@content="0"]') }
11
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:head/xmlns:meta[@name="dtb:maxPageNumber"][@content="0"]') }
12
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:docTitle/xmlns:text[text()="title"]') }
15
13
 
16
14
  context 'without chapters' do
17
- it { should_not have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint') }
15
+ it { is_expected.not_to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint') }
18
16
  end
19
17
 
20
18
  context 'with chapters' do
@@ -22,19 +20,19 @@ describe Rpub::Epub::Toc do
22
20
  let(:heading2) { double('heading', :children => [], :value => double('value', :options => { :level => 2, :raw_text => 'chapter title 2' }), :attr => { :id => 'bar' }) }
23
21
  let(:toc) { double('toc', :children => [heading1])}
24
22
  let(:chapters) { [double('chapter', :title => 'chapter title', :filename => 'filename', :xml_id => 'id', :toc => toc)] }
25
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
26
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
27
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
28
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint[@id="bar"]') }
29
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title 2"]') }
30
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:content[@src="filename#bar"]') }
23
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
24
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
25
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
26
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint[@id="bar"]') }
27
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title 2"]') }
28
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint/xmlns:content[@src="filename#bar"]') }
31
29
 
32
30
  context 'with low max_level' do
33
- let(:config) { { :max_level => 1 } }
34
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
35
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
36
- it { should have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
37
- it { should_not have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint') }
31
+ let(:config) { OpenStruct.new({ 'title' => 'title', 'max_level' => 1 }) }
32
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint[@id="foo"]') }
33
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navLabel/xmlns:text[text()="chapter title"]') }
34
+ it { is_expected.to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:content[@src="filename#foo"]') }
35
+ it { is_expected.not_to have_xpath('/xmlns:ncx/xmlns:navMap/xmlns:navPoint/xmlns:navPoint') }
38
36
  end
39
37
  end
40
38
  end
@@ -1,7 +1,5 @@
1
- require 'spec_helper'
2
-
3
1
  describe Rpub do
4
2
  it 'should define a version number' do
5
- Rpub::VERSION.should =~ /\d+\.\d+\.\d+/
3
+ expect(Rpub::VERSION).to match(/\d+\.\d+\.\d+/)
6
4
  end
7
5
  end
@@ -3,11 +3,39 @@ if RUBY_VERSION >= '1.9' && ENV.has_key?('COVERAGE')
3
3
  SimpleCov.start
4
4
  end
5
5
 
6
+ if ENV.has_key?('TRAVIS')
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+ end
10
+
6
11
  require 'rpub'
7
12
  require 'nokogiri'
8
13
 
9
14
  FIXTURES_DIRECTORY = File.expand_path('../fixtures', __FILE__)
10
15
 
16
+ RSpec.configure do |config|
17
+ config.filter_run :focus
18
+ config.run_all_when_everything_filtered = true
19
+
20
+ if config.files_to_run.one?
21
+ config.default_formatter = 'doc'
22
+ else
23
+ config.profile_examples = 10
24
+ end
25
+
26
+ config.order = :random
27
+ Kernel.srand config.seed
28
+
29
+ config.expect_with :rspec do |expectations|
30
+ expectations.syntax = :expect
31
+ end
32
+
33
+ config.mock_with :rspec do |mocks|
34
+ mocks.syntax = :expect
35
+ mocks.verify_partial_doubles = true
36
+ end
37
+ end
38
+
11
39
  RSpec::Matchers.define :remove_file do |filename|
12
40
  match do |block|
13
41
  before = File.exist?(filename)