Skip to content

Commit

Permalink
Merge pull request #140 from skoji/fix/gh-actions-windows-spec-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
skoji committed Apr 27, 2024
2 parents 96ba83c + 07e8d72 commit 8c9f437
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 231 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ jobs:
matrix:
ruby: [2.7, 3.0, 3.1, 3.2, 3.3, jruby]
platform: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- platform: windows-latest
runs-on: ${{ matrix.platform }}
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ rdoc
pkg

## PROJECT::SPECIFIC
testepub*.epub
example_test*.epub

## BUNDLER
Gemfile.lock
Expand Down
4 changes: 2 additions & 2 deletions lib/gepub/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def self.parse(io)
package = nil
package_path = nil
book = nil
Zip::File.open_buffer(io) {
Zip::File.open_buffer(io) do
|zip_file|
package, package_path = parse_container(zip_file, files)
check_consistency_of_package(package, package_path)
parse_files_into_package(files, package)
book = Book.new(package.path)
book.instance_eval { @package = package; @optional_files = files }
}
end
book
end

Expand Down
18 changes: 13 additions & 5 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
end

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

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 @@ -33,7 +41,7 @@
}
}
}
epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder_buffer.epub')
epubname = File.join(@tempdir, 'example_test_with_builder_buffer.epub')
File.open(epubname, 'wb') { |io| io.write builder.generate_epub_stream.string }
epubcheck(epubname)
end
Expand Down Expand Up @@ -64,7 +72,7 @@
}
}
}
epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder.epub')
epubname = File.join(@tempdir, 'example_test_with_builder.epub')
builder.generate_epub(epubname)
epubcheck(epubname)
end
Expand Down Expand Up @@ -106,7 +114,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(File.dirname(__FILE__), 'example_test.epub')
epubname = File.join(@tempdir, 'example_test.epub')
book.generate_epub(epubname)
epubcheck(epubname)
end
Expand All @@ -124,7 +132,7 @@
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(File.dirname(__FILE__), 'example_test.epub')
epubname = File.join(@tempdir, 'example_test.epub')
book.generate_epub(epubname)
epubcheck(epubname)
end
Expand Down Expand Up @@ -167,7 +175,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(File.dirname(__FILE__), 'example_test.epub')
epubname = File.join(@tempdir, 'example_test.epub')

# check nav doc
xml = Nokogiri::XML::Document.parse book.nav_doc
Expand Down
15 changes: 10 additions & 5 deletions spec/gepub_deprectad_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
</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 @@ -155,12 +160,12 @@
end

it "should generate correct epub" do
epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
epubname = File.join(@tempdir, 'testepub.epub')
@book.generate_epub(epubname)
epubcheck(epubname)
end
it "should generate correct epub with buffer" do
epubname = File.join(File.dirname(__FILE__), 'testepub_buf.epub')
epubname = File.join(@tempdir, 'testepub_buf.epub')
File.open(epubname, 'wb') {
|io|
io.write @book.generate_epub_stream.string
Expand All @@ -169,7 +174,7 @@
end

it "should generate correct epub2.0" do
epubname = File.join(File.dirname(__FILE__), 'testepub2.epub')
epubname = File.join(@tempdir, 'testepub2.epub')
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '2.0'} )
@book.title = 'thetitle'
@book.creator = "theauthor"
Expand All @@ -189,14 +194,14 @@
epubcheck(epubname)
end
it 'should generate epub with extra file' do
epubname = File.join(File.dirname(__FILE__), 'testepub3.epub')
epubname = File.join(@tempdir, 'testepub3.epub')
@book.add_optional_file('META-INF/foobar.xml', StringIO.new('<foo></foo>'))
@book.generate_epub(epubname)
epubcheck(epubname)
end

it 'should generate valid EPUB when @toc is empty' do
epubname = File.join(File.dirname(__FILE__), 'testepub4.epub')
epubname = File.join(@tempdir, 'testepub4.epub')
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '3.0'} )
@book.title = 'thetitle'
@book.creator = "theauthor"
Expand Down

0 comments on commit 8c9f437

Please sign in to comment.