Class: Assert::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/assert/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/assert/cli.rb', line 13

def initialize
  @cli = CLIRB.new do
    option 'runner_seed', 'Use a given seed to run tests', {
      :abbrev => 's', :value => Fixnum
    }
    option 'show_output', 'show stdout output (do not capture)', {
      :abbrev => 'o'
    }
    option 'halt_on_fail', 'halt a test when it fails', {
      :abbrev => 't'
    }
    # show loaded test files, cli err backtraces, etc
    option 'debug', 'run in debug mode'
  end
end

Class Method Details

.run(*args) ⇒ Object



9
10
11
# File 'lib/assert/cli.rb', line 9

def self.run(*args)
  self.new.run(*args)
end

Instance Method Details

#helpObject



53
54
55
56
57
# File 'lib/assert/cli.rb', line 53

def help
  "Usage: assert [options] [TESTS]\n\n"\
  "Options:"\
  "#{@cli}"
end

#run(*args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/assert/cli.rb', line 29

def run(*args)
  # default debug_mode to the env var
  debug_mode = ENV['ASSERT_DEBUG'] == 'true'
  begin
    # parse manually in the case that parsing fails before the debug arg
    debug_mode ||= args.include?('-d') || args.include?('--debug')
    @cli.parse!(args)
    Assert::AssertRunner.new(@cli.args, @cli.opts).run
  rescue CLIRB::HelpExit
    puts help
  rescue CLIRB::VersionExit
    puts Assert::VERSION
  rescue CLIRB::Error => exception
    puts "#{exception.message}\n\n"
    puts  debug_mode ? exception.backtrace.join("\n") : help
    exit(1)
  rescue Exception => exception
    puts "#{exception.class}: #{exception.message}"
    puts exception.backtrace.join("\n")
    exit(1)
  end
  exit(0)
end