Skip to content

Commit

Permalink
Merge branch 'main' into less_noisy_fixtures_with_pathname
Browse files Browse the repository at this point in the history
  • Loading branch information
skoji authored Jul 31, 2024
2 parents 22a0717 + 0a2d5a3 commit 9fa8e5a
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 115 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
1 change: 0 additions & 1 deletion spec/bindings_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'rubygems'
require 'nokogiri'

Expand Down
1 change: 0 additions & 1 deletion spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'rubygems'
require 'nokogiri'

Expand Down
1 change: 0 additions & 1 deletion spec/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'rubygems'
describe GEPUB::Builder do
context 'metadata generating' do
Expand Down
40 changes: 16 additions & 24 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'rubygems'

describe 'GEPUB usage' do
context 'On using Builder' do
end

context 'On generating EPUB' do
before do
@tempdir = Dir.mktmpdir
end
context 'On generating EPUB', :uses_temporary_directory do

after do
FileUtils.remove_entry_secure @tempdir
end

it 'should generate simple EPUB3 with Builder and buffer' do
workdir = File.join(File.dirname(__FILE__), 'fixtures', 'testdata')
builder = GEPUB::Builder.new {
Expand All @@ -41,9 +33,9 @@
}
}
}
epubname = File.join(@tempdir, 'example_test_with_builder_buffer.epub')
File.open(epubname, 'wb') { |io| io.write builder.generate_epub_stream.string }
epubcheck(epubname)
epub_file = @temporary_directory / 'example_test_with_builder_buffer.epub'
epub_file.open('wb') { |io| io.write builder.generate_epub_stream.string }
epubcheck(epub_file)
end

it 'should generate simple EPUB3 with Builder' do
Expand Down Expand Up @@ -72,9 +64,9 @@
}
}
}
epubname = File.join(@tempdir, 'example_test_with_builder.epub')
builder.generate_epub(epubname)
epubcheck(epubname)
epub_file = @temporary_directory / 'example_test_with_builder.epub'
builder.generate_epub(epub_file)
epubcheck(epub_file)
end

it 'should generate simple EPUB3 with rather complicated matadata' do
Expand Down Expand Up @@ -114,9 +106,9 @@
book.add_item('text/chap1-1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>the second page</p></body></html>')) # do not appear on table of contents
book.add_item('text/chap2.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c3</title></head><body><p>the third page</p></body></html>')).toc_text('Chapter 2')
}
epubname = File.join(@tempdir, 'example_test.epub')
book.generate_epub(epubname)
epubcheck(epubname)
epub_file = @temporary_directory / 'example_test.epub'
book.generate_epub(epub_file)
epubcheck(epub_file)
end

it 'should generate simple EPUB3 with some nil metadata' do
Expand All @@ -132,9 +124,9 @@
item.add_content StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>')
end

epubname = File.join(@tempdir, 'example_test.epub')
book.generate_epub(epubname)
epubcheck(epubname)
epub_file = @temporary_directory / 'example_test.epub'
book.generate_epub(epub_file)
epubcheck(epub_file)
end

it 'should generate simple EPUB3 with landmarks' do
Expand Down Expand Up @@ -175,7 +167,7 @@
book.add_item('text/chap1-1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>the second page</p></body></html>')) # do not appear on table of contents
book.add_item('text/chap2.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c3</title></head><body><p>the third page</p></body></html>')).toc_text('Chapter 2')
}
epubname = File.join(@tempdir, 'example_test.epub')
epub_file = @temporary_directory / 'example_test.epub'

# check nav doc
xml = Nokogiri::XML::Document.parse book.nav_doc
Expand All @@ -193,8 +185,8 @@
expect(landmarks[0]['href']).to eq 'text/cover.xhtml'
expect(landmarks[1]['epub:type']).to eq 'bodymatter'
expect(landmarks[1]['href']).to eq 'text/chap1.xhtml'
book.generate_epub(epubname)
epubcheck(epubname)
book.generate_epub(epub_file)
epubcheck(epub_file)
end
end
end
47 changes: 21 additions & 26 deletions spec/gepub_deprectad_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'rubygems'
require 'nokogiri'

Expand Down Expand Up @@ -75,11 +74,6 @@
</html>
EOF
item3 = @book.add_ordered_item('text/nav.xhtml', StringIO.new(nav_string), 'nav').add_property('nav')
@tempdir = Dir.mktmpdir
end

after do
FileUtils.remove_entry_secure @tempdir
end

it "should have title" do
Expand Down Expand Up @@ -159,22 +153,23 @@
expect(meta['content']).to eq(item.itemid)
end

it "should generate correct epub" do
epubname = File.join(@tempdir, 'testepub.epub')
@book.generate_epub(epubname)
epubcheck(epubname)
it "should generate correct epub", :uses_temporary_directory do
epub_file = @temporary_directory / 'testepub.epub'
@book.generate_epub(epub_file)
epubcheck(epub_file)
end
it "should generate correct epub with buffer" do
epubname = File.join(@tempdir, 'testepub_buf.epub')
File.open(epubname, 'wb') {

it "should generate correct epub with buffer", :uses_temporary_directory do
epub_file = @temporary_directory / 'testepub_buf.epub'
File.open(epub_file, 'wb') {
|io|
io.write @book.generate_epub_stream.string
}
epubcheck(epubname)
epubcheck(epub_file)
end

it "should generate correct epub2.0" do
epubname = File.join(@tempdir, 'testepub2.epub')
it "should generate correct epub2.0", :uses_temporary_directory do
epub_file = @temporary_directory / 'testepub2.epub'
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '2.0'} )
@book.title = 'thetitle'
@book.creator = "theauthor"
Expand All @@ -190,18 +185,18 @@
StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
'c2')
item2.toc_text 'test chapter'
@book.generate_epub(epubname)
epubcheck(epubname)
@book.generate_epub(epub_file)
epubcheck(epub_file)
end
it 'should generate epub with extra file' do
epubname = File.join(@tempdir, 'testepub3.epub')
it 'should generate epub with extra file', :uses_temporary_directory do
epub_file = @temporary_directory / 'testepub3.epub'
@book.add_optional_file('META-INF/foobar.xml', StringIO.new('<foo></foo>'))
@book.generate_epub(epubname)
epubcheck(epubname)
@book.generate_epub(epub_file)
epubcheck(epub_file)
end

it 'should generate valid EPUB when @toc is empty' do
epubname = File.join(@tempdir, 'testepub4.epub')
it 'should generate valid EPUB when @toc is empty', :uses_temporary_directory do
epub_file = @temporary_directory / 'testepub4.epub'
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '3.0'} )
@book.title = 'thetitle'
@book.creator = "theauthor"
Expand All @@ -216,8 +211,8 @@
item2 = @book.add_ordered_item('text/barbar.xhtml',
StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
'c2')
@book.generate_epub(epubname)
epubcheck(epubname)
@book.generate_epub(epub_file)
epubcheck(epub_file)

end
end
Loading

0 comments on commit 9fa8e5a

Please sign in to comment.