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 57
def initialize(configuration = Configuration.default)
  @configuration = Configuration.new(configuration)
  @support_code = SupportCode.new(self, @configuration)
end

Public Instance Methods

begin_scenario(test_case) click to toggle source
# File lib/cucumber/runtime.rb, line 101
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 63
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 111
def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0)
  Core::Test::DocString.new(string_without_triple_quotes, content_type)
end
dry_run?() click to toggle source
# File lib/cucumber/runtime.rb, line 93
def dry_run?
  @configuration.dry_run?
end
end_scenario(_scenario) click to toggle source
# File lib/cucumber/runtime.rb, line 105
def end_scenario(_scenario)
  @support_code.fire_hook(:end_scenario)
end
failure?() click to toggle source
# File lib/cucumber/runtime.rb, line 232
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 89
def features_paths
  @configuration.paths
end
run!() click to toggle source
# File lib/cucumber/runtime.rb, line 69
def run!
  @configuration.notify :envelope, Cucumber::Messages::Envelope.new(
    meta: Cucumber::CreateMeta.create_meta('cucumber-ruby', Cucumber::VERSION)
  )

  load_step_definitions
  fire_after_configuration_hook
  fire_install_plugin_hook
  install_wire_plugin
  fire_before_all_hook unless dry_run?
  # TODO: can we remove this state?
  self.visitor = report

  receiver = Test::Runner.new(@configuration.event_bus)
  compile features, receiver, filters, @configuration.event_bus
  @configuration.notify :test_run_finished

  fire_after_all_hook unless dry_run?
end
unmatched_step_definitions() click to toggle source
# File lib/cucumber/runtime.rb, line 97
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 228
def accept_options?(factory)
  factory.instance_method(:initialize).arity > 1
end
create_formatter(factory, formatter_options, path_or_io) click to toggle source
# File lib/cucumber/runtime.rb, line 217
def create_formatter(factory, formatter_options, path_or_io)
  if accept_options?(factory)
    return factory.new(@configuration, formatter_options) if path_or_io.nil?
    factory.new(@configuration.with_options(out_stream: path_or_io),
                formatter_options)
  else
    return factory.new(@configuration) if path_or_io.nil?
    factory.new(@configuration.with_options(out_stream: path_or_io))
  end
end
fail_fast_report() click to toggle source
# File lib/cucumber/runtime.rb, line 202
def fail_fast_report
  @fail_fast_report ||= Formatter::FailFast.new(@configuration)
end
feature_files() click to toggle source
# File lib/cucumber/runtime.rb, line 142
def feature_files
  filespecs.files
end
features() click to toggle source
# File lib/cucumber/runtime.rb, line 134
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 146
def filespecs
  @filespecs ||= FileSpecs.new(@configuration.feature_files)
end
filters() click to toggle source
# File lib/cucumber/runtime.rb, line 242
def filters # rubocop:disable Metrics/AbcSize
  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 { |filter| filters << filter }

    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)
    end

    filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)

    unless configuration.dry_run?
      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
formatters() click to toggle source
# File lib/cucumber/runtime.rb, line 210
def formatters
  @formatters ||=
    @configuration.formatter_factories do |factory, formatter_options, path_or_io|
      create_formatter(factory, formatter_options, path_or_io)
    end
end
install_wire_plugin() click to toggle source
# File lib/cucumber/runtime.rb, line 281
def install_wire_plugin
  return if Cucumber::Wire::Plugin.installed?
  return unless @configuration.all_files_to_load.any? { |f| f =~ /\.wire$/ }

  Cucumber::Wire::Plugin.new(@configuration, registry_wrapper).install
  Cucumber.deprecate(
    'See https://github.com/cucumber/cucumber-ruby/blob/main/UPGRADING.md#upgrading-to-710 for more info',
    ' built-in usage of the wire protocol',
    '8.0.0'
  )
end
load_step_definitions() click to toggle source
# File lib/cucumber/runtime.rb, line 276
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 297
def log
  Cucumber.logger
end
publish_banner_printer() click to toggle source
# File lib/cucumber/runtime.rb, line 206
def publish_banner_printer
  @publish_banner_printer ||= Formatter::PublishBannerPrinter.new(@configuration)
end
registry_wrapper() click to toggle source
# File lib/cucumber/runtime.rb, line 293
def registry_wrapper
  Cucumber::Glue::RegistryWrapper.new(@support_code.registry)
end
report() click to toggle source
# File lib/cucumber/runtime.rb, line 190
def report
  return @report if @report
  reports = [summary_report] + formatters
  reports << fail_fast_report if @configuration.fail_fast?
  reports << publish_banner_printer unless @configuration.publish_quiet?
  @report ||= Formatter::Fanout.new(reports)
end
summary_report() click to toggle source
# File lib/cucumber/runtime.rb, line 198
def summary_report
  @summary_report ||= Core::Report::Summary.new(@configuration.event_bus)
end