class Cucumber::Cli::Main
def configuration
def configuration return @configuration if @configuration @configuration = Configuration.new(@out_stream, @error_stream) @configuration.parse!(@args) @configuration end
def each_lib
def each_lib requires = configuration.files_to_require verbose_log("Ruby files required:") verbose_log(requires.map{|lib| " * #{lib}"}.join("\n")) requires.each do |lib| begin yield lib rescue LoadError => e e.message << "\nFailed to load #{lib}" raise e end end verbose_log("\n") end
def enable_diffing
def enable_diffing if configuration.diff_enabled? begin require 'spec/expectations' begin require 'spec/runner/differs/default' # RSpec >=1.2.4 rescue ::LoadError require 'spec/expectations/differs/default' # RSpec <=1.2.3 end options = OpenStruct.new(:diff_format => :unified, :context_lines => 3) ::Spec::Expectations.differ = ::Spec::Expectations::Differs::Default.new(options) rescue ::LoadError => ignore end end end
def execute(args)
def execute(args) new(args).execute!(@step_mother) end
def execute!(step_mother)
def execute!(step_mother) trap_interrupt if configuration.drb? begin return DRbClient.run(@args, @error_stream, @out_stream) rescue DRbClientError => e @error_stream.puts "WARNING: #{e.message} Running features locally:" configuration.parse!(@args) end end step_mother.options = configuration.options # Feature files must be loaded before files are required. # This is because i18n step methods are only aliased when # features are loaded. If we swap the order, the requires # will fail. features = load_plain_text_features require_files enable_diffing visitor = configuration.build_formatter_broadcaster(step_mother) step_mother.visitor = visitor # Needed to support World#announce visitor.visit_features(features) failure = if configuration.wip? step_mother.scenarios(:passed).any? else step_mother.scenarios(:failed).any? || (configuration.strict? && step_mother.steps(:undefined).any?) end end
def initialize(args, out_stream = STDOUT, error_stream = STDERR)
def initialize(args, out_stream = STDOUT, error_stream = STDERR) @args = args @out_stream = out_stream == STDOUT ? Formatter::ColorIO.new : out_stream @error_stream = error_stream end
def load_files
def load_files each_lib{|lib| load(lib)} end
def load_plain_text_features
def load_plain_text_features features = Ast::Features.new verbose_log("Features:") configuration.feature_files.each do |f| feature_file = FeatureFile.new(f) feature = feature_file.parse(configuration.options) if feature features.add_feature(feature) verbose_log(" * #{f}") end end verbose_log("\n"*2) features end
def require_files
def require_files each_lib{|lib| require lib} end
def step_mother
def step_mother @step_mother end
def step_mother=(step_mother)
def step_mother=(step_mother) @step_mother = step_mother @step_mother.extend(StepMother) @step_mother.snippet_generator = StepDefinition end
def trap_interrupt
def trap_interrupt trap('INT') do $cucumber_interrupted = true end end
def verbose_log(string)
def verbose_log(string) @out_stream.puts(string) if configuration.verbose? end