spec/alexandria/library_spec.rb in alexandria-book-collection-manager-0.7.5 vs spec/alexandria/library_spec.rb in alexandria-book-collection-manager-0.7.6
- old
+ new
@@ -76,14 +76,10 @@
before do
FileUtils.mkdir(TESTDIR) unless File.exist? TESTDIR
end
- after do
- FileUtils.rm_rf(TESTDIR)
- end
-
it "disallows multiple deletion of the same copy of a book" do
first_copy = an_artist_of_the_floating_world
my_library << first_copy
my_library.delete(first_copy)
expect { my_library.delete(first_copy) }.to raise_error ArgumentError
@@ -102,117 +98,133 @@
expect { my_library.delete(second_copy) }.not_to raise_error
end
end
describe ".import_as_isbn_list" do
- def __test_fake_import_isbns
+ before do
libraries = Alexandria::LibraryCollection.instance
- library = Alexandria::Library.new("Test Library")
+ library = described_class.new("Test Library")
libraries.add_library(library)
- [library, libraries]
+
+ allow(Alexandria::BookProviders)
+ .to receive(:isbn_search)
+ .and_raise Alexandria::BookProviders::SearchEmptyError
+ allow(Alexandria::BookProviders)
+ .to receive(:isbn_search).with("0595371086")
+ .and_return(an_artist_of_the_floating_world)
end
- it "doesn't work quite yet" do
- skip
- # Doesn't work quite yet.
- on_iterate_cb = proc {}
- on_error_cb = proc {}
- library, _libraries = __test_fake_import_isbns
- test_file = "data/isbns.txt"
- library.import_as_isbn_list("Test Library", test_file, on_iterate_cb, on_error_cb)
+ it "imports books with correct isbn and search result" do
+ library, bad_isbns, failed_lookup_isbns =
+ described_class.import_as_isbn_list("Test Library", "spec/data/isbns.txt",
+ proc {}, proc {})
+
+ aggregate_failures do
+ expect(library.to_a).to eq [an_artist_of_the_floating_world]
+ expect(bad_isbns).to eq ["0911826449"]
+ expect(failed_lookup_isbns).to eq ["0740704923"]
+ end
end
end
context "when importing from 0.6.1 data files" do
+ let(:libs) { loader.load_all_libraries }
+ let(:my_library) { libs[0] }
+
before do
lib_version = File.join(LIBDIR, "0.6.1")
FileUtils.cp_r(lib_version, TESTDIR)
end
- after do
- FileUtils.rm_rf(TESTDIR)
+ it "can be loaded" do
+ expect(libs.size).to eq(1)
+ expect(my_library.size).to eq(3)
end
it "imports cleanly from version 0.6.1 data format" do
- libs = loader.load_all_libraries
- expect(libs.size).to eq(1)
- my_library = libs[0]
- expect(my_library.size).to eq(3)
# Malory
- malory_book = my_library.select { |b| b.isbn == "9780192812179" }[0]
+ malory_book = my_library.find { |b| b.isbn == "9780192812179" }
expect(malory_book.publisher).to eq("Oxford University Press")
expect(malory_book.authors.include?("Vinaver")).to be_truthy
expect(malory_book.version).to eq(Alexandria::DATA_VERSION)
# Guide to LaTeX
- latex_book = my_library.select { |b| b.title.include? "Latex" }[0]
+ latex_book = my_library.find { |b| b.title.include? "Latex" }
expect(latex_book.isbn).to eq("9780201398250")
expect(latex_book.publisher).to eq("Addison Wesley") # note, no Ruby-Amazon cruft
end
end
context "when importing from 0.6.1 with books without an ISBN" do
+ let(:libs) { loader.load_all_libraries }
+ let(:my_library) { libs[0] }
+
before do
lib_version = File.join(LIBDIR, "0.6.1-noisbn")
FileUtils.cp_r(lib_version, TESTDIR)
end
after do
FileUtils.rm_rf(TESTDIR)
end
- it "allows books to have no ISBN" do
- libs = loader.load_all_libraries
+ it "can be loaded" do
expect(libs.size).to eq(1)
- my_library = libs[0]
expect(my_library.size).to eq(2)
+ end
+ it "loads a book with ISBN" do
# Guide to LaTeX
- latex_book = my_library.select { |b| b.title.include? "Latex" }[0]
+ latex_book = my_library.find { |b| b.title.include? "Latex" }
expect(latex_book.isbn).to eq("9780201398250")
expect(latex_book.publisher).to eq("Addison Wesley") # note, no Ruby-Amazon cruft
expect(latex_book.version).to eq(Alexandria::DATA_VERSION)
+ end
+ it "loads a book without ISBN" do
# Lex and Yacc
- lex_and_yacc_book = my_library.select { |b| b.title.include? "Lex" }[0]
+ lex_and_yacc_book = my_library.find { |b| b.title.include? "Lex" }
expect(lex_and_yacc_book.publisher).to eq("O'Reilley")
+ end
- my_library.each do |book|
- my_library.save(book, true)
- end
-
- libraries_reloaded = loader.load_all_libraries
- my_library_reloaded = libraries_reloaded[0]
-
+ it "saves loaded books properly" do
+ my_library.each { |book| my_library.save(book, true) }
+ my_library_reloaded = loader.load_all_libraries[0]
expect(my_library_reloaded.size).to eq(2)
- latex_book = my_library_reloaded.select { |b| b.title.include? "Latex" }[0]
- expect(latex_book).not_to be_nil
+ latex_book = my_library_reloaded.find { |b| b.title.include? "Latex" }
expect(latex_book.publisher).to eq("Addison Wesley")
- lex_and_yacc_book = my_library_reloaded.select { |b| b.title.include? "Lex" }[0]
- expect(lex_and_yacc_book).not_to be_nil
+ lex_and_yacc_book = my_library_reloaded.find { |b| b.title.include? "Lex" }
expect(lex_and_yacc_book.publisher).to eq("O'Reilley")
end
end
describe ".move" do
+ let(:source) { loader.load_library("My Library") }
+ let(:target) { loader.load_library("Target") }
+ let(:book) { source.first }
+
before do
lib_version = File.join(LIBDIR, "0.6.2")
FileUtils.cp_r(lib_version, TESTDIR)
end
- it "moves the given book from source to target" do
- source = loader.load_library("My Library")
+ it "changes the number of books in the source and target libraries" do
count = source.count
- book = source.first
- target = loader.load_library("Target")
- described_class.move(source, target, source.first)
+ described_class.move(source, target, book)
aggregate_failures do
expect(source.count).to eq count - 1
expect(target.count).to eq 1
+ end
+ end
+
+ it "moves the book files from source to target" do
+ described_class.move(source, target, book)
+
+ aggregate_failures do
expect(File.exist?(source.yaml(book))).to be_falsey
expect(File.exist?(source.cover(book))).to be_falsey
expect(File.exist?(target.yaml(book))).to be_truthy
expect(File.exist?(target.cover(book))).to be_truthy
end