From dcd50e38d56f95e2bf88413b4d56db7132dccf11 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Thu, 20 Jun 2024 11:41:02 -0400 Subject: [PATCH] Switch from rspec to minitest Also adds a Rakefile, and pulls in Rubocop while we're at it. --- Gemfile | 2 + Gemfile.lock | 85 +++++++++++++++++----- Rakefile | 11 +++ author.rb => app/author.rb | 0 book.rb => app/book.rb | 0 book_loader.rb => app/book_loader.rb | 0 classification.rb => app/classification.rb | 0 cover.rb => app/cover.rb | 0 extract.rb => app/extract.rb | 0 main.rb => app/main.rb | 0 navigator.rb => app/navigator.rb | 0 page.rb => app/page.rb | 0 series.rb => app/series.rb | 0 store.rb => app/store.rb | 0 tconn.rb => app/tconn.rb | 0 walk_dir.rb => app/walk_dir.rb | 0 test/book_test.rb | 17 +++-- test/store_test.rb | 19 +++-- test/test_helper.rb | 6 ++ 19 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 Rakefile rename author.rb => app/author.rb (100%) rename book.rb => app/book.rb (100%) rename book_loader.rb => app/book_loader.rb (100%) rename classification.rb => app/classification.rb (100%) rename cover.rb => app/cover.rb (100%) rename extract.rb => app/extract.rb (100%) rename main.rb => app/main.rb (100%) rename navigator.rb => app/navigator.rb (100%) rename page.rb => app/page.rb (100%) rename series.rb => app/series.rb (100%) rename store.rb => app/store.rb (100%) rename tconn.rb => app/tconn.rb (100%) rename walk_dir.rb => app/walk_dir.rb (100%) create mode 100644 test/test_helper.rb diff --git a/Gemfile b/Gemfile index e3b145e..0181479 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ source 'http://rubygems.org' gem 'inifile' +gem 'mocha' gem 'nokogiri' gem 'pg' gem 'rspec' +gem 'rubocop' gem 'rubyzip' diff --git a/Gemfile.lock b/Gemfile.lock index 3cc58d3..9778251 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,36 +1,83 @@ GEM remote: http://rubygems.org/ specs: - diff-lcs (1.3) + ast (2.4.2) + diff-lcs (1.5.1) inifile (3.0.0) - mini_portile2 (2.4.0) - nokogiri (1.10.3) - mini_portile2 (~> 2.4.0) - pg (1.1.4) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) + json (2.7.2) + language_server-protocol (3.17.0.3) + mocha (2.4.0) + ruby2_keywords (>= 0.0.5) + nokogiri (1.16.6-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.6-arm-linux) + racc (~> 1.4) + nokogiri (1.16.6-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.6-x86-linux) + racc (~> 1.4) + nokogiri (1.16.6-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.6-x86_64-linux) + racc (~> 1.4) + parallel (1.25.1) + parser (3.3.3.0) + ast (~> 2.4.1) + racc + pg (1.5.6) + racc (1.8.0) + rainbow (3.1.1) + regexp_parser (2.9.2) + rexml (3.3.0) + strscan + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.2) - rubyzip (1.2.3) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) + strscan (3.1.0) + unicode-display_width (2.5.0) PLATFORMS - ruby + aarch64-linux + arm-linux + arm64-darwin + x86-linux + x86_64-darwin + x86_64-linux DEPENDENCIES inifile + mocha nokogiri pg rspec + rubocop rubyzip BUNDLED WITH - 2.0.2 + 2.5.13 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9cf3b56 --- /dev/null +++ b/Rakefile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "minitest/test_task" + +Minitest::TestTask.create + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[test rubocop] diff --git a/author.rb b/app/author.rb similarity index 100% rename from author.rb rename to app/author.rb diff --git a/book.rb b/app/book.rb similarity index 100% rename from book.rb rename to app/book.rb diff --git a/book_loader.rb b/app/book_loader.rb similarity index 100% rename from book_loader.rb rename to app/book_loader.rb diff --git a/classification.rb b/app/classification.rb similarity index 100% rename from classification.rb rename to app/classification.rb diff --git a/cover.rb b/app/cover.rb similarity index 100% rename from cover.rb rename to app/cover.rb diff --git a/extract.rb b/app/extract.rb similarity index 100% rename from extract.rb rename to app/extract.rb diff --git a/main.rb b/app/main.rb similarity index 100% rename from main.rb rename to app/main.rb diff --git a/navigator.rb b/app/navigator.rb similarity index 100% rename from navigator.rb rename to app/navigator.rb diff --git a/page.rb b/app/page.rb similarity index 100% rename from page.rb rename to app/page.rb diff --git a/series.rb b/app/series.rb similarity index 100% rename from series.rb rename to app/series.rb diff --git a/store.rb b/app/store.rb similarity index 100% rename from store.rb rename to app/store.rb diff --git a/tconn.rb b/app/tconn.rb similarity index 100% rename from tconn.rb rename to app/tconn.rb diff --git a/walk_dir.rb b/app/walk_dir.rb similarity index 100% rename from walk_dir.rb rename to app/walk_dir.rb diff --git a/test/book_test.rb b/test/book_test.rb index 64a2892..de32278 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -1,17 +1,18 @@ +# frozen_string_literal: true -require 'rspec/autorun' -require_relative '../book' +require "test_helper" +require "book" -describe Book do - it "can handle .epub and .pdf files" do - ['epub', 'pdf'].each do |extension| - expect(Book.can_handle?("sample.#{extension}")).to be true +class BookTest < Minitest::Test + def test_that_it_can_handle_epub_and_pdf_files + %w(epub pdf).each do |extension| + assert_equal true, Book.can_handle?("sample.#{extension}") end end - it "cannot handle .mobi, .html, .txt, .doc, .zip, .rtf or .rar files" do + def test_that_it_cannot_handle_mobi_html_txt_doc_zip_rtf_nor_rar %w(doc html mobi rar rtf txt zip).each do |extension| - expect(Book.can_handle?("sample.#{extension}")).to be false + assert_equal false, Book.can_handle?("sample.#{extension}") end end end diff --git a/test/store_test.rb b/test/store_test.rb index 5ebeff1..46676b8 100644 --- a/test/store_test.rb +++ b/test/store_test.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true -require 'rspec/autorun' -require_relative '../store' +require "test_helper" -describe Store do - it "construct_efs_path produces paths and filenames as expected" do +require "store" + +class StoreTest < Minitest::Test + def test_construct_efs_path data = [ [ 1234, '00/00/00/12', '0000001234.dat'], [ 1, '00/00/00/00', '0000000001.dat'], @@ -12,13 +14,14 @@ describe Store do [ 0x1b, '00/00/00/00', '0000000027.dat'] ] + IniFile.stubs(:load).returns({"database" => {}, "filesystem" => {}}) store = Store.new('quanlib.ini') - data.each do |input, expectedPath, expectedName| - (actualPath, actualName) = store.construct_efs_path(input) + data.each do |input, expected_path, expected_name| + (actual_path, actual_name) = store.construct_efs_path(input) - expect(actualPath).to eq(expectedPath) - expect(actualName).to eq(expectedName) + assert_equal expected_path, actual_path + assert_equal expected_name, actual_name end end end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..25bf530 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +$LOAD_PATH.unshift File.expand_path("../app", __dir__) + +require "minitest/autorun" +require "mocha/minitest" -- 2.39.2