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 47
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(scenario) click to toggle source
# File lib/cucumber/runtime.rb, line 90
def begin_scenario(scenario)
  @support_code.fire_hook(:begin_scenario, scenario)
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 54
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 100
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 74
def dry_run?
  @configuration.dry_run?
end
end_scenario(scenario) click to toggle source
# File lib/cucumber/runtime.rb, line 94
def end_scenario(scenario)
  @support_code.fire_hook(:end_scenario)
end
failure?() click to toggle source
# File lib/cucumber/runtime.rb, line 212
def failure?
  if @configuration.wip?
    summary_report.test_cases.total_passed > 0
  else
    summary_report.test_cases.total_failed > 0 || summary_report.test_steps.total_failed > 0 ||
      (@configuration.strict? && (summary_report.test_steps.total_undefined > 0 || summary_report.test_steps.total_pending > 0))
  end
end
features_paths() click to toggle source
# File lib/cucumber/runtime.rb, line 70
def features_paths
  @configuration.paths
end
run!() click to toggle source
# File lib/cucumber/runtime.rb, line 60
def run!
  load_step_definitions
  install_wire_plugin
  fire_after_configuration_hook
  self.visitor = report

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

Private Instance Methods

create_formatter(factory, path_or_io, options) click to toggle source
# File lib/cucumber/runtime.rb, line 195
def create_formatter(factory, path_or_io, options)
  if !legacy_formatter?(factory)
    out_stream = Cucumber::Formatter::Io.ensure_io(path_or_io)
    return factory.new(@configuration.with_options(out_stream: out_stream))
  end
  results = Formatter::LegacyApi::Results.new
  runtime_facade = Formatter::LegacyApi::RuntimeFacade.new(results, @support_code, @configuration)
  formatter = factory.new(runtime_facade, path_or_io, options)
  Formatter::LegacyApi::Adapter.new(
    Formatter::IgnoreMissingMessages.new(formatter),
    results, @configuration)
end
event_bus_report() click to toggle source
# File lib/cucumber/runtime.rb, line 181
def event_bus_report
  @event_bus_report ||= Formatter::EventBusReport.new(@configuration)
end
fail_fast_report() click to toggle source
# File lib/cucumber/runtime.rb, line 185
def fail_fast_report
  @fail_fast_report ||= Formatter::FailFast.new(@configuration)
end
feature_files() click to toggle source
# File lib/cucumber/runtime.rb, line 119
def feature_files
  filespecs.files
end
features() click to toggle source
# File lib/cucumber/runtime.rb, line 112
def features
  @features ||= feature_files.map do |path|
    source = NormalisedEncodingFile.read(path)
    Cucumber::Core::Gherkin::Document.new(path, source)
  end
end
filespecs() click to toggle source
# File lib/cucumber/runtime.rb, line 123
def filespecs
  @filespecs ||= FileSpecs.new(@configuration.feature_files)
end
filters() click to toggle source
# File lib/cucumber/runtime.rb, line 223
def filters
  tag_expressions = @configuration.tag_expressions
  name_regexps = @configuration.name_regexps
  tag_limits = @configuration.tag_limits
  [].tap do |filters|
    filters << Filters::Randomizer.new(@configuration.seed) if @configuration.randomize?
    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::Quit.new
    # TODO: can we just use RbLanguages's step definitions directly?
    step_match_search = StepMatchSearch.new(@support_code.ruby.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)
      # 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 107
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 189
def formatters
  @formatters ||= @configuration.formatter_factories { |factory, path_or_io, options|
    create_formatter(factory, path_or_io, options)
  }
end
install_wire_plugin() click to toggle source
# File lib/cucumber/runtime.rb, line 256
def install_wire_plugin
  Cucumber::Wire::Plugin.new(@configuration).install if @configuration.all_files_to_load.any? {|f| f =~ %r{\.wire$} }
end
legacy_formatter?(factory) click to toggle source
# File lib/cucumber/runtime.rb, line 208
def legacy_formatter?(factory)
  factory.instance_method(:initialize).arity > 1
end
load_step_definitions() click to toggle source
# File lib/cucumber/runtime.rb, line 251
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 260
def log
  Cucumber.logger
end
report() click to toggle source
# File lib/cucumber/runtime.rb, line 170
def report
  return @report if @report
  reports = [summary_report, event_bus_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 177
def summary_report
  @summary_report ||= Core::Report::Summary.new
end