Class: Crspec::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
16
# File 'lib/crspec/cli.rb', line 12

def initialize(args)
  @args = args
  @concurrency = Etc.nprocessors
  @paths = []
end

Class Method Details

.run(args) ⇒ Object



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

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

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/crspec/cli.rb', line 18

def run
  parse_options
  load_specs
  runner = Runner.new(concurrency: @concurrency)
  groups = Crspec.world.example_groups

  if groups.empty?
    puts "No example groups found."
    return true
  end

  puts "Running Crspec suite with concurrency #{@concurrency}..."
  runner.run(groups)

  puts "\nFinished in #{runner.total_duration.round(4)} seconds"
  puts "#{runner.passed_examples.size + runner.failed_examples.size} examples, #{runner.failed_examples.size} failures"

  unless runner.failed_examples.empty?
    puts "\nFailures:"
    runner.failed_examples.each_with_index do |ex, idx|
      puts "#{idx + 1}) #{ex.description}"
      puts "   Failure/Error: #{ex.error.message}"
      puts "   #{ex.error.backtrace&.first}" if ex.error.backtrace
    end
  end

  runner.success?
end