Class: Cucumber::Cli::Main

Inherits:
Object show all
Defined in:
lib/cucumber/cli/main.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, stdin = STDIN, out = STDOUT, err = STDERR, kernel = Kernel) ⇒ Main

Returns a new instance of Main.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cucumber/cli/main.rb', line 24

def initialize(args, stdin=STDIN, out=STDOUT, err=STDERR, kernel=Kernel)
  raise "args can't be nil" unless args
  raise "out can't be nil" unless out
  raise "err can't be nil" unless err
  raise "kernel can't be nil" unless kernel
  @args   = args
  @out    = out
  @err    = err
  @kernel = kernel
  @configuration = nil
end

Class Method Details

.execute(args) ⇒ Object



19
20
21
# File 'lib/cucumber/cli/main.rb', line 19

def execute(args)
  new(args).execute!
end

Instance Method Details

#configurationObject



64
65
66
67
68
69
70
71
# File 'lib/cucumber/cli/main.rb', line 64

def configuration
  return @configuration if @configuration

  @configuration = Configuration.new(@out, @err)
  @configuration.parse!(@args)
  Cucumber.logger = @configuration.log
  @configuration
end

#execute!(existing_runtime = nil) ⇒ Object



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/cucumber/cli/main.rb', line 36

def execute!(existing_runtime = nil)
  trap_interrupt
  return @drb_output if run_drb_client

  runtime = if existing_runtime
    existing_runtime.configure(configuration)
    existing_runtime
  else
    Runtime.new(configuration)
  end

  runtime.run!
  runtime.write_stepdefs_json
  failure = runtime.results.failure? || Cucumber.wants_to_quit
  @kernel.exit(failure ? 1 : 0)
rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e
  @err.puts(e.message)
rescue SystemExit => e
  @kernel.exit(e.status)
rescue Errno::EACCES, Errno::ENOENT => e
  @err.puts("#{e.message} (#{e.class})")
  @kernel.exit(1)
rescue Exception => e
  @err.puts("#{e.message} (#{e.class})")
  @err.puts(e.backtrace.join("\n"))
  @kernel.exit(1)
end