Sha256: e77671e8ef8a4fc0e5546ac5c98469adee5768074cc9fb78fa72a74ecdb7d10f

Contents?: true

Size: 1.85 KB

Versions: 22

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require 'eac_cli/runner_with/output'
require 'eac_ruby_utils/fs/temp'

RSpec.describe ::EacCli::RunnerWith::Output do
  let(:runner) do
    the_module = described_class
    Class.new do
      include the_module

      attr_accessor :temp_dir

      runner_definition do
        desc 'A stub root runner.'
        pos_arg :input_text
      end

      def run
        run_output
      end

      def output_content
        parsed.input_text
      end

      def default_file_to_output
        temp_dir.join('default_file')
      end
    end
  end

  let(:stub_text) { 'STUB_TEXT' }
  let(:instance) do
    r = runner.create(argv: runner_argv)
    r.temp_dir = temp_dir
    r
  end
  let(:temp_dir) { ::EacRubyUtils::Fs::Temp.directory }

  after { temp_dir.remove }

  context 'without --output option' do
    let(:runner_argv) { [stub_text] }

    it do
      expect { instance.run }.to output(stub_text).to_stdout_from_any_process
    end
  end

  context 'without --output option as to stdout' do
    let(:runner_argv) { ['--output', ::EacCli::RunnerWith::Output::STDOUT_OPTION, stub_text] }

    it do
      expect { instance.run }.to output(stub_text).to_stdout_from_any_process
    end
  end

  context 'without --output option as to default file' do
    let(:output_file) { temp_dir.join('default_file') }
    let(:runner_argv) do
      ['--output', ::EacCli::RunnerWith::Output::DEFAULT_FILE_OPTION,
       stub_text]
    end

    before { instance.run }

    it { expect(output_file).to exist }
    it { expect(output_file.read).to eq(stub_text) }
  end

  context 'with --output option' do
    let(:output_file) { temp_dir.join('a output file') }
    let(:runner_argv) { ['--output', output_file.to_path, stub_text] }

    before { instance.run }

    it { expect(output_file).to exist }
    it { expect(output_file.read).to eq(stub_text) }
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
eac_tools-0.76.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.75.2 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.75.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.75.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.74.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.74.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.73.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.72.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.70.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.70.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.69.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.69.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.68.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.67.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.67.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.66.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.65.1 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.65.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.64.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb
eac_tools-0.63.0 sub/eac_cli/spec/lib/eac_cli/runner_with/output_spec.rb