/
maker_spec.rb
126 lines (119 loc) · 4.29 KB
/
maker_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "EeePub::Maker" do
before do
@maker = EeePub::Maker.new do
title 'sample'
creator 'jugyo'
publisher 'jugyo.org'
date "2010-05-06"
language 'en'
subject 'epub sample'
description 'this is epub sample'
rights 'xxx'
relation 'xxx'
identifier 'http://example.com/book/foo', :scheme => 'URL'
uid 'http://example.com/book/foo'
ncx_file 'toc.ncx'
opf_file 'content.opf'
files ['foo.html', 'bar.html']
nav [
{:label => '1. foo', :content => 'foo.html'},
{:label => '1. bar', :content => 'bar.html'}
]
end
end
it { @maker.instance_variable_get(:@titles).should == ['sample'] }
it { @maker.instance_variable_get(:@creators).should == ['jugyo'] }
it { @maker.instance_variable_get(:@publishers).should == ['jugyo.org'] }
it { @maker.instance_variable_get(:@dates).should == ["2010-05-06"] }
it { @maker.instance_variable_get(:@identifiers).should == [{:value => 'http://example.com/book/foo', :scheme => 'URL', :id => nil}] }
it { @maker.instance_variable_get(:@uid).should == 'http://example.com/book/foo' }
it { @maker.instance_variable_get(:@ncx_file).should == 'toc.ncx' }
it { @maker.instance_variable_get(:@opf_file).should == 'content.opf' }
it { @maker.instance_variable_get(:@files).should == ['foo.html', 'bar.html'] }
it {
@maker.instance_variable_get(:@nav).should == [
{:label => '1. foo', :content => 'foo.html'},
{:label => '1. bar', :content => 'bar.html'}
]
}
it 'should save' do
stub(FileUtils).cp.with_any_args
mock(Dir).mktmpdir { '/tmp' }
mock(EeePub::NCX).new(
:title => "sample",
:nav => [
{:label => '1. foo', :content => 'foo.html'},
{:label => '1. bar', :content => 'bar.html'}
],
:uid=>{:value=>"http://example.com/book/foo", :scheme=>"URL", :id=>"http://example.com/book/foo"}
) { stub!.save }
mock(EeePub::OPF).new(
:title => ["sample"],
:creator => ["jugyo"],
:date => ["2010-05-06"],
:language => ['en'],
:subject => ['epub sample'],
:description => ['this is epub sample'],
:rights => ['xxx'],
:relation => ['xxx'],
:ncx => "toc.ncx",
:publisher => ["jugyo.org"],
:unique_identifier=>"http://example.com/book/foo",
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id => "http://example.com/book/foo"}],
:manifest => ['foo.html', 'bar.html']
) { stub!.save }
mock(EeePub::OCF).new(
:container => "content.opf",
:dir => '/tmp'
) { stub!.save }
@maker.save('test.epub')
end
describe "files as hash" do
before do
@maker = EeePub::Maker.new do
title 'sample'
creator 'jugyo'
publisher 'jugyo.org'
date "2010-05-06"
language 'en'
subject 'epub sample'
description 'this is epub sample'
rights 'xxx'
relation 'xxx'
identifier 'http://example.com/book/foo', :scheme => 'URL'
uid 'http://example.com/book/foo'
ncx_file 'toc.ncx'
opf_file 'content.opf'
files [{'foo.html' => 'foo/bar'}, {'bar.html' => 'foo/bar/baz'}]
nav [
{:label => '1. foo', :content => 'foo.html'},
{:label => '1. bar', :content => 'bar.html'}
]
end
end
it 'should save' do
stub(FileUtils).cp.with_any_args
stub(FileUtils).mkdir_p.with_any_args
mock(Dir).mktmpdir { '/tmp' }
mock(EeePub::NCX).new.with_any_args { stub!.save }
mock(EeePub::OPF).new(
:title => ["sample"],
:creator => ["jugyo"],
:date => ["2010-05-06"],
:language => ['en'],
:subject => ['epub sample'],
:description => ['this is epub sample'],
:rights => ['xxx'],
:relation => ['xxx'],
:ncx => "toc.ncx",
:publisher => ["jugyo.org"],
:unique_identifier=>"http://example.com/book/foo",
:identifier => [{:value => "http://example.com/book/foo", :scheme => "URL", :id=>"http://example.com/book/foo"}],
:manifest => ["foo/bar/foo.html", "foo/bar/baz/bar.html"]
) { stub!.save }
mock(EeePub::OCF).new.with_any_args { stub!.save }
@maker.save('test.epub')
end
end
end