diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8967a59..0cdb301 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,48 @@ require_relative "../lib/ht_traject" require_relative "examples" +def test_log + "TEST_LOG.txt" +end + +def remove_test_log + FileUtils.rm(CICTL::LogfileDefaults.filepath_of(test_log)) +rescue Errno::ENOENT + # file wasn't there, and that's fine +end + +# Combined setup and teardown for journal directory and files. +# Services handles creating the journal directory if it doesn't exist, +# so we just need to empty it. +def init_journals + FileUtils.rm_rf Dir.glob("#{HathiTrust::Services[:journal_directory]}/*") +end + +def solr_count + CICTL::SolrClient.new.count +end + +def solr_deleted_count + CICTL::SolrClient.new.count_deleted +end + +def solr_ids(q = "*:*") + solr_params = {q: q, wt: "ruby", rows: 100} + response = CICTL::SolrClient.new.get("select", params: solr_params) + response["response"]["docs"].map { |doc| doc["id"] } +end + +def override_service(key, &block) + around(:each) do |example| + old_val = HathiTrust::Services[key] + HathiTrust::Services.register(key, &block) + example.run + HathiTrust::Services.register(key) { old_val } + end +end + +# BEGIN RSPEC BOILERPLATE + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -115,43 +157,3 @@ # # as the one that triggered the failure. # Kernel.srand config.seed end - -def test_log - "TEST_LOG.txt" -end - -def remove_test_log - FileUtils.rm(CICTL::LogfileDefaults.filepath_of(test_log)) -rescue Errno::ENOENT - # file wasn't there, and that's fine -end - -# Combined setup and teardown for journal directory and files. -# Services handles creating the journal directory if it doesn't exist, -# so we just need to empty it. -def init_journals - FileUtils.rm_rf Dir.glob("#{HathiTrust::Services[:journal_directory]}/*") -end - -def solr_count - CICTL::SolrClient.new.count -end - -def solr_deleted_count - CICTL::SolrClient.new.count_deleted -end - -def solr_ids(q = "*:*") - solr_params = {q: q, wt: "ruby", rows: 100} - response = CICTL::SolrClient.new.get("select", params: solr_params) - response["response"]["docs"].map { |doc| doc["id"] } -end - -def override_service(key, &block) - around(:each) do |example| - old_val = HathiTrust::Services[key] - HathiTrust::Services.register(key, &block) - example.run - HathiTrust::Services.register(key) { old_val } - end -end