Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access spec fixtures less noisy through Pathname #145

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/bindings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe GEPUB::Bindings do
context 'parse existing opf' do
before do
@bindings = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test_with_bindings.opf'), '/package.opf').instance_eval{ @bindings }
@bindings = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test_with_bindings.opf', '/package.opf').instance_eval{ @bindings }
end
it 'should be parsed' do
expect(@bindings.media_types.size).to eq(2)
Expand Down
16 changes: 8 additions & 8 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@
describe '.parse' do
context 'IO Object' do
it 'loads book and returns GEPUB::Book object' do
filehandle = File.new(File.dirname(__FILE__) + '/fixtures/testdata/wasteland-20120118.epub')
book = GEPUB::Book.parse(filehandle)
file = @fixtures_directory / 'testdata/wasteland-20120118.epub'
book = GEPUB::Book.parse(file)
expect(book).to be_instance_of GEPUB::Book
expect(book.items.size).to eq 6
expect(book.items['t1'].href).to eq 'wasteland-content.xhtml'
Expand All @@ -389,23 +389,23 @@
expect(book.spine_items[0].href).to eq 'wasteland-content.xhtml'
end
it 'loads non-latin EPUB as UTF-8' do
filehandle = File.new(File.dirname(__FILE__) + '/fixtures/testdata/lemon.epub')
book = GEPUB::Book.parse(filehandle)
file = @fixtures_directory / 'testdata/lemon.epub'
book = GEPUB::Book.parse(file)
expect(book.items['p-001'].href).to eq 'xhtml/p-001.xhtml'
expect(book.items['p-001'].content.encoding).to eq Encoding::UTF_8
end
it 'reads EPUB with streamed entries' do
filehandle = File.new(File.dirname(__FILE__) + '/fixtures/testdata/streamed_item.epub')
book = GEPUB::Book.parse(filehandle)
file = @fixtures_directory / 'testdata/streamed_item.epub'
book = GEPUB::Book.parse(file)
expect(book).to be_instance_of GEPUB::Book
expect(book.items.size).to eq 3
end
end

context 'file path' do
it 'loads book and returns GEPUB::Book object' do
filepath = File.join(File.dirname(__FILE__), 'fixtures', 'testdata', 'wasteland-20120118.epub')
book = GEPUB::Book.parse(filepath)
file = @fixtures_directory / 'testdata/wasteland-20120118.epub'
book = GEPUB::Book.parse(file)
expect(book).to be_instance_of GEPUB::Book
expect(book.items.size).to eq 6
end
Expand Down
11 changes: 4 additions & 7 deletions spec/gepub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,9 @@
end

it 'should generate parsed and generated EPUB with renewed lastmodified', :uses_temporary_directory do
originalfile = File.join(File.dirname(__FILE__), 'fixtures/testdata/wasteland-20120118.epub')
original_file = @fixtures_directory / 'testdata/wasteland-20120118.epub'
epub_file = @temporary_directory / 'testepub.epub'

original_book = File.open(originalfile) do |f|
original_book = File.open(original_file) do |f|
GEPUB::Book.parse(f)
end
original_lastmodified = original_book.lastmodified.content
Expand All @@ -252,13 +251,11 @@
end

it 'should generate parsed and generated EPUB with newly set lastmodified', :uses_temporary_directory do
originalfile = File.join(File.dirname(__FILE__), 'fixtures/testdata/wasteland-20120118.epub')
original_file = @fixtures_directory / 'testdata/wasteland-20120118.epub'
epub_file = @temporary_directory / 'testepub.epub'
mod_time = Time.mktime(2010,5,5,8,10,15)

original_book = File.open(originalfile) do |f|
GEPUB::Book.parse(f)
end
original_book = original_file.open {|f| GEPUB::Book.parse(f) }
original_book.lastmodified = mod_time
original_book.generate_epub(epub_file)
epub_file.open do |f|
Expand Down
2 changes: 1 addition & 1 deletion spec/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe GEPUB::Manifest do
context 'parse existing opf' do
before do
@manifest = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @manifest }
@manifest = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf').instance_eval{ @manifest }
end

it 'should be parsed' do
Expand Down
6 changes: 3 additions & 3 deletions spec/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

context 'Parse Existing OPF' do
before do
@metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @metadata }
@metadata = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf').instance_eval{ @metadata }
end
it 'should parse title' do
expect(@metadata.main_title).to eq('TheTitle')
Expand All @@ -25,7 +25,7 @@
end

it 'should parse main title with not first display-seq' do
metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test2.opf'), '/package.opf').instance_eval{ @metadata }
metadata = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test2.opf', '/package.opf').instance_eval{ @metadata }
expect(metadata.title.to_s).to eq('TheTitle')
end

Expand Down Expand Up @@ -55,7 +55,7 @@

context 'Should parse OPF2.0' do
before do
@metadata = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/package_2_0.opf'), '/package.opf').instance_eval{ @metadata }
@metadata = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/package_2_0.opf', '/package.opf').instance_eval{ @metadata }
end
it 'should parse title' do
expect(@metadata.main_title).to eq('thetitle')
Expand Down
6 changes: 3 additions & 3 deletions spec/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

context 'parse existing opf' do
it 'should be initialized with opf' do
opf = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
opf = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf')
expect(opf.ns_prefix(GEPUB::XMLUtil::OPF_NS)).to eq('xmlns')
expect(opf['version']).to eq('3.0')
expect(opf['unique-identifier']).to eq('pub-id')
expect(opf['xml:lang']).to eq('ja')
expect(opf['prefix']).to eq('foaf: http://xmlns.com/foaf/spec/ rendition: http://www.idpf.org/vocab/rendition/#')
end
it 'should parse prefix data' do
package = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
package = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf')
expect(package.prefixes.size).to eq(2)
expect(package.prefixes['foaf']).to eq('http://xmlns.com/foaf/spec/')
expect(package.prefixes['rendition']).to eq('http://www.idpf.org/vocab/rendition/#')

end

it 'should parse rendition metadata' do
package = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf')
package = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf')
expect(package.rendition_layout).to eq('pre-paginated')
expect(package.rendition_orientation).to eq('auto')
expect(package.rendition_spread).to eq('both')
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def epubcheck(epubname)
expect(stdout).to include("No errors or warnings detected.")
end

config.before(:all) do
@fixtures_directory = Pathname(__FILE__).dirname / "fixtures"
end

config.around(:example, :uses_temporary_directory) do |example|
@temporary_directory = Pathname(Dir.mktmpdir("gepub_spec"))
example.run
Expand Down
2 changes: 1 addition & 1 deletion spec/spine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe GEPUB::Spine do
context 'parse existing opf' do
before do
@spine = GEPUB::Package.parse_opf(File.open(File.dirname(__FILE__) + '/fixtures/testdata/test.opf'), '/package.opf').instance_eval{ @spine }
@spine = GEPUB::Package.parse_opf(@fixtures_directory / 'testdata/test.opf', '/package.opf').instance_eval{ @spine }
end
it 'should be parsed' do
expect(@spine.toc).to eq('ncx')
Expand Down