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.



12
13
14
# File 'lib/assert/cli.rb', line 12

def initialize
  @cli = CLIRB.new
end

Class Method Details

.run(*args) ⇒ Object



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

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

Instance Method Details

#helpObject



40
41
42
43
44
# File 'lib/assert/cli.rb', line 40

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

#run(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/assert/cli.rb', line 16

def run(*args)
  begin
    @cli.parse!(*args)
    tests = @cli.args
    tests = ['test'] if tests.empty?
    Assert::CLIRunner.new(*tests).run
  rescue CLIRB::HelpExit
    puts help
  rescue CLIRB::VersionExit
    puts Assert::VERSION
  rescue CLIRB::Error => exception
    puts "#{exception.message}\n"
    puts help
    exit(1)
  rescue Exception => exception
    puts "#{exception.class}: #{exception.message}"
    puts exception.backtrace.join("\n") if ENV['DEBUG']
    exit(1)
  end

  # Don't call `exit(0)`.  The test suite runs as the by an `at_exit`
  # callback.  Calling `exit(0)` bypasses that callback.
end