Skip to content

Commit

Permalink
TIDY: move boilerplate config to end of spec/spec_helper.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
moseshll committed Oct 18, 2024
1 parent d6d5ded commit 3da8b23
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 3da8b23

Please sign in to comment.