Sha256: 1fe586b439a82c0fb390c260518e65886794a1a2b779ce89c9276715844821d2

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class CliUsageTest < Test::Unit::TestCase
  run_command_line_as {CliApp.run}
  
  run_with_options ["--help"] do
    assert_successful_run
    assert_out_contains /Usage:/
  end

  run_with_options [], "running with no arguments" do
    assert_successful_run
  end

  run_with_options ["--option", "PRINT_THIS"] do
    assert_successful_run
    assert_out_contains /PRINT_THIS/
  end
  
  run_with_options [], "run_with_options could be used within block" do
    assert_successful_run
    run_with_options []
  end
  
  run_with_options ["--invalid-option"], "running with invalid option" do
    assert_failed_run
    exception_raised = false
    begin
      assert_successful_run
    rescue Exception 
      exception_raised = true
    end
    assert(exception_raised)
  end
  
  run_with_options ["--raise"], "raise exception" do
    assert_failed_run
    exception_raised = false
    begin
      assert_successful_run
    rescue StandardError => error
      assert error.to_s =~ /CLI exception/
      exception_raised = true
    end
    assert(exception_raised)
  end
end

class CliTestNoCommandLineDefined < Test::Unit::TestCase
  def test_failure_when_command_line_defined
    assert_raise(RuntimeError) {self.class.run_with_options []}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fkocherga-cmd_line_test-0.1.3 test/test.rb