Class: Assert::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



27
28
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 27

def initialize(*args)
  @args = args
  @cli = CLIRB.new do
    option 'runner_seed', 'Use a given seed to run tests', {
      :abbrev => 's', :value => Fixnum
    }
    option 'capture_output', 'capture stdout and display in result details', {
      :abbrev => 'o'
    }
    option 'halt_on_fail', 'halt a test when it fails', {
      :abbrev => 't'
    }
    option 'changed_only', 'only run test files with changes', {
      :abbrev => 'c'
    }
    option 'pp_objects', 'pretty-print objects in fail messages', {
      :abbrev => 'p'
    }
    option 'profile', 'output test profile info', {
      :abbrev => 'e'
    }
    # show loaded test files, cli err backtraces, etc
    option 'debug', 'run in debug mode'
  end
end

Class Method Details

.bench(msg, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/assert/cli.rb', line 18

def self.bench(msg, &block)
  if !Assert.config.debug
    block.call; return
  end
  RoundedMillisecondTime.new(Benchmark.measure(&block).real).tap do |time_in_ms|
    puts debug_msg(msg, time_in_ms)
  end
end

.debug?(args) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.debug?(args)
  args.include?('-d') || args.include?('--debug')
end

.debug_msg(msg, time_in_ms = nil) ⇒ Object



14
15
16
# File 'lib/assert/cli.rb', line 14

def self.debug_msg(msg, time_in_ms = nil)
  "[DEBUG] #{msg}#{" (#{time_in_ms} ms)" if time_in_ms}"
end

Instance Method Details

#helpObject



73
74
75
76
77
# File 'lib/assert/cli.rb', line 73

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

#runObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/assert/cli.rb', line 53

def run
  begin
    @cli.parse!(@args)
    Assert::AssertRunner.new(Assert.config, @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  Assert.config.debug ? 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