Skip to content

Commit 7377daa

Browse files
committed
Add file existence spec
1 parent 939678e commit 7377daa

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

spec/cson_generator_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'spec_helper'
22
require 'ever2boost/note'
33
require 'ever2boost/cson_generator'
4+
require 'fileutils'
45

56
describe Ever2boost::CsonGenerator do
67
let (:folder_hash) { '0123abcdef' }
@@ -9,6 +10,8 @@
910
let (:note) { Ever2boost::Note.new(title: title, content: content) }
1011
let (:md_note_content) { Ever2boost::MdConverter.convert(note.content) }
1112
let (:timestamp) { Ever2boost::CsonGenerator.timestamp }
13+
let (:output_dir) { 'spec/dist/evernote_storage' }
14+
let (:filename) { `ls spec/dist/evernote_storage/notes`.lines.first.chomp }
1215

1316
let (:cson) {
1417
<<-EOS
@@ -31,4 +34,16 @@
3134
expect(Ever2boost::CsonGenerator.build(folder_hash, note)).to eq(cson)
3235
end
3336
end
37+
38+
describe '#output' do
39+
around(:each) do |example|
40+
Ever2boost::CsonGenerator.output(folder_hash, note, output_dir)
41+
example.run
42+
FileUtils.rm_r(output_dir)
43+
end
44+
45+
it 'should create notes' do
46+
expect(File.exist?("#{output_dir}/notes#{filename}"))
47+
end
48+
end
3449
end

spec/enex_converter_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
let(:output_dir) { 'spec/dist/evernote_storage' }
77
let(:filename) { 'lorem' }
88
let(:cson_folder_hash) do
9+
# I use `ls` because the filename of cson is random.
910
cson_filename = `ls spec/dist/evernote_storage/notes`.lines.first.chomp
1011
File.read("#{output_dir}/notes/#{cson_filename}").lines[1].chomp.slice(/[a-f0-9]{12}/)
1112
end
@@ -15,11 +16,9 @@
1516
end
1617

1718
describe '#convert' do
18-
before do
19+
around(:each) do |example|
1920
Ever2boost::EnexConverter.convert(enex, output_dir, filename)
20-
end
21-
22-
after do
21+
example.run
2322
FileUtils.rm_r(output_dir)
2423
end
2524

spec/json_generator_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
require 'spec_helper'
2+
require 'fileutils'
23

34
describe Ever2boost::JsonGenerator do
45
let (:notelist1) { Ever2boost::NoteList.new(title: 'title1', guid: '012345abcdef')}
56
let (:notelist2) { Ever2boost::NoteList.new(title: 'title2', guid: '0123456abcde')}
67
let (:notebook_list) { [notelist1, notelist2] }
78
let (:json) { "{\"folders\":[{\"key\":\"012345abcdef\",\"name\":\"title1\",\"color\":\"#E10051\"},{\"key\":\"0123456abcde\",\"name\":\"title2\",\"color\":\"#E10051\"}],\"version\":\"1.0\"}" }
9+
let (:output_dir) { 'spec/dist/evernote_storage' }
810

911
describe '#build' do
1012
before do
@@ -18,4 +20,16 @@
1820
expect(Ever2boost::JsonGenerator.build(notebook_list)).to eq(json)
1921
end
2022
end
23+
24+
describe '#output' do
25+
around(:each) do |example|
26+
Ever2boost::JsonGenerator.output(notebook_list, output_dir)
27+
example.run
28+
FileUtils.rm_r(output_dir)
29+
end
30+
31+
it 'should create boostnote.json' do
32+
expect(File.exist?("#{output_dir}/boostnote.json")).to be_truthy
33+
end
34+
end
2135
end

0 commit comments

Comments
 (0)