Sha256: 6bfc220dd50b73c69293aaf19b0b9596ca6fbf77ed17dcabb3e2cc5ab4543a93

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

# we mostly unit test with a Traject::Indexer itself and lower-level, but
# we need at least some basic top-level integration actually command line tests,
# this is a start, we can add more.
#
# Should we be testing Traject::CommandLine as an object instead of/in addition to
# actually testing shell-out to command line call? Maybe.

require 'test_helper'

describe "Shell out to command line" do
  # just encapsuluate using the minitest capture helper, but also
  # getting and returning exit code
  #
  #     out, err, result = execute_with_args("-c configuration")
  def execute_with_args(args)
    out, err = capture_subprocess_io do
      system("./bin/traject #{args}")
    end

    return out, err, $?
  end

  it "can display version" do
    out, err, result = execute_with_args("-v")

    assert result.success?, "Expected subprocess exit code to be success.\nSTDERR:\n#{err}\n\nSTDOUT:\n#{out}"
    assert_equal err, "traject version #{Traject::VERSION}\n"
  end

  it "can display help text" do
    out, err, result = execute_with_args("-h")

    assert result.success?, "Expected subprocess exit code to be success.\nSTDERR:\n#{err}\n\nSTDOUT:\n#{out}"
    assert err.start_with?("traject [options] -c configuration.rb [-c config2.rb] file.mrc")
  end

  it "handles bad argument" do
    out, err, result = execute_with_args("--no-such-arg")
    refute result.success?

    assert err.start_with?("Error: unknown option `--no-such-arg'\nExiting...\n")
  end

  it "does basic dry run" do
    out, err, result = execute_with_args("--debug-mode -s one=two -s three=four -c test/test_support/demo_config.rb test/test_support/emptyish_record.marc")

    assert result.success?, "Expected subprocess exit code to be success.\nSTDERR:\n#{err}\n\nSTDOUT:\n#{out}"
    assert_includes err, "executing with: `--debug-mode -s one=two -s three=four"
    assert_match /bib_1000165 +author_sort +Collection la/, out
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
traject-3.8.2 test/command_line_test.rb
traject-3.8.1 test/command_line_test.rb
traject-3.8.0 test/command_line_test.rb
traject-3.7.0 test/command_line_test.rb
traject-3.6.0 test/command_line_test.rb