klipbook 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Klipbook::Sources::KindleDevice::EntryParser do
3
+ RSpec.describe Klipbook::Sources::KindleDevice::EntryParser do
4
4
 
5
5
  describe '#build_entry' do
6
6
  subject { Klipbook::Sources::KindleDevice::EntryParser.new.build_entry(entry_text) }
@@ -8,7 +8,9 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
8
8
  context 'passed an empty entry' do
9
9
  let(:entry_text) { " " }
10
10
 
11
- it { should be_nil }
11
+ it 'returns nil' do
12
+ expect(subject).to be_nil
13
+ end
12
14
  end
13
15
 
14
16
  context 'passed an incomplete entry' do
@@ -16,7 +18,9 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
16
18
  "Not long enough"
17
19
  end
18
20
 
19
- it { should be_nil }
21
+ it 'returns nil' do
22
+ expect(subject).to be_nil
23
+ end
20
24
  end
21
25
 
22
26
  context 'passed an entry with the title line "Book title (Author\'s Name)"' do
@@ -27,9 +31,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
27
31
  "Highlight text\n"
28
32
  end
29
33
 
30
- its(:title) { should == 'Book title' }
34
+ it 'extracts the title' do
35
+ expect(subject.title).to eq 'Book title'
36
+ end
31
37
 
32
- its(:author) { should == "Author's Name" }
38
+ it 'extracts the author' do
39
+ expect(subject.author).to eq "Author's Name"
40
+ end
33
41
  end
34
42
 
35
43
  context 'passed an entry with the title line "Book title (sub title) (Author\'s Name)"' do
@@ -40,9 +48,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
40
48
  "Highlight text\n"
41
49
  end
42
50
 
43
- its(:title) { should == 'Book title (sub title)' }
51
+ it 'extracts the title containing parens' do
52
+ expect(subject.title).to eq 'Book title (sub title)'
53
+ end
44
54
 
45
- its(:author) { should == "Author's Name" }
55
+ it 'extracts the author' do
56
+ expect(subject.author).to eq "Author's Name"
57
+ end
46
58
  end
47
59
 
48
60
  context 'passed an entry with the title line "Book title"' do
@@ -53,9 +65,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
53
65
  "Highlight text\n"
54
66
  end
55
67
 
56
- its(:title) { should == 'Book title' }
68
+ it 'extracts the title' do
69
+ expect(subject.title).to eq 'Book title'
70
+ end
57
71
 
58
- its (:author) { should be_nil }
72
+ it 'sets author to nil' do
73
+ expect(subject.author).to be_nil
74
+ end
59
75
  end
60
76
 
61
77
  context 'passed an entry that is a highlight' do
@@ -67,10 +83,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
67
83
  "The second line of the highlight"
68
84
  end
69
85
 
70
- its(:type) { should == :highlight }
86
+ it 'returns a highlight' do
87
+ expect(subject.type).to eq :highlight
88
+ end
71
89
 
72
90
  it 'extracts the highlighted text' do
73
- subject.text.should == "The first line of the highlight\nThe second line of the highlight"
91
+ expect(subject.text).to eq "The first line of the highlight\nThe second line of the highlight"
74
92
  end
75
93
  end
76
94
 
@@ -83,10 +101,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
83
101
  "The second line of the highlight"
84
102
  end
85
103
 
86
- its(:type) { should == :highlight }
104
+ it 'returns a highlight' do
105
+ expect(subject.type).to eq :highlight
106
+ end
87
107
 
88
108
  it 'extracts the highlighted text' do
89
- subject.text.should == "The first line of the highlight\nThe second line of the highlight"
109
+ expect(subject.text).to eq "The first line of the highlight\nThe second line of the highlight"
90
110
  end
91
111
  end
92
112
 
@@ -98,10 +118,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
98
118
  "The note text"
99
119
  end
100
120
 
101
- its(:type) { should == :note }
121
+ it 'returns a note' do
122
+ expect(subject.type).to eq :note
123
+ end
102
124
 
103
125
  it 'extracts the note text' do
104
- subject.text.should == "The note text"
126
+ expect(subject.text).to eq "The note text"
105
127
  end
106
128
  end
107
129
 
@@ -113,10 +135,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
113
135
  "The note text"
114
136
  end
115
137
 
116
- its(:type) { should == :note }
138
+ it 'returns a note' do
139
+ expect(subject.type).to eq :note
140
+ end
117
141
 
118
142
  it 'extracts the note text' do
119
- subject.text.should == "The note text"
143
+ expect(subject.text).to eq "The note text"
120
144
  end
121
145
  end
122
146
 
@@ -128,9 +152,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
128
152
  "\n"
129
153
  end
130
154
 
131
- its(:type) { should == :bookmark }
155
+ it 'returns a bookmark' do
156
+ expect(subject.type).to eq :bookmark
157
+ end
132
158
 
133
- its(:text) { should == '' }
159
+ it 'extracts empty text' do
160
+ expect(subject.text).to eq ""
161
+ end
134
162
  end
135
163
 
136
164
  context 'passed an entry with a 4th-generation bookmark' do
@@ -141,9 +169,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
141
169
  "\n"
142
170
  end
143
171
 
144
- its(:type) { should == :bookmark }
172
+ it 'returns a bookmark' do
173
+ expect(subject.type).to eq :bookmark
174
+ end
145
175
 
146
- its(:text) { should == '' }
176
+ it 'extracts empty text' do
177
+ expect(subject.text).to eq ""
178
+ end
147
179
  end
148
180
 
149
181
  context 'passed an entry with a single location value' do
@@ -155,9 +187,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
155
187
  "The second line of the highlight"
156
188
  end
157
189
 
158
- its(:location) { should == 465 }
190
+ it 'returns the correct location' do
191
+ expect(subject.location).to eq 465
192
+ end
159
193
 
160
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
194
+ it 'returns the correct added date' do
195
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
196
+ end
161
197
  end
162
198
 
163
199
  context 'passed a 4th-generation entry with a single location value' do
@@ -169,9 +205,13 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
169
205
  "The second line of the highlight"
170
206
  end
171
207
 
172
- its(:location) { should == 465 }
208
+ it 'returns the correct location' do
209
+ expect(subject.location).to eq 465
210
+ end
173
211
 
174
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
212
+ it 'returns the correct added date' do
213
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
214
+ end
175
215
  end
176
216
 
177
217
  context 'passed an entry with a location range' do
@@ -184,10 +224,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
184
224
  end
185
225
 
186
226
  it 'extracts the first element of the location range' do
187
- subject.location.should == 466
227
+ expect(subject.location).to eq 466
188
228
  end
189
229
 
190
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
230
+ it 'returns the correct added date' do
231
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
232
+ end
191
233
  end
192
234
 
193
235
  context 'passed a 4th-generation entry with a location range' do
@@ -200,10 +242,12 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
200
242
  end
201
243
 
202
244
  it 'extracts the first element of the location range' do
203
- subject.location.should == 466
245
+ expect(subject.location).to eq 466
204
246
  end
205
247
 
206
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
248
+ it 'returns the correct added date' do
249
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
250
+ end
207
251
  end
208
252
 
209
253
  context 'passed an entry with a page number and location range' do
@@ -216,12 +260,16 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
216
260
  end
217
261
 
218
262
  it 'extracts the first element of the location range' do
219
- subject.location.should == 1858
263
+ expect(subject.location).to eq 1858
220
264
  end
221
265
 
222
- its(:page) { should == 171 }
266
+ it 'extracts the page number' do
267
+ expect(subject.page).to eq 171
268
+ end
223
269
 
224
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
270
+ it 'returns the correct added date' do
271
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
272
+ end
225
273
  end
226
274
 
227
275
  context 'passed a 4th-generation entry with a page number and location range' do
@@ -234,12 +282,16 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
234
282
  end
235
283
 
236
284
  it 'extracts the first element of the location range' do
237
- subject.location.should == 1858
285
+ expect(subject.location).to eq 1858
238
286
  end
239
287
 
240
- its(:page) { should == 171 }
288
+ it 'extracts the page number' do
289
+ expect(subject.page).to eq 171
290
+ end
241
291
 
242
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
292
+ it 'returns the correct added date' do
293
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
294
+ end
243
295
  end
244
296
 
245
297
  context 'passed an entry with a page number and no location' do
@@ -250,11 +302,17 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
250
302
  "Clipping"
251
303
  end
252
304
 
253
- its(:location) { should == 0 }
305
+ it 'sets location to 0' do
306
+ expect(subject.location).to eq 0
307
+ end
254
308
 
255
- its(:page) { should == 9 }
309
+ it 'extracts the page number' do
310
+ expect(subject.page).to eq 9
311
+ end
256
312
 
257
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
313
+ it 'returns the correct added date' do
314
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
315
+ end
258
316
  end
259
317
 
260
318
  context 'passed a 4th-generation entry with a page number and no location' do
@@ -265,11 +323,17 @@ describe Klipbook::Sources::KindleDevice::EntryParser do
265
323
  "Clipping"
266
324
  end
267
325
 
268
- its(:location) { should == 0 }
326
+ it 'sets location to 0' do
327
+ expect(subject.location).to eq 0
328
+ end
269
329
 
270
- its(:page) { should == 9 }
330
+ it 'extracts the page number' do
331
+ expect(subject.page).to eq 9
332
+ end
271
333
 
272
- its(:added_on) { should == DateTime.parse('Thursday, April 21, 2011, 07:31 AM') }
334
+ it 'returns the correct added date' do
335
+ expect(subject.added_on).to eq DateTime.parse('Thursday, April 21, 2011, 07:31 AM')
336
+ end
273
337
  end
274
338
  end
275
339
  end
@@ -2,14 +2,12 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Klipbook::Sources::KindleDevice::FileParser do
5
+ RSpec.describe Klipbook::Sources::KindleDevice::FileParser do
6
6
 
7
7
  let(:parser) { Klipbook::Sources::KindleDevice::FileParser.new(entry_parser) }
8
8
 
9
9
  let(:entry_parser) do
10
- mock_parser = Object.new
11
- stub(mock_parser).build_entry
12
- mock_parser
10
+ double('parser', build_entry: nil)
13
11
  end
14
12
 
15
13
  describe '#extract_entries' do
@@ -19,7 +17,9 @@ describe Klipbook::Sources::KindleDevice::FileParser do
19
17
 
20
18
  let(:raw_text) { '' }
21
19
 
22
- it { should be_empty }
20
+ it 'return an empty set of entries' do
21
+ expect(subject).to be_empty
22
+ end
23
23
  end
24
24
 
25
25
  context 'called with text containing two entries' do
@@ -34,10 +34,10 @@ describe Klipbook::Sources::KindleDevice::FileParser do
34
34
  entry_one = Object.new
35
35
  entry_two = Object.new
36
36
 
37
- stub(entry_parser).build_entry(' entry one') { entry_one }
38
- stub(entry_parser).build_entry(' entry two') { entry_two }
37
+ allow(entry_parser).to receive(:build_entry).with(' entry one') { entry_one }
38
+ allow(entry_parser).to receive(:build_entry).with(' entry two') { entry_two }
39
39
 
40
- subject.should == [ entry_one, entry_two ]
40
+ expect(subject).to eq [ entry_one, entry_two ]
41
41
  end
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ describe Klipbook::Sources::KindleDevice::FileParser do
49
49
 
50
50
  it 'strips carriage returns before calling the entry parser' do
51
51
  subject
52
- entry_parser.should have_received.build_entry('Example text')
52
+ expect(entry_parser).to have_received(:build_entry).with('Example text')
53
53
  end
54
54
  end
55
55
 
@@ -61,7 +61,7 @@ describe Klipbook::Sources::KindleDevice::FileParser do
61
61
 
62
62
  it 'strips control characters before calling the entry parser' do
63
63
  subject
64
- entry_parser.should have_received.build_entry('Example text')
64
+ expect(entry_parser).to have_received(:build_entry).with('Example text')
65
65
  end
66
66
  end
67
67
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Klipbook::Sources::KindleDevice::File do
3
+ RSpec.describe Klipbook::Sources::KindleDevice::File do
4
4
 
5
5
  let(:file) { Klipbook::Sources::KindleDevice::File.new(input_file, max_books, file_parser) }
6
6
 
@@ -8,24 +8,16 @@ describe Klipbook::Sources::KindleDevice::File do
8
8
 
9
9
  let(:entries) { [] }
10
10
 
11
- let(:file_parser) do
12
- Object.new.tap do |fake_parser|
13
- stub(fake_parser).extract_entries { entries }
14
- end
15
- end
11
+ let(:file_parser) { double(extract_entries: entries) }
16
12
 
17
- let(:input_file) do
18
- Object.new.tap do |fake_file|
19
- stub(fake_file).read { 'file text' }
20
- end
21
- end
13
+ let(:input_file) { double(read: 'file text') }
22
14
 
23
15
  describe '#books' do
24
16
  subject { file.books }
25
17
 
26
18
  it 'parses the file text with the file parser' do
27
19
  subject
28
- file_parser.should have_received.extract_entries('file text')
20
+ expect(file_parser).to have_received(:extract_entries).with('file text')
29
21
  end
30
22
 
31
23
  context 'with entries for three books' do
@@ -59,11 +51,11 @@ describe Klipbook::Sources::KindleDevice::File do
59
51
  end
60
52
 
61
53
  it 'returns three books' do
62
- subject.should have(3).items
54
+ expect(subject.size).to eq 3
63
55
  end
64
56
 
65
57
  it 'returns books sorted by last_update descending' do
66
- subject.map(&:title).should == [ 'Book two', 'Book three', 'Book one' ]
58
+ expect(subject.map(&:title)).to eq [ 'Book two', 'Book three', 'Book one' ]
67
59
  end
68
60
 
69
61
  context 'and max_books set to 2' do
@@ -71,7 +63,7 @@ describe Klipbook::Sources::KindleDevice::File do
71
63
  let (:max_books) { 2 }
72
64
 
73
65
  it 'returns two books' do
74
- subject.should have(2).items
66
+ expect(subject.size).to eq 2
75
67
  end
76
68
  end
77
69
  end
@@ -119,23 +111,23 @@ describe Klipbook::Sources::KindleDevice::File do
119
111
  end
120
112
 
121
113
  it 'returns a single book with the correct title and author information' do
122
- subject.first.title.should == 'Book one'
123
- subject.first.author.should == 'Author one'
114
+ expect(subject.first.title).to eq 'Book one'
115
+ expect(subject.first.author).to eq 'Author one'
124
116
  end
125
117
 
126
118
  it "returns a single book with last update equal to the latest added on date of the book's entries" do
127
- subject.first.last_update.should == DateTime.new(2012, 10, 21)
119
+ expect(subject.first.last_update).to eq DateTime.new(2012, 10, 21)
128
120
  end
129
121
 
130
122
  it "ignores bookmarks when building the book's clipping list" do
131
- subject.first.clippings.should have(3).items
132
- subject.first.clippings.map(&:type).should_not include(:bookmark)
123
+ expect(subject.first.clippings.size).to eq 3
124
+ expect(subject.first.clippings.map(&:type)).not_to include(:bookmark)
133
125
  end
134
126
 
135
127
  it 'returns a single book whose clippings are sorted by location' do
136
- subject.first.clippings.map(&:location).should == [2, 3, 10]
137
- subject.first.clippings.map(&:text).should == ['Fourth one', 'Third one', 'Second one']
138
- subject.first.clippings.map(&:page).should == [1, 2, 3]
128
+ expect(subject.first.clippings.map(&:location)).to eq [2, 3, 10]
129
+ expect(subject.first.clippings.map(&:text)).to eq ['Fourth one', 'Third one', 'Second one']
130
+ expect(subject.first.clippings.map(&:page)).to eq [1, 2, 3]
139
131
  end
140
132
  end
141
133
 
@@ -163,7 +155,9 @@ describe Klipbook::Sources::KindleDevice::File do
163
155
  ]
164
156
  end
165
157
 
166
- it { should be_empty }
158
+ it 'should be empty' do
159
+ expect(subject).to be_empty
160
+ end
167
161
  end
168
162
  end
169
163
  end
@@ -22,9 +22,7 @@ describe Klipbook::ToHtml::HtmlPrinter do
22
22
  end
23
23
 
24
24
  let(:message_stream) do
25
- Object.new.tap do |fake_stream|
26
- stub(fake_stream).puts
27
- end
25
+ double(puts: nil)
28
26
  end
29
27
 
30
28
  describe '#print_to_file' do
@@ -43,12 +41,12 @@ describe Klipbook::ToHtml::HtmlPrinter do
43
41
 
44
42
  it 'writes a file named after the book into the output directory' do
45
43
  subject
46
- File.exists?(expected_filepath).should be_true
44
+ expect(File.exists?(expected_filepath)).to be_truthy
47
45
  end
48
46
 
49
47
  it 'writes a html summary to the file' do
50
48
  subject
51
- File.read(expected_filepath).should include("<h1>Fake book title</h1>")
49
+ expect(File.read(expected_filepath)).to include("<h1>Fake book title</h1>")
52
50
  end
53
51
  end
54
52
 
@@ -63,12 +61,12 @@ describe Klipbook::ToHtml::HtmlPrinter do
63
61
 
64
62
  it "won't write to the file" do
65
63
  subject
66
- File.size(expected_filepath).should == 0
64
+ expect(File.size(expected_filepath)).to eq 0
67
65
  end
68
66
 
69
67
  it 'prints a message informing that the file is being skipped' do
70
68
  subject
71
- message_stream.should have_received.puts("\e[33mSkipping \e[0m#{expected_filename}")
69
+ expect(message_stream).to have_received(:puts).with("\e[33mSkipping \e[0m#{expected_filename}")
72
70
  end
73
71
  end
74
72
 
@@ -77,12 +75,12 @@ describe Klipbook::ToHtml::HtmlPrinter do
77
75
 
78
76
  it 'overwrites the file' do
79
77
  subject
80
- File.size(expected_filepath).should > 0
78
+ expect(File.size(expected_filepath)).to be > 0
81
79
  end
82
80
 
83
81
  it 'prints a message informing that the file is being written' do
84
82
  subject
85
- message_stream.should have_received.puts("\e[32mWriting \e[0m#{expected_filename}")
83
+ expect(message_stream).to have_received(:puts).with("\e[32mWriting \e[0m#{expected_filename}")
86
84
  end
87
85
  end
88
86
  end
@@ -10,15 +10,15 @@ describe Klipbook::ToJson::BookFile do
10
10
 
11
11
  let(:json) { '' }
12
12
 
13
- its(:books) { should be_empty }
13
+ it 'returns an object with no books' do
14
+ expect(subject.books).to be_empty
15
+ end
14
16
  end
15
17
  end
16
18
 
17
19
  describe '#add_books' do
18
20
  let (:message_stream) do
19
- Object.new.tap do |fake_stream|
20
- stub(fake_stream).puts
21
- end
21
+ double(puts: nil)
22
22
  end
23
23
 
24
24
  let(:it) do
@@ -42,8 +42,9 @@ describe Klipbook::ToJson::BookFile do
42
42
  end
43
43
 
44
44
  it.add_books([ new_book ], false, message_stream)
45
- it.books.should have(3).items
46
- it.books.should include(new_book)
45
+
46
+ expect(it.books.size).to eq 3
47
+ expect(it.books).to include(new_book)
47
48
  end
48
49
 
49
50
  it "replaces books that exist if force is true" do
@@ -54,8 +55,9 @@ describe Klipbook::ToJson::BookFile do
54
55
  end
55
56
 
56
57
  it.add_books([ new_book ], true, message_stream)
57
- it.books.should have(2).items
58
- it.books.should include(new_book)
58
+
59
+ expect(it.books.size).to eq 2
60
+ expect(it.books).to include(new_book)
59
61
  end
60
62
 
61
63
  it "does not replace existing books if force is false" do
@@ -66,8 +68,9 @@ describe Klipbook::ToJson::BookFile do
66
68
  end
67
69
 
68
70
  it.add_books([ new_book ], false, message_stream)
69
- it.books.should have(2).items
70
- it.books.should_not include(new_book)
71
+
72
+ expect(it.books.size).to eq 2
73
+ expect(it.books).not_to include(new_book)
71
74
  end
72
75
  end
73
76
  end
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,6 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  require 'rspec'
5
- require 'rr'
6
-
7
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
5
 
9
6
  $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
10
7
  require 'klipbook'