Skip to content

Commit

Permalink
revert spec; should pass all existing spec for the present.
Browse files Browse the repository at this point in the history
  • Loading branch information
skoji committed Jun 12, 2018
1 parent 749440c commit d9b72a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
it 'returns main title' do
book = GEPUB::Book.new()
book.add_title 'sub title'
book.add_title('the main title', title_type: GEPUB::TITLE_TYPE::MAIN)
book.add_title('the main title', nil, GEPUB::TITLE_TYPE::MAIN)
expect(book.title.to_s).to eq('the main title')
end
end
Expand All @@ -136,7 +136,7 @@
it 'returns titles in defined order' do
book = GEPUB::Book.new()
book.add_title 'sub title'
book.add_title('the main title', title_type: GEPUB::TITLE_TYPE::MAIN)
book.add_title('the main title', nil, GEPUB::TITLE_TYPE::MAIN)
expect(book.title_list[0].to_s).to eq('sub title')
expect(book.title_list[1].to_s).to eq('the main title')
end
Expand Down
10 changes: 4 additions & 6 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
book.language = 'ja'

# you can add metadata and its property using block
book.add_title('GEPUBサンプル文書', title_type: GEPUB::TITLE_TYPE::MAIN) {
book.add_title('GEPUBサンプル文書', nil, GEPUB::TITLE_TYPE::MAIN) {
|title|
title.lang = 'ja'
title.file_as = 'GEPUB Sample Book'
Expand All @@ -86,7 +86,7 @@
'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)')
}
# you can do the same thing using method chain
book.add_title('これはあくまでサンプルです', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'this book is just a sample.')
book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'this book is just a sample.')
book.add_creator('小嶋智') {
|creator|
creator.display_seq = 1
Expand All @@ -98,15 +98,13 @@
book.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')

imgfile = File.join(File.dirname(__FILE__), 'fixtures', 'testdata', 'image1.jpg')
book.add_item('img/image1.jpg',content: imgfile).cover_image
book.add_item('img/image1.jpg',imgfile).cover_image

# within ordered block, add_item will be added to spine.
book.ordered {
book.add_item('text/chap1.xhtml').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>')).toc_text('Chapter 1')
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',
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')
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')
book.generate_epub(epubname)
Expand Down
28 changes: 13 additions & 15 deletions spec/gepub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@
@book.date = "2010-05-05"
@book.identifier = "http://example.jp/foobar/"
@book.language = 'ja'
item1 = @book.add_item('text/foobar.xhtml', id: 'c1')
item1 = @book.add_item('text/foobar.xhtml',nil, 'c1')
item1.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>'))
@book.spine.push(item1)

item2 = @book.add_ordered_item('text/barbar.xhtml',
id: 'c2',
content: 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>'),
toc_text: 'test chapter'
)
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'

item3 = @book.add_item('text/handler.xhtml',
content: StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title><script>alert("foo");</script></head><body><p>this is scripted item</p></body></html>')
StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title><script>alert("foo");</script></head><body><p>this is scripted item</p></body></html>')
)
item3.add_property('scripted')
item3.is_handler_of('application/x-some-media-type')
Expand All @@ -79,7 +78,7 @@
</body>
</html>
EOF
item3 = @book.add_ordered_item('text/nav.xhtml', id: 'nav', content: StringIO.new(nav_string)).add_property('nav')
item3 = @book.add_ordered_item('text/nav.xhtml', StringIO.new(nav_string), 'nav').add_property('nav')
end

it "should have titile" do
Expand Down Expand Up @@ -190,13 +189,13 @@
@book.date = "2010-05-05"
@book.identifier = "http://example.jp/foobar/"
@book.language = 'ja'
item1 = @book.add_item('text/foobar.xhtml', id: 'c1')
item1 = @book.add_item('text/foobar.xhtml',nil, 'c1')
item1.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>'))
@book.spine.push(item1)
item2 = @book.add_ordered_item('text/barbar.xhtml',
id: 'c2',
content: 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>'),
toc_text: 'test chapter')
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)
end
Expand All @@ -217,13 +216,12 @@
@book.date = "2015-05-05"
@book.identifier = "http://example.jp/foobar/"
@book.language = 'ja'
item1 = @book.add_item('text/foobar.xhtml', id: 'c1')
item1 = @book.add_item('text/foobar.xhtml',nil, 'c1')
item1.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>'))
@book.spine.push(item1)
item2 = @book.add_ordered_item('text/barbar.xhtml',
id: 'c2',
content: 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>')
)
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)

Expand Down
14 changes: 7 additions & 7 deletions spec/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@

it 'should write and read title with type' do
metadata = GEPUB::Metadata.new
metadata.add_title('The Main Title', id: 'maintitle', title_type: GEPUB::TITLE_TYPE::MAIN)
metadata.add_title('The Main Title', 'maintitle', GEPUB::TITLE_TYPE::MAIN)
expect(metadata.title.to_s).to eq('The Main Title')
expect(metadata.title.title_type.to_s).to eq('main')
end

it 'should write and read multipletitle with type' do
metadata = GEPUB::Metadata.new
metadata.add_title('The Main Title', id: 'maintitle', title_type: GEPUB::TITLE_TYPE::MAIN)
metadata.add_title('The Book Series', id: 'series', title_type: GEPUB::TITLE_TYPE::COLLECTION).group_position(1)
metadata.add_title('The Main Title', 'maintitle', GEPUB::TITLE_TYPE::MAIN)
metadata.add_title('The Book Series', 'series', GEPUB::TITLE_TYPE::COLLECTION).group_position(1)
expect(metadata.title.to_s).to eq('The Main Title')
expect(metadata.title.title_type.to_s).to eq('main')

Expand Down Expand Up @@ -132,7 +132,7 @@
it 'should detect duplicate id' do
metadata = GEPUB::Metadata.new
metadata.add_creator('TheCreator', 'id', 'aut')
expect { metadata.add_title('TheTitle', id: 'id') }.to raise_error(RuntimeError, "id 'id' is already in use.")
expect { metadata.add_title('TheTitle', 'id') }.to raise_error(RuntimeError, "id 'id' is already in use.")
end

it 'should generate empty metadata xml' do
Expand All @@ -149,7 +149,7 @@
it 'should handle date with Time object' do
metadata = GEPUB::Metadata.new
a = Time.parse '2012-02-27 20:00:00 UTC'
metadata.add_date(a, id: 'date')
metadata.add_date(a, 'date')
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
end

Expand All @@ -163,14 +163,14 @@
it 'should handle date with Time object by content = ' do
metadata = GEPUB::Metadata.new
a = Time.parse '2012-02-27 20:00:00 UTC'
metadata.add_date('2011-01-01', id: 'date')
metadata.add_date('2011-01-01', 'date')
metadata.date.content = a
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
end

it 'should handle date with a not W3C-DTF string' do
metadata = GEPUB::Metadata.new
metadata.add_date('2012-02-28 05:00:00 +0900', id: 'date')
metadata.add_date('2012-02-28 05:00:00 +0900', 'date')
expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
end

Expand Down
8 changes: 4 additions & 4 deletions spec/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
package['xml:lang'] = 'ja'

# metadata add: style 1
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
package.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) {
|title|
title.display_seq = 1
title.file_as = 'Sample EPUB3'
Expand All @@ -53,7 +53,7 @@
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
}
# metadata add: style2
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
package.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
Expand Down Expand Up @@ -117,7 +117,7 @@
package['xml:lang'] = 'ja'

# metadata add: style 1
package.metadata.add_title('EPUB3 Sample', title_type: GEPUB::TITLE_TYPE::MAIN) {
package.metadata.add_title('EPUB3 Sample', nil, GEPUB::TITLE_TYPE::MAIN) {
|title|
title.display_seq = 1
title.file_as = 'Sample EPUB3'
Expand All @@ -127,7 +127,7 @@
'th' => 'EPUB3 ตัวอย่าง (ญี่ปุ่น)')
}
# metadata add: style2
package.metadata.add_title('これでEPUB3もばっちり', title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
package.metadata.add_title('これでEPUB3もばっちり', nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'you need nothing but this book!')
package.metadata.add_creator('小嶋智').display_seq(1).add_alternates('en' => 'KOJIMA Satoshi')
package.metadata.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
package.metadata.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
Expand Down

0 comments on commit d9b72a3

Please sign in to comment.