class Cucumber::Runtime

Attributes

configuration[R]
results[R]
support_code[R]

Public Class Methods

new(configuration = Configuration.default) click to toggle source
# File lib/cucumber/runtime.rb, line 53
def initialize(configuration = Configuration.default)
  @configuration = Configuration.new(configuration)
  @support_code = SupportCode.new(self, @configuration)
  @results = Formatter::LegacyApi::Results.new
end

Public Instance Methods

begin_scenario(test_case) click to toggle source
# File lib/cucumber/runtime.rb, line 98
def begin_scenario(test_case)
  @support_code.fire_hook(:begin_scenario, test_case)
end
configure(new_configuration) click to toggle source

Allows you to take an existing runtime and change its configuration

# File lib/cucumber/runtime.rb, line 60
def configure(new_configuration)
  @configuration = Configuration.new(new_configuration)
  @support_code.configure(@configuration)
end
doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0) click to toggle source

Returns Ast::DocString for string_without_triple_quotes.

# File lib/cucumber/runtime.rb, line 108
def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0)
  location = Core::Ast::Location.of_caller
  Core::Ast::DocString.new(string_without_triple_quotes, content_type, location)
end
dry_run?() click to toggle source
# File lib/cucumber/runtime.rb, line 82
def dry_run?
  @configuration.dry_run?
end
end_scenario(_scenario) click to toggle source
# File lib/cucumber/runtime.rb, line 102
def end_scenario(_scenario)
  @support_code.fire_hook(:end_scenario)
end
failure?() click to toggle source
# File lib/cucumber/runtime.rb, line 229
def failure?
  if @configuration.wip?
    summary_report.test_cases.total_passed > 0
  else
    !summary_report.ok?(@configuration.strict)
  end
end
features_paths() click to toggle source
# File lib/cucumber/runtime.rb, line 78
def features_paths
  @configuration.paths
end
run!() click to toggle source
# File lib/cucumber/runtime.rb, line 66
def run!
  load_step_definitions
  install_wire_plugin
  fire_after_configuration_hook
  # TODO: can we remove this state?
  self.visitor = report

  receiver = Test::Runner.new(@configuration.event_bus)
  compile features, receiver, filters
  @configuration.notify :test_run_finished
end
scenarios(status = nil) click to toggle source
# File lib/cucumber/runtime.rb, line 86
def scenarios(status = nil)
  @results.scenarios(status)
end
steps(status = nil) click to toggle source
# File lib/cucumber/runtime.rb, line 90
def steps(status = nil)
  @results.steps(status)
end
unmatched_step_definitions() click to toggle source
# File lib/cucumber/runtime.rb, line 94
def unmatched_step_definitions
  @support_code.unmatched_step_definitions
end

Private Instance Methods

accept_options?(factory) click to toggle source
# File lib/cucumber/runtime.rb, line 221
def accept_options?(factory)
  factory.instance_method(:initialize).arity > 1
end
create_formatter(factory, formatter_options, path_or_io, cli_options) click to toggle source
# File lib/cucumber/runtime.rb, line 201
def create_formatter(factory, formatter_options, path_or_io, cli_options)
  if !legacy_formatter?(factory)
    if accept_options?(factory)
      return factory.new(@configuration, formatter_options) if path_or_io.nil?
      return factory.new(@configuration.with_options(out_stream: path_or_io),
                         formatter_options)
    else
      return factory.new(@configuration) if path_or_io.nil?
      return factory.new(@configuration.with_options(out_stream: path_or_io))
    end
  end
  results = Formatter::LegacyApi::Results.new
  runtime_facade = Formatter::LegacyApi::RuntimeFacade.new(results, @support_code, @configuration)
  formatter = factory.new(runtime_facade, path_or_io, cli_options)
  Formatter::LegacyApi::Adapter.new(
    Formatter::IgnoreMissingMessages.new(formatter),
    results, @configuration
  )
end
fail_fast_report() click to toggle source
# File lib/cucumber/runtime.rb, line 190
def fail_fast_report
  @fail_fast_report ||= Formatter::FailFast.new(@configuration)
end
feature_files() click to toggle source
# File lib/cucumber/runtime.rb, line 128
def feature_files
  filespecs.files
end
features() click to toggle source
# File lib/cucumber/runtime.rb, line 120
def features
  @features ||= feature_files.map do |path|
    source = NormalisedEncodingFile.read(path)
    @configuration.notify :gherkin_source_read, path, source
    Cucumber::Core::Gherkin::Document.new(path, source)
  end
end
filespecs() click to toggle source
# File lib/cucumber/runtime.rb, line 132
def filespecs
  @filespecs ||= FileSpecs.new(@configuration.feature_files)
end
filters() click to toggle source
# File lib/cucumber/runtime.rb, line 239
def filters
  tag_expressions = @configuration.tag_expressions
  name_regexps = @configuration.name_regexps
  tag_limits = @configuration.tag_limits
  [].tap do |filters|
    filters << Filters::TagLimits.new(tag_limits) if tag_limits.any?
    filters << Cucumber::Core::Test::TagFilter.new(tag_expressions)
    filters << Cucumber::Core::Test::NameFilter.new(name_regexps)
    filters << Cucumber::Core::Test::LocationsFilter.new(filespecs.locations)
    filters << Filters::Randomizer.new(@configuration.seed) if @configuration.randomize?
    # TODO: can we just use Glue::RegistryAndMore's step definitions directly?
    step_match_search = StepMatchSearch.new(@support_code.registry.method(:step_matches), @configuration)
    filters << Filters::ActivateSteps.new(step_match_search, @configuration)
    @configuration.filters.each do |filter|
      filters << filter
    end
    unless configuration.dry_run?
      filters << Filters::ApplyAfterStepHooks.new(@support_code)
      filters << Filters::ApplyBeforeHooks.new(@support_code)
      filters << Filters::ApplyAfterHooks.new(@support_code)
      filters << Filters::ApplyAroundHooks.new(@support_code)
      filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
      filters << Filters::Quit.new
      filters << Filters::Retry.new(@configuration)
      # need to do this last so it becomes the first test step
      filters << Filters::PrepareWorld.new(self)
    end
  end
end
fire_after_configuration_hook() click to toggle source
# File lib/cucumber/runtime.rb, line 115
def fire_after_configuration_hook #:nodoc
  @support_code.fire_hook(:after_configuration, @configuration)
end
formatters() click to toggle source
# File lib/cucumber/runtime.rb, line 194
def formatters
  @formatters ||=
    @configuration.formatter_factories do |factory, formatter_options, path_or_io, options|
      create_formatter(factory, formatter_options, path_or_io, options)
    end
end
install_wire_plugin() click to toggle source
# File lib/cucumber/runtime.rb, line 274
def install_wire_plugin
  Cucumber::Wire::Plugin.new(@configuration, @support_code.registry).install if @configuration.all_files_to_load.any? { |f| f =~ /\.wire$/ }
end
legacy_formatter?(factory) click to toggle source
# File lib/cucumber/runtime.rb, line 225
def legacy_formatter?(factory)
  factory.instance_method(:initialize).arity > 2
end
load_step_definitions() click to toggle source
# File lib/cucumber/runtime.rb, line 269
def load_step_definitions
  files = @configuration.support_to_load + @configuration.step_defs_to_load
  @support_code.load_files!(files)
end
log() click to toggle source
# File lib/cucumber/runtime.rb, line 278
def log
  Cucumber.logger
end
report() click to toggle source
# File lib/cucumber/runtime.rb, line 179
def report
  return @report if @report
  reports = [summary_report] + formatters
  reports << fail_fast_report if @configuration.fail_fast?
  @report ||= Formatter::Fanout.new(reports)
end
summary_report() click to toggle source
# File lib/cucumber/runtime.rb, line 186
def summary_report
  @summary_report ||= Core::Report::Summary.new(@configuration.event_bus)
end