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.



13
14
15
16
17
18
19
# File 'lib/crspec/cli.rb', line 13

def initialize(args)
  @args = args
  @concurrency = Crspec.configuration.concurrency
  @paths = []
  @requires = []
  @init_mode = false
end

Class Method Details

.run(args) ⇒ Object



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

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

Instance Method Details

#runObject



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/crspec/cli.rb', line 21

def run
  parse_options

  if @init_mode
    created = Generators::Init.generate
    if created.empty?
      puts "No helper files were created (already exists or not a Rails project)."
    else
      created.each { |f| puts "  create #{f}" }
    end
    return true
  end

  load_requires
  load_specs

  concurrency = @concurrency || Crspec.configuration.concurrency
  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