class Cucumber::Cli::Main
Public Class Methods
Source
# File lib/cucumber/cli/main.rb, line 12 def execute(args) new(args).execute! end
Source
# File lib/cucumber/cli/main.rb, line 17 def initialize(args, out = $stdout, err = $stderr, kernel = Kernel) @args = args @out = out @err = err @kernel = kernel end
Public Instance Methods
Source
# File lib/cucumber/cli/main.rb, line 59 def configuration @configuration ||= Configuration.new(@out, @err).tap do |configuration| configuration.parse!(@args) Cucumber.logger = configuration.log end end
Source
# File lib/cucumber/cli/main.rb, line 24 def execute!(existing_runtime = nil) trap_interrupt trap_thread_dump_signal runtime = runtime(existing_runtime) runtime.run! if Cucumber.wants_to_quit exit_unable_to_finish elsif runtime.failure? exit_tests_failed else exit_ok end rescue SystemExit => e @kernel.exit(e.status) rescue FileNotFoundException => e @err.puts(e.message) @err.puts("Couldn't open #{e.path}") exit_unable_to_finish rescue FeatureFolderNotFoundException => e @err.puts("#{e.message}. You can use `cucumber --init` to get started.") exit_unable_to_finish rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e @err.puts(e.message) exit_unable_to_finish rescue Errno::EACCES, Errno::ENOENT => e @err.puts("#{e.message} (#{e.class})") exit_unable_to_finish rescue Exception => e @err.puts("#{e.message} (#{e.class})") @err.puts(e.backtrace.join("\n")) exit_unable_to_finish end
Private Instance Methods
Source
# File lib/cucumber/cli/main.rb, line 72 def exit_tests_failed @kernel.exit 1 end
Source
# File lib/cucumber/cli/main.rb, line 76 def exit_unable_to_finish @kernel.exit 2 end
Source
# File lib/cucumber/cli/main.rb, line 81 def exit_unable_to_finish! @kernel.exit! 2 end
stops the program immediately, without running at_exit blocks
Source
# File lib/cucumber/cli/main.rb, line 115 def runtime(existing_runtime) return Runtime.new(configuration) unless existing_runtime existing_runtime.tap { |runtime| runtime.configure(configuration) } end
Source
# File lib/cucumber/cli/main.rb, line 85 def trap_interrupt trap('INT') do exit_unable_to_finish! if Cucumber.wants_to_quit Cucumber.wants_to_quit = true $stderr.puts "\nExiting... Interrupt again to exit immediately." exit_unable_to_finish end end
Source
# File lib/cucumber/cli/main.rb, line 94 def trap_thread_dump_signal signal = %w[INFO PWR].find { |s| Signal.list.key?(s) } return if signal.nil? trap(signal) do Thread.list.each do |thread| prefix = "Thread TID-#{(thread.object_id ^ Process.pid).to_s(36)} #{thread.name || '<no name>'}" backtrace = thread.backtrace if backtrace&.any? backtrace.each do |line| @err.puts("#{prefix} #{line}") end else @err.puts("#{prefix} <no backtrace available>") end end end end