repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/examples/i18n/lv/lib/calculator.rb | examples/i18n/lv/lib/calculator.rb | # frozen_string_literal: true
class Calculator
def initialize
@stack = []
end
def push(arg)
@stack.push(arg)
end
def add
@stack.inject(0) { |n, sum| sum + n }
end
def divide
@stack[0].to_f / @stack[1]
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/examples/i18n/da/features/step_definitions/lommeregner_steps.rb | examples/i18n/da/features/step_definitions/lommeregner_steps.rb | # frozen_string_literal: true
begin
require 'rspec/expectations'
rescue LoadError
require 'spec/expectations'
end
require 'cucumber/formatter/unicode'
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../lib")
require 'lommeregner'
Before do
@calc = Lommeregner.new
end
After do
end
Given(/at jeg har indtastet (\d+)/) do |n|
@calc.push n.to_i
end
When('jeg lægger sammen') do
@result = @calc.add
end
Then(/skal resultatet være (\d*)/) do |result|
expect(@result).to eq(result.to_f)
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/examples/i18n/da/lib/lommeregner.rb | examples/i18n/da/lib/lommeregner.rb | # frozen_string_literal: true
class Lommeregner
def initialize
@stack = []
end
def push(arg)
@stack.push(arg)
end
def add
@stack.inject(0) { |n, sum| sum + n }
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb | examples/i18n/et/features/step_definitions/kalkulaator_steps.rb | # frozen_string_literal: true
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../lib")
require 'kalkulaator'
Before do
@calc = Kalkulaator.new
end
After do
end
Given(/olen sisestanud kalkulaatorisse numbri (\d+)/) do |n|
@calc.push n.to_i
end
When(/ma vajutan (\w+)/) do |op|
@result = @calc.send op
end
Then(/vastuseks peab ekraanil kuvatama (.*)/) do |result|
expect(@result).to eq(result.to_f)
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/examples/i18n/et/lib/kalkulaator.rb | examples/i18n/et/lib/kalkulaator.rb | # frozen_string_literal: true
class Kalkulaator
def initialize
@stack = []
end
def push(arg)
@stack.push(arg)
end
def liida
@stack.inject(0) { |n, sum| sum + n }
end
def jaga
@stack[0].to_f / @stack[1]
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/simplecov_setup.rb | lib/simplecov_setup.rb | # frozen_string_literal: true
if ENV['SIMPLECOV']
begin
# Suppress warnings in order not to pollute stdout which tests expectations rely on
$VERBOSE = nil if defined?(JRUBY_VERSION)
require 'simplecov'
SimpleCov.root(File.expand_path("#{File.dirname(__FILE__)}/.."))
SimpleCov.start do
add_filter 'iso-8859-1_steps.rb'
add_filter '.-ruby-core/'
add_filter '/spec/'
add_filter '/features/'
end
rescue LoadError
warn('Unable to load simplecov')
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber.rb | lib/cucumber.rb | # frozen_string_literal: true
require 'yaml'
require 'cucumber/encoding'
require 'cucumber/platform'
require 'cucumber/runtime'
require 'cucumber/cli/main'
require 'cucumber/step_definitions'
require 'cucumber/term/ansicolor'
module Cucumber
class << self
attr_accessor :wants_to_quit
attr_reader :use_legacy_autoloader
def deprecate(message, method, remove_after_version)
Kernel.warn(
"\nWARNING: #{method} is deprecated" \
" and will be removed after version #{remove_after_version}. #{message}.\n" \
"(Called from #{caller(3..3).first})"
)
end
def logger
return @log if @log
@log = Logger.new($stdout)
@log.level = Logger::INFO
@log
end
def logger=(logger)
@log = logger
end
def use_legacy_autoloader=(value)
Cucumber.deprecate(
'This will be phased out of cucumber and should not be used. It is only there to support legacy systems',
'.use_legacy_autoloader',
'11.0.0'
)
@use_legacy_autoloader = value
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events.rb | lib/cucumber/events.rb | # frozen_string_literal: true
Dir["#{File.dirname(__FILE__)}/events/*.rb"].map(&method(:require))
module Cucumber
# Events tell you what's happening while Cucumber runs your features.
#
# They're designed to be read-only, appropriate for writing formatters and other
# output tools. If you need to be able to influence the result of a scenario, use a {RbSupport::RbDsl hook} instead.
#
# To subscribe to an event, use {Cucumber::Configuration#on_event}
#
# @example
# InstallPlugin do |config|
# config.on_event :test_case_finished do |event|
# puts event.result
# end
# end
#
module Events
def self.make_event_bus
Core::EventBus.new(registry)
end
def self.registry
Core::Events.build_registry(
GherkinSourceParsed,
GherkinSourceRead,
HookTestStepCreated,
StepActivated,
StepDefinitionRegistered,
TestCaseCreated,
TestCaseFinished,
TestCaseStarted,
TestCaseReady,
TestRunFinished,
TestRunStarted,
TestStepCreated,
TestStepFinished,
TestStepStarted,
Envelope,
UndefinedParameterType
)
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/running_test_case.rb | lib/cucumber/running_test_case.rb | # frozen_string_literal: true
require 'delegate'
module Cucumber
# Represents the current status of a running test case.
#
# This wraps a `Cucumber::Core::Test::Case` and delegates
# many methods to that object.
#
# We decorete the core object with the current result.
# In the first Before hook of a scenario, this will be an
# instance of `Cucumber::Core::Test::Result::Unknown`
# but as the scenario runs, it will be updated to reflect
# the passed / failed / undefined / skipped status of
# the test case.
#
module RunningTestCase
def self.new(test_case)
TestCase.new(test_case)
end
class TestCase < SimpleDelegator
def initialize(test_case, result = Core::Test::Result::Unknown.new)
@test_case = test_case
@result = result
super test_case
end
def accept_hook?(hook)
hook.tag_expressions.all? { |expression| @test_case.match_tags?(expression) }
end
def exception
return unless @result.failed?
@result.exception
end
def status
@result.to_sym
end
def failed?
@result.failed?
end
def passed?
!failed?
end
def source_tag_names
tags.map(&:name)
end
def with_result(result)
self.class.new(@test_case, result)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/platform.rb | lib/cucumber/platform.rb | # frozen_string_literal: true
require 'rbconfig'
require 'cucumber/core/platform'
module Cucumber
VERSION = File.read(File.expand_path('../../VERSION', __dir__)).strip
BINARY = File.expand_path("#{File.dirname(__FILE__)}/../../bin/cucumber")
LIBDIR = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
class << self
attr_writer :use_full_backtrace
def use_full_backtrace
@use_full_backtrace ||= false
end
def file_mode(mode, encoding = 'UTF-8')
"#{mode}:#{encoding}"
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/unit.rb | lib/cucumber/unit.rb | # frozen_string_literal: true
module Cucumber
class Unit
def initialize(step_collection)
@step_collection = step_collection
end
def step_count
@step_collection.length
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/repository.rb | lib/cucumber/repository.rb | # frozen_string_literal: true
module Cucumber
# In memory repository i.e. a thread based link to cucumber-query
class Repository
attr_accessor :meta, :test_run_started, :test_run_finished
attr_reader :attachments_by_test_case_started_id, :attachments_by_test_run_hook_started_id,
:hook_by_id,
:pickle_by_id, :pickle_step_by_id,
:step_by_id, :step_definition_by_id,
:test_case_by_id, :test_case_started_by_id, :test_case_finished_by_test_case_started_id,
:test_run_hook_started_by_id, :test_run_hook_finished_by_test_run_hook_started_id,
:test_step_by_id, :test_steps_started_by_test_case_started_id, :test_steps_finished_by_test_case_started_id
# TODO: Missing structs (3)
# final Map<Object, Lineage> lineageById = new HashMap<>();
# final Map<String, List<Suggestion>> suggestionsByPickleStepId = new LinkedHashMap<>();
# final List<UndefinedParameterType> undefinedParameterTypes = new ArrayList<>();
def initialize
@attachments_by_test_case_started_id = Hash.new { |hash, key| hash[key] = [] }
@attachments_by_test_run_hook_started_id = Hash.new { |hash, key| hash[key] = [] }
@hook_by_id = {}
@pickle_by_id = {}
@pickle_step_by_id = {}
@step_by_id = {}
@step_definition_by_id = {}
@test_case_by_id = {}
@test_case_started_by_id = {}
@test_case_finished_by_test_case_started_id = {}
@test_run_hook_started_by_id = {}
@test_run_hook_finished_by_test_run_hook_started_id = {}
@test_step_by_id = {}
@test_steps_started_by_test_case_started_id = Hash.new { |hash, key| hash[key] = [] }
@test_steps_finished_by_test_case_started_id = Hash.new { |hash, key| hash[key] = [] }
end
def update(envelope)
return self.meta = envelope.meta if envelope.meta
return self.test_run_started = envelope.test_run_started if envelope.test_run_started
return self.test_run_finished = envelope.test_run_finished if envelope.test_run_finished
return update_attachment(envelope.attachment) if envelope.attachment
return update_gherkin_document(envelope.gherkin_document) if envelope.gherkin_document
return update_hook(envelope.hook) if envelope.hook
return update_pickle(envelope.pickle) if envelope.pickle
return update_step_definition(envelope.step_definition) if envelope.step_definition
return update_test_run_hook_started(envelope.test_run_hook_started) if envelope.test_run_hook_started
return update_test_run_hook_finished(envelope.test_run_hook_finished) if envelope.test_run_hook_finished
return update_test_case_started(envelope.test_case_started) if envelope.test_case_started
return update_test_case_finished(envelope.test_case_finished) if envelope.test_case_finished
return update_test_step_started(envelope.test_step_started) if envelope.test_step_started
return update_test_step_finished(envelope.test_step_finished) if envelope.test_step_finished
return update_test_case(envelope.test_case) if envelope.test_case
nil
end
private
def update_attachment(attachment)
attachments_by_test_case_started_id[attachment.test_case_started_id] << attachment if attachment.test_case_started_id
attachments_by_test_run_hook_started_id[attachment.test_run_hook_started_id] << attachment if attachment.test_run_hook_started_id
end
def update_feature(feature)
feature.children.each do |feature_child|
update_steps(feature_child.background.steps) if feature_child.background
update_scenario(feature_child.scenario) if feature_child.scenario
next unless feature_child.rule
feature_child.rule.children.each do |rule_child|
update_steps(rule_child.background.steps) if rule_child.background
update_scenario(rule_child.scenario) if rule_child.scenario
end
end
end
def update_gherkin_document(gherkin_document)
# TODO: Update lineage at a later date. Java Impl -> lineageById.putAll(Lineages.of(document));
update_feature(gherkin_document.feature) if gherkin_document.feature
end
def update_hook(hook)
hook_by_id[hook.id] = hook
end
def update_pickle(pickle)
pickle_by_id[pickle.id] = pickle
pickle.steps.each { |pickle_step| pickle_step_by_id[pickle_step.id] = pickle_step }
end
def update_scenario(scenario)
update_steps(scenario.steps)
end
def update_steps(steps)
steps.each { |step| step_by_id[step.id] = step }
end
def update_step_definition(step_definition)
step_definition_by_id[step_definition.id] = step_definition
end
def update_test_case(test_case)
test_case_by_id[test_case.id] = test_case
test_case.test_steps.each { |test_step| test_step_by_id[test_step.id] = test_step }
end
def update_test_case_started(test_case_started)
test_case_started_by_id[test_case_started.id] = test_case_started
end
def update_test_case_finished(test_case_finished)
test_case_finished_by_test_case_started_id[test_case_finished.test_case_started_id] = test_case_finished
end
def update_test_run_hook_started(test_run_hook_started)
test_run_hook_started_by_id[test_run_hook_started.id] = test_run_hook_started
end
def update_test_run_hook_finished(test_run_hook_finished)
test_run_hook_finished_by_test_run_hook_started_id[test_run_hook_finished.test_run_hook_started_id] = test_run_hook_finished
end
def update_test_step_started(test_step_started)
test_steps_started_by_test_case_started_id[test_step_started.test_case_started_id] << test_step_started
end
def update_test_step_finished(test_step_finished)
test_steps_finished_by_test_case_started_id[test_step_finished.test_case_started_id] << test_step_finished
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/multiline_argument.rb | lib/cucumber/multiline_argument.rb | # frozen_string_literal: true
require 'delegate'
require 'cucumber/multiline_argument/data_table'
require 'cucumber/multiline_argument/doc_string'
module Cucumber
module MultilineArgument
class << self
def from_core(node)
builder.wrap(node)
end
def from(argument, location = nil, content_type = nil)
location ||= Core::Test::Location.of_caller
case argument
when String
builder.doc_string(Core::Test::DocString.new(argument, content_type))
when Array
location = location.on_line(argument.first.line..argument.last.line)
builder.data_table(argument.map(&:cells), location)
when DataTable, DocString, None
argument
when nil
None.new
else
raise ArgumentError, "Don't know how to convert #{argument.class} #{argument.inspect} into a MultilineArgument"
end
end
private
def builder
@builder ||= Builder.new
end
class Builder
def wrap(node)
@result = None.new
node.describe_to(self)
@result
end
def doc_string(node, *_args)
@result = DocString.new(node)
end
def data_table(node, *_args)
@result = DataTable.new(node)
end
end
end
class None
def append_to(array); end
def describe_to(visitor); end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/errors.rb | lib/cucumber/errors.rb | # frozen_string_literal: true
require 'cucumber/core/test/result'
module Cucumber
# Raised when there is no matching StepDefinition for a step.
class Undefined < Core::Test::Result::Undefined
def self.from(result, step_name)
return result.with_message(with_prefix(result.message)) if result.is_a?(self)
begin
raise self, with_prefix(step_name)
rescue StandardError => e
e
end
end
def self.with_prefix(step_name)
%(Undefined step: "#{step_name}")
end
end
# Raised when there is no matching StepDefinition for a step called
# from within another step definition.
class UndefinedDynamicStep < StandardError
def initialize(step_name)
super %(Undefined dynamic step: "#{step_name}")
end
end
# Raised when a StepDefinition's block invokes World#pending
class Pending < Core::Test::Result::Pending
end
# Raised when a step matches 2 or more StepDefinitions
class Ambiguous < StandardError
def initialize(step_name, step_definitions, used_guess)
# TODO: [LH] - Just use a heredoc here to fix this up
message = String.new
message << "Ambiguous match of \"#{step_name}\":\n\n"
message << step_definitions.map(&:backtrace_line).join("\n")
message << "\n\n"
message << "You can run again with --guess to make Cucumber be more smart about it\n" unless used_guess
super(message)
end
end
class TagExcess < StandardError
def initialize(messages)
super(messages.join("\n"))
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/step_match_search.rb | lib/cucumber/step_match_search.rb | # frozen_string_literal: true
module Cucumber
module StepMatchSearch
def self.new(search, configuration)
CachesStepMatch.new(
AssertUnambiguousMatch.new(
configuration.guess? ? AttemptToGuessAmbiguousMatch.new(search) : search,
configuration
)
)
end
class AssertUnambiguousMatch
def initialize(search, configuration)
@search = search
@configuration = configuration
end
def call(step_name)
result = @search.call(step_name)
raise Cucumber::Ambiguous.new(step_name, result, @configuration.guess?) if result.length > 1
result
end
end
class AttemptToGuessAmbiguousMatch
def initialize(search)
@search = search
end
def call(step_name)
best_matches(step_name, @search.call(step_name))
end
private
def best_matches(_step_name, step_matches) # :nodoc:
no_groups = step_matches.select { |step_match| step_match.args.empty? }
max_arg_length = step_matches.map { |step_match| step_match.args.length }.max
top_groups = step_matches.select { |step_match| step_match.args.length == max_arg_length }
if no_groups.any?
longest_regexp_length = no_groups.map(&:text_length).max
no_groups.select { |step_match| step_match.text_length == longest_regexp_length }
elsif top_groups.any?
shortest_capture_length = top_groups.map { |step_match| step_match.args.inject(0) { |sum, c| sum + c.to_s.length } }.min
top_groups.select { |step_match| step_match.args.inject(0) { |sum, c| sum + c.to_s.length } == shortest_capture_length }
else
top_groups
end
end
end
require 'delegate'
class CachesStepMatch < SimpleDelegator
def call(step_name) # :nodoc:
@match_cache ||= {}
matches = @match_cache[step_name]
return matches if matches
@match_cache[step_name] = super(step_name)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/hooks.rb | lib/cucumber/hooks.rb | # frozen_string_literal: true
require 'pathname'
require 'cucumber/core/test/location'
require 'cucumber/core/test/around_hook'
module Cucumber
# Hooks quack enough like `Cucumber::Core::Ast` source nodes that we can use them as
# source for test steps
module Hooks
class << self
def before_hook(id, location, &block)
build_hook_step(id, location, block, BeforeHook, Core::Test::Action::Unskippable)
end
def after_hook(id, location, &block)
build_hook_step(id, location, block, AfterHook, Core::Test::Action::Unskippable)
end
def after_step_hook(id, test_step, location, &block)
raise ArgumentError if test_step.hook?
build_hook_step(id, location, block, AfterStepHook, Core::Test::Action::Defined)
end
def around_hook(&block)
Core::Test::AroundHook.new(&block)
end
private
def build_hook_step(id, location, block, hook_type, action_type)
action = action_type.new(location, &block)
hook = hook_type.new(action.location)
Core::Test::HookStep.new(id, hook.text, location, action)
end
end
class AfterHook
attr_reader :location
def initialize(location)
@location = location
end
def text
'After hook'
end
def to_s
"#{text} at #{location}"
end
def match_locations?(queried_locations)
queried_locations.any? { |other_location| other_location.match?(location) }
end
def describe_to(visitor, *args)
visitor.after_hook(self, *args)
end
end
class BeforeHook
attr_reader :location
def initialize(location)
@location = location
end
def text
'Before hook'
end
def to_s
"#{text} at #{location}"
end
def match_locations?(queried_locations)
queried_locations.any? { |other_location| other_location.match?(location) }
end
def describe_to(visitor, *args)
visitor.before_hook(self, *args)
end
end
class AfterStepHook
attr_reader :location
def initialize(location)
@location = location
end
def text
'AfterStep hook'
end
def to_s
"#{text} at #{location}"
end
def match_locations?(queried_locations)
queried_locations.any? { |other_location| other_location.match?(location) }
end
def describe_to(visitor, *args)
visitor.after_step_hook(self, *args)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/query.rb | lib/cucumber/query.rb | # frozen_string_literal: true
require 'cucumber/repository'
# Given one Cucumber Message, find another.
#
# Queries can be made while the test run is incomplete - and this will naturally return incomplete results
# see <a href="https://github.com/cucumber/messages?tab=readme-ov-file#message-overview">Cucumber Messages - Message Overview</a>
#
module Cucumber
class Query
attr_reader :repository
private :repository
def initialize(repository)
@repository = repository
end
# TODO: count methods (1/2) Complete
# Missing: countMostSevereTestStepResultStatus
# TODO: findAll methods (11/12) Complete
# Missing: findAllUndefinedParameterTypes
# TODO: find****By methods (16/25) Complete
# Missing: findLocationOf (1 variant) - This strictly speaking isn't a findBy but is located within them
# Missing: findSuggestionsBy (2 variants)
# Missing: findUnambiguousStepDefinitionBy (1 variant)
# Missing: findTestStepFinishedAndTestStepBy (1 variant)
# Missing: findMostSevereTestStepResultBy (2 variants)
# Missing: findAttachmentsBy (2 variants)
# Missing: findTestCaseDurationBy (2 variant)
# Missing: findLineageBy (9 variants!)
# To Review: findTestRunDuration (1 variant) - This strictly speaking isn't a findBy but is located within them
# Complete: findMeta (1 variant)
# Complete: findTestRunHookStartedBy (1 variant)
# Complete: findTestRunHookFinishedBy (1 variant)
# Complete: findPickleStepBy (1 variant)
# Complete: findStepDefinitionsBy (1 variant)
# Complete: findStepBy (1 variant)
# Complete: findTestRunFinished (1 variant)
# Complete: findTestRunStarted (1 variant)
# Fully Complete (2/2): findTestStepsStartedBy (2 variants)
# Fully Complete (2/2): findTestStepBy (2 variants)
# Fully Complete (3/3): findTestCaseStartedBy (3 variants)
# Fully Complete (1/1): findTestCaseFinishedBy (1 variant)
# Fully Complete (4/4): findTestCaseBy (4 variants)
# Fully Complete (5/5): findPickleBy (5 variants)
# Fully Complete (3/3): findHookBy (3 variants)
# Fully Complete (2/2): findTestStepsFinishedBy (2 variants)
def count_test_cases_started
find_all_test_case_started.length
end
def find_all_pickles
repository.pickle_by_id.values
end
def find_all_pickle_steps
repository.pickle_step_by_id.values
end
def find_all_step_definitions
repository.step_definition_by_id.values
end
# This finds all test cases from the following conditions (UNION)
# -> Test cases that have started, but not yet finished
# -> Test cases that have started, finished, but that will NOT be retried
def find_all_test_case_started
repository.test_case_started_by_id.values.select do |test_case_started|
test_case_finished = find_test_case_finished_by(test_case_started)
test_case_finished.nil? || !test_case_finished.will_be_retried
end
end
# This finds all test cases that have finished AND will not be retried
def find_all_test_case_finished
repository.test_case_finished_by_test_case_started_id.values.reject(&:will_be_retried)
end
def find_all_test_cases
repository.test_case_by_id.values
end
def find_all_test_run_hook_started
repository.test_run_hook_started_by_id.values
end
def find_all_test_run_hook_finished
repository.test_run_hook_finished_by_test_run_hook_started_id.values
end
def find_all_test_step_started
repository.test_steps_started_by_test_case_started_id.values.flatten
end
def find_all_test_step_finished
repository.test_steps_finished_by_test_case_started_id.values.flatten
end
def find_all_test_steps
repository.test_step_by_id.values
end
# This method will be called with 1 of these 3 messages
# [TestStep || TestRunHookStarted || TestRunHookFinished]
def find_hook_by(message)
ensure_only_message_types!(message, %i[test_step test_run_hook_started test_run_hook_finished], '#find_hook_by')
if message.is_a?(Cucumber::Messages::TestRunHookFinished)
test_run_hook_started_message = find_test_run_hook_started_by(message)
test_run_hook_started_message ? find_hook_by(test_run_hook_started_message) : nil
else
repository.hook_by_id[message.hook_id]
end
end
def find_meta
repository.meta
end
# This method will be called with 1 of these 5 messages
# [TestCase || TestCaseStarted || TestCaseFinished || TestStepStarted || TestStepFinished]
def find_pickle_by(message)
ensure_only_message_types!(message, %i[test_case test_case_started test_case_finished test_step_started test_step_finished], '#find_pickle_by')
test_case_message = message.is_a?(Cucumber::Messages::TestCase) ? message : find_test_case_by(message)
repository.pickle_by_id[test_case_message.pickle_id]
end
# This method will be called with only 1 message
# [TestStep]
def find_pickle_step_by(test_step)
ensure_only_message_types!(test_step, %i[test_step], '#find_pickle_step_by')
repository.pickle_step_by_id[test_step.pickle_step_id]
end
# This method will be called with only 1 message
# [PickleStep]
def find_step_by(pickle_step)
ensure_only_message_types!(pickle_step, %i[pickle_step], '#find_step_by')
repository.step_by_id[pickle_step.ast_node_ids.first]
end
# This method will be called with only 1 message
# [TestStep]
def find_step_definitions_by(test_step)
ensure_only_message_types!(test_step, %i[test_step], '#find_step_definitions_by')
ids = test_step.step_definition_ids.nil? ? [] : test_step.step_definition_ids
ids.map { |id| repository.step_definition_by_id[id] }.compact
end
# This method will be called with 1 of these 4 messages
# [TestCaseStarted || TestCaseFinished || TestStepStarted || TestStepFinished]
def find_test_case_by(message)
ensure_only_message_types!(message, %i[test_case_started test_case_finished test_step_started test_step_finished], '#find_test_case_by')
test_case_started_message = message.is_a?(Cucumber::Messages::TestCaseStarted) ? message : find_test_case_started_by(message)
repository.test_case_by_id[test_case_started_message.test_case_id]
end
# This method will be called with 1 of these 3 messages
# [TestCaseFinished || TestStepStarted || TestStepFinished]
def find_test_case_started_by(message)
ensure_only_message_types!(message, %i[test_case_finished test_step_started test_step_finished], '#find_test_case_started_by')
repository.test_case_started_by_id[message.test_case_started_id]
end
# This method will be called with only 1 message
# [TestCaseStarted]
def find_test_case_finished_by(test_case_started)
ensure_only_message_types!(test_case_started, %i[test_case_started], '#find_test_case_finished_by')
repository.test_case_finished_by_test_case_started_id[test_case_started.id]
end
def find_test_run_duration
if repository.test_run_started.nil? || repository.test_run_finished.nil?
nil
else
timestamp_to_time(repository.test_run_finished.timestamp) - timestamp_to_time(repository.test_run_started.timestamp)
end
end
# This method will be called with only 1 message
# [TestRunHookFinished]
def find_test_run_hook_started_by(test_run_hook_finished)
ensure_only_message_types!(test_run_hook_finished, %i[test_run_hook_finished], '#find_test_run_hook_started_by')
repository.test_run_hook_started_by_id[test_run_hook_finished.test_run_hook_started_id]
end
# This method will be called with only 1 message
# [TestRunHookStarted]
def find_test_run_hook_finished_by(test_run_hook_started)
ensure_only_message_types!(test_run_hook_started, %i[test_run_hook_started], '#find_test_run_hook_finished_by')
repository.test_run_hook_finished_by_test_run_hook_started_id[test_run_hook_started.id]
end
def find_test_run_started
repository.test_run_started
end
def find_test_run_finished
repository.test_run_finished
end
# This method will be called with 1 of these 2 messages
# [TestStepStarted || TestStepFinished]
def find_test_step_by(message)
ensure_only_message_types!(message, %i[test_case_started test_case_finished], '#find_test_step_by')
repository.test_step_by_id[message.test_step_id]
end
# This method will be called with 1 of these 2 messages
# [TestCaseStarted || TestCaseFinished]
def find_test_steps_started_by(message)
ensure_only_message_types!(message, %i[test_case_started test_case_finished], '#find_test_steps_started_by')
key = message.is_a?(Cucumber::Messages::TestCaseStarted) ? message.id : message.test_case_started_id
repository.test_steps_started_by_test_case_started_id.fetch(key, [])
end
# This method will be called with 1 of these 2 messages
# [TestCaseStarted || TestCaseFinished]
def find_test_steps_finished_by(message)
ensure_only_message_types!(message, %i[test_case_started test_case_finished], '#find_test_steps_finished_by')
if message.is_a?(Cucumber::Messages::TestCaseStarted)
test_steps_finished_by_test_case_started_id.fetch(message.id, [])
else
test_case_started_message = find_test_case_started_by(message)
test_case_started_message.nil? ? [] : find_test_steps_finished_by(test_case_started_message)
end
end
private
def ensure_only_message_types!(supplied_message, permissible_message_types, method_name)
raise ArgumentError, "Supplied argument is not a Cucumber Message. Argument: #{supplied_message.class}" unless supplied_message.is_a?(Cucumber::Messages::Message)
permitted_klasses = permissible_message_types.map { |message| message_types[message] }
raise ArgumentError, "Supplied message type '#{supplied_message.class}' is not permitted to be used when calling #{method_name}" unless permitted_klasses.include?(supplied_message.class)
end
def message_types
{
pickle_step: Cucumber::Messages::PickleStep,
test_case: Cucumber::Messages::TestCase,
test_case_started: Cucumber::Messages::TestCaseStarted,
test_case_finished: Cucumber::Messages::TestCaseFinished,
test_run_hook_started: Cucumber::Messages::TestRunHookStarted,
test_run_hook_finished: Cucumber::Messages::TestRunHookFinished,
test_step: Cucumber::Messages::TestStep,
test_step_started: Cucumber::Messages::TestStepStarted,
test_step_finished: Cucumber::Messages::TestStepFinished
}
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/encoding.rb | lib/cucumber/encoding.rb | # frozen_string_literal: true
# See https://github.com/cucumber/cucumber/issues/693
if defined? Encoding
Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8'
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/configuration.rb | lib/cucumber/configuration.rb | # frozen_string_literal: true
require 'cucumber/constantize'
require 'cucumber/cli/rerun_file'
require 'cucumber/events'
require 'cucumber/messages'
require 'cucumber/core/event_bus'
require 'cucumber/core/test/result'
require 'forwardable'
require 'cucumber'
module Cucumber
# The base class for configuring settings for a Cucumber run.
class Configuration
include Constantize
extend Forwardable
def self.default
new
end
# Subscribe to an event.
#
# See {Cucumber::Events} for the list of possible events.
#
# @param event_id [Symbol, Class, String] Identifier for the type of event to subscribe to
# @param handler_object [Object optional] an object to be called when the event occurs
# @yield [Object] Block to be called when the event occurs
# @method on_event
def_instance_delegator :event_bus, :on, :on_event
# @private
def notify(message, *args)
event_bus.send(message, *args)
end
def initialize(user_options = {})
@options = default_options.merge(Hash(user_options))
end
def with_options(new_options)
self.class.new(@options.merge(new_options))
end
def out_stream
@options[:out_stream]
end
def error_stream
@options[:error_stream]
end
def randomize?
@options[:order] == 'random'
end
def seed
@options[:seed]
end
def dry_run?
@options[:dry_run]
end
def publish_enabled?
@options[:publish_enabled]
end
def publish_quiet?
@options[:publish_quiet]
end
def fail_fast?
@options[:fail_fast]
end
def retry_attempts
@options[:retry]
end
def retry_total_tests
@options[:retry_total]
end
def guess?
@options[:guess]
end
def strict
@options[:strict]
end
def wip?
@options[:wip]
end
def expand?
@options[:expand]
end
def source?
@options[:source]
end
def duration?
@options[:duration]
end
def snippets?
@options[:snippets]
end
def skip_profile_information?
@options[:skip_profile_information]
end
def profiles
@options[:profiles] || []
end
def custom_profiles
profiles - [@options[:default_profile]]
end
def paths
@options[:paths]
end
def formats
@options[:formats]
end
def autoload_code_paths
@options[:autoload_code_paths]
end
def snippet_type
@options[:snippet_type]
end
def feature_dirs
dirs = paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
dirs.delete('.') unless paths.include?('.')
with_default_features_path(dirs)
end
def tag_limits
@options[:tag_limits]
end
def tag_expressions
@options[:tag_expressions]
end
def name_regexps
@options[:name_regexps]
end
def filters
@options[:filters]
end
def feature_files
potential_feature_files = with_default_features_path(paths).map do |path|
path = path.tr('\\', '/') # In case we're on windows. Globs don't work with backslashes.
path = path.chomp('/')
# TODO: Move to using feature loading strategies stored in
# options[:feature_loaders]
if File.directory?(path)
Dir["#{path}/**/*.feature"].sort
elsif Cli::RerunFile.can_read?(path)
Cli::RerunFile.new(path).features
else
path
end
end.flatten.uniq
remove_excluded_files_from(potential_feature_files)
potential_feature_files
end
def support_to_load
support_files = all_files_to_load.select { |f| f =~ /\/support\// }
# env_files are separated from other_files so we can ensure env files
# load first.
#
env_files = support_files.select { |f| f =~ /\/support\/env\..*/ }
other_files = support_files - env_files
env_files.reverse + other_files.reverse
end
def all_files_to_load
files = require_dirs.map do |path|
path = path.tr('\\', '/') # In case we're on windows. Globs don't work with backslashes.
path = path.gsub(/\/$/, '') # Strip trailing slash.
File.directory?(path) ? Dir["#{path}/**/*"] : path
end.flatten.uniq
remove_excluded_files_from(files)
files.select! { |f| File.file?(f) }
files.reject! { |f| File.extname(f) == '.feature' }
files.reject! { |f| f =~ /^http/ }
files.sort
end
def step_defs_to_load
all_files_to_load.reject { |f| f =~ /\/support\// }
end
def formatter_factories
formats.map do |format, formatter_options, path_or_io|
factory = formatter_class(format)
yield factory,
formatter_options,
path_or_io
rescue Exception => e
raise e, "#{e.message}\nError creating formatter: #{format}", e.backtrace
end
end
def formatter_class(format)
if (builtin = Cli::Options::BUILTIN_FORMATS[format])
constantize(builtin[0])
else
constantize(format)
end
end
def to_hash
@options
end
# An array of procs that can generate snippets for undefined steps. These procs may be called if a
# formatter wants to display snippets to the user.
#
# Each proc should take the following arguments:
#
# - keyword
# - step text
# - multiline argument
# - snippet type
#
def snippet_generators
@options[:snippet_generators] ||= []
end
def register_snippet_generator(generator)
snippet_generators << generator
self
end
def event_bus
@options[:event_bus]
end
def id_generator
@id_generator ||= Cucumber::Messages::Helpers::IdGenerator::UUID.new
end
private
def default_options
{
autoload_code_paths: ['features/support', 'features/step_definitions'],
filters: [],
strict: Cucumber::Core::Test::Result::StrictConfiguration.new,
require: [],
dry_run: false,
publish_quiet: false,
fail_fast: false,
formats: [],
excludes: [],
tag_expressions: [],
name_regexps: [],
env_vars: {},
diff_enabled: true,
snippets: true,
source: true,
duration: true,
event_bus: Cucumber::Events.make_event_bus,
retry_total: Float::INFINITY
}
end
def default_features_paths
['features']
end
def with_default_features_path(paths)
return default_features_paths if paths.empty?
paths
end
def remove_excluded_files_from(files)
files.reject! { |path| @options[:excludes].detect { |pattern| path =~ pattern } }
end
def require_dirs
if @options[:require].empty?
default_features_paths + Dir['vendor/{gems,plugins}/*/cucumber']
else
@options[:require]
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/load_path.rb | lib/cucumber/load_path.rb | # frozen_string_literal: true
module Cucumber
module LoadPath
def add_dirs(*dirs)
dirs.each do |dir|
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
end
end
module_function :add_dirs
end
end
Cucumber::LoadPath.add_dirs('lib')
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/constantize.rb | lib/cucumber/constantize.rb | # frozen_string_literal: true
require 'cucumber/platform'
module Cucumber
module Constantize # :nodoc:
def constantize(camel_cased_word)
try = 0
begin
try += 1
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = ::Object
names.each do |name|
constant = constantize_name(constant, name)
end
constant
rescue NameError => e
require underscore(camel_cased_word)
retry if try < 2
raise e
end
end
# Snagged from active_support
def underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/')
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr('-', '_')
.downcase
end
private
def constantize_name(constant, name)
if constant.const_defined?(name, false)
constant.const_get(name, false)
else
constant.const_missing(name)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/step_definitions.rb | lib/cucumber/step_definitions.rb | # frozen_string_literal: true
module Cucumber
class StepDefinitions
def initialize(configuration = Configuration.default)
configuration = Configuration.new(configuration)
@support_code = Runtime::SupportCode.new(nil, configuration)
@support_code.load_files_from_paths(configuration.autoload_code_paths)
end
def to_json(obj = nil)
@support_code.step_definitions.map(&:to_hash).to_json(obj)
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime.rb | lib/cucumber/runtime.rb | # frozen_string_literal: true
require 'fileutils'
require 'cucumber/configuration'
require 'cucumber/load_path'
require 'cucumber/formatter/duration'
require 'cucumber/file_specs'
require 'cucumber/filters'
require 'cucumber/formatter/fanout'
require 'cucumber/gherkin/i18n'
require 'cucumber/glue/registry_wrapper'
require 'cucumber/step_match_search'
require 'cucumber/messages'
require 'cucumber/runtime/meta_message_builder'
require 'sys/uname'
module Cucumber
module FixRuby21Bug9285
def message
String(super).gsub('@ rb_sysopen ', '')
end
end
class FileException < RuntimeError
attr_reader :path
def initialize(original_exception, path)
@path = path
super(original_exception)
end
end
class FileNotFoundException < FileException
end
class FeatureFolderNotFoundException < RuntimeError
def initialize(path)
@path = path
super
end
def message
"No such file or directory - #{@path}"
end
end
require 'cucumber/core'
require 'cucumber/runtime/user_interface'
require 'cucumber/runtime/support_code'
class Runtime
attr_reader :results, :support_code, :configuration
include Cucumber::Core
include Formatter::Duration
include Runtime::UserInterface
def initialize(configuration = Configuration.default)
@configuration = Configuration.new(configuration)
@support_code = SupportCode.new(self, @configuration)
end
# Allows you to take an existing runtime and change its configuration
def configure(new_configuration)
@configuration = Configuration.new(new_configuration)
@support_code.configure(@configuration)
end
def run!
@configuration.notify :envelope, Cucumber::Messages::Envelope.new(
meta: MetaMessageBuilder.build_meta_message
)
load_step_definitions
fire_install_plugin_hook
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, !failure?
fire_after_all_hook unless dry_run?
end
def features_paths
@configuration.paths
end
def dry_run?
@configuration.dry_run?
end
def unmatched_step_definitions
@support_code.unmatched_step_definitions
end
def begin_scenario(test_case)
@support_code.fire_hook(:begin_scenario, test_case)
end
def end_scenario(_scenario)
@support_code.fire_hook(:end_scenario)
end
# Returns Ast::DocString for +string_without_triple_quotes+.
#
def doc_string(string_without_triple_quotes, content_type = '', _line_offset = 0)
Core::Test::DocString.new(string_without_triple_quotes, content_type)
end
def failure?
if @configuration.wip?
summary_report.test_cases.total_passed.positive?
else
!summary_report.ok?(strict: @configuration.strict)
end
end
private
def fire_install_plugin_hook # :nodoc:
@support_code.fire_hook(:install_plugin, @configuration, registry_wrapper)
end
def fire_before_all_hook # :nodoc:
@support_code.fire_hook(:before_all)
end
def fire_after_all_hook # :nodoc:
@support_code.fire_hook(:after_all)
end
require 'cucumber/core/gherkin/document'
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
def feature_files
filespecs.files
end
def filespecs
@filespecs ||= FileSpecs.new(@configuration.feature_files)
end
class NormalisedEncodingFile
COMMENT_OR_EMPTY_LINE_PATTERN = /^\s*#|^\s*$/.freeze # :nodoc:
ENCODING_PATTERN = /^\s*#\s*encoding\s*:\s*([^\s]+)/.freeze # :nodoc:
def self.read(path)
new(path).read
end
def initialize(path)
@file = File.new(path)
set_encoding
rescue Errno::EACCES => e
raise FileNotFoundException.new(e, File.expand_path(path))
rescue Errno::ENOENT
raise FeatureFolderNotFoundException, path
end
def read
@file.read.encode('UTF-8')
end
private
def set_encoding
@file.each do |line|
if ENCODING_PATTERN =~ line
@file.set_encoding Regexp.last_match(1)
break
end
break unless COMMENT_OR_EMPTY_LINE_PATTERN =~ line
end
@file.rewind
end
end
require 'cucumber/formatter/ignore_missing_messages'
require 'cucumber/formatter/fail_fast'
require 'cucumber/formatter/publish_banner_printer'
require 'cucumber/core/report/summary'
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
def summary_report
@summary_report ||= Core::Report::Summary.new(@configuration.event_bus)
end
def fail_fast_report
@fail_fast_report ||= Formatter::FailFast.new(@configuration)
end
def publish_banner_printer
@publish_banner_printer ||= Formatter::PublishBannerPrinter.new(@configuration)
end
def formatters
@formatters ||=
@configuration.formatter_factories do |factory, formatter_options, path_or_io|
create_formatter(factory, formatter_options, path_or_io)
end
end
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
def accept_options?(factory)
factory.instance_method(:initialize).arity > 1
end
require 'cucumber/core/test/filters'
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 { |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)
filters << Filters::BroadcastTestRunStartedEvent.new(@configuration)
filters << Filters::Quit.new
end
filters << Filters::BroadcastTestCaseReadyEvent.new(@configuration)
unless configuration.dry_run?
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
def load_step_definitions
files = @configuration.support_to_load + @configuration.step_defs_to_load
@support_code.load_files!(files)
end
def registry_wrapper
Cucumber::Glue::RegistryWrapper.new(@support_code.registry)
end
def log
Cucumber.logger
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/filters.rb | lib/cucumber/filters.rb | # frozen_string_literal: true
require 'cucumber/filters/activate_steps'
require 'cucumber/filters/apply_after_step_hooks'
require 'cucumber/filters/apply_before_hooks'
require 'cucumber/filters/apply_after_hooks'
require 'cucumber/filters/apply_around_hooks'
require 'cucumber/filters/broadcast_test_run_started_event'
require 'cucumber/filters/prepare_world'
require 'cucumber/filters/quit'
require 'cucumber/filters/randomizer'
require 'cucumber/filters/retry'
require 'cucumber/filters/tag_limits'
require 'cucumber/filters/broadcast_test_case_ready_event'
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/file_specs.rb | lib/cucumber/file_specs.rb | # frozen_string_literal: true
require 'cucumber'
require 'cucumber/core/test/location'
module Cucumber
class FileSpecs
FILE_COLON_LINE_PATTERN = /^([\w\W]*?)(?::([\d:]+))?$/.freeze # :nodoc:
def initialize(file_specs)
Cucumber.logger.debug("Features:\n")
@file_specs = file_specs.map { |spec| FileSpec.new(spec) }
Cucumber.logger.debug("\n")
end
def locations
@file_specs.map(&:locations).flatten
end
def files
@file_specs.map(&:file).uniq
end
class FileSpec
def initialize(spec)
@file, @lines = *FILE_COLON_LINE_PATTERN.match(spec).captures
Cucumber.logger.debug(" * #{@file}\n")
@lines = String(@lines).split(':').map { |line| Integer(line) }
end
attr_reader :file
def locations
return [Core::Test::Location.new(@file)] if @lines.empty?
@lines.map { |line| Core::Test::Location.new(@file, line) }
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/project_initializer.rb | lib/cucumber/project_initializer.rb | # frozen_string_literal: true
module Cucumber
# Generates generic file structure for a cucumber project
class ProjectInitializer
def run
create_directory('features')
create_directory('features/step_definitions')
create_directory('features/support')
create_file('features/support/env.rb')
end
private
def create_directory(directory_name)
create_directory_or_file(directory_name, command: :mkdir_p)
end
def create_file(filename)
create_directory_or_file(filename, command: :touch)
end
def create_directory_or_file(name, command:)
if File.exist?(name)
puts "#{name} already exists"
else
puts "creating #{name}"
FileUtils.send(command, name)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/step_definition_light.rb | lib/cucumber/step_definition_light.rb | # frozen_string_literal: true
module Cucumber
# TODO: pointless, ancient, kill with fire.
# Only used for keeping track of available and invoked step definitions
# in a way that also works for other programming languages (i.e. cuke4duke)
# Used for reporting purposes only (usage formatter).
class StepDefinitionLight
attr_reader :regexp_source, :location
def initialize(regexp_source, location)
@regexp_source = regexp_source
@location = location
Cucumber.deprecate(
'StepDefinitionLight class is no longer a supported part of cucumber',
'#initialize',
'11.0.0'
)
end
def eql?(other)
regexp_source == other.regexp_source && location == other.location
end
def hash
regexp_source.hash + 31 * location.to_s.hash
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/step_match.rb | lib/cucumber/step_match.rb | # frozen_string_literal: true
require 'cucumber/multiline_argument'
module Cucumber
# Represents the match found between a Test Step and its activation
class StepMatch # :nodoc:
attr_reader :step_definition, :step_arguments
def initialize(step_definition, step_name, step_arguments)
raise "step_arguments can't be nil (but it can be an empty array)" if step_arguments.nil?
@step_definition = step_definition
@name_to_match = step_name
@step_arguments = step_arguments
end
def args
current_world = @step_definition.registry.current_world
@step_arguments.map do |arg|
arg.value(current_world)
end
end
def activate(test_step)
test_step.with_action(@step_definition.location) do
invoke(MultilineArgument.from_core(test_step.multiline_arg))
end
end
def invoke(multiline_arg)
all_args = args
multiline_arg.append_to(all_args)
@step_definition.invoke(all_args)
end
# Formats the matched arguments of the associated Step. This method
# is usually called from visitors, which render output.
#
# The +format+ can either be a String or a Proc.
#
# If it is a String it should be a format string according to
# <tt>Kernel#sprinf</tt>, for example:
#
# '<span class="param">%s</span></tt>'
#
# If it is a Proc, it should take one argument and return the formatted
# argument, for example:
#
# lambda { |param| "[#{param}]" }
#
def format_args(format = ->(a) { a }, &proc)
replace_arguments(@name_to_match, @step_arguments, format, &proc)
end
def location
@step_definition.location
end
def file_colon_line
location.to_s
end
def backtrace_line
"#{file_colon_line}:in `#{@step_definition.expression}'"
end
def text_length
@step_definition.expression.source.to_s.unpack('U*').length
end
def replace_arguments(string, step_arguments, format)
s = string.dup
offset = past_offset = 0
step_arguments.each do |step_argument|
group = step_argument.group
next if group.value.nil? || group.start < past_offset
replacement = if block_given?
yield(group.value)
elsif format.instance_of?(Proc)
format.call(group.value)
else
format % group.value
end
s[group.start + offset, group.value.length] = replacement
offset += replacement.unpack('U*').length - group.value.unpack('U*').length
past_offset = group.start + group.value.length
end
s
end
def inspect # :nodoc:
"#<#{self.class}: #{location}>"
end
end
class SkippingStepMatch
def activate(test_step)
test_step.with_action { raise Core::Test::Result::Skipped }
end
end
class NoStepMatch # :nodoc:
attr_reader :step_definition, :name
def initialize(step, name)
@step = step
@name = name
end
def format_args(*_args)
@name
end
def location
raise "No location for #{@step}" unless @step.location
@step.location
end
def file_colon_line
location.to_s
end
def backtrace_line
@step.backtrace_line
end
def text_length
@step.text.length
end
def step_arguments
[]
end
def activate(test_step)
# noop
test_step
end
end
class AmbiguousStepMatch
def initialize(error)
@error = error
end
def activate(test_step)
test_step.with_action { raise @error }
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/rspec/doubles.rb | lib/cucumber/rspec/doubles.rb | # frozen_string_literal: true
require 'rspec/mocks'
World(RSpec::Mocks::ExampleMethods)
Before do
if RSpec::Mocks::Version::STRING >= '2.9.9'
RSpec::Mocks.setup
else
RSpec::Mocks.setup(self)
end
end
After do
RSpec::Mocks.verify
ensure
RSpec::Mocks.teardown
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/rspec/disable_option_parser.rb | lib/cucumber/rspec/disable_option_parser.rb | # frozen_string_literal: true
require 'optparse'
module Spec # :nodoc:
module Runner # :nodoc:
# Neuters RSpec's option parser.
# (RSpec's option parser tries to parse ARGV, which
# will fail when running cucumber)
class OptionParser < ::OptionParser # :nodoc:
NEUTERED_RSPEC = Object.new
def NEUTERED_RSPEC.method_missing(_method, *_args) # rubocop:disable Style/MissingRespondToMissing
self || super
end
def self.method_added(method)
return if @__neutering_rspec
@__neutering_rspec = true
define_method(method) do |*_a|
NEUTERED_RSPEC
end
@__neutering_rspec = false
super
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/multiline_argument/data_table.rb | lib/cucumber/multiline_argument/data_table.rb | # frozen_string_literal: true
require 'forwardable'
require 'cucumber/gherkin/data_table_parser'
require 'cucumber/gherkin/formatter/escaping'
require 'cucumber/multiline_argument/data_table/diff_matrices'
module Cucumber
module MultilineArgument
# Step Definitions that match a plain text Step with a multiline argument table
# will receive it as an instance of Table. A Table object holds the data of a
# table parsed from a feature file and lets you access and manipulate the data
# in different ways.
#
# For example:
#
# Given I have:
# | a | b |
# | c | d |
#
# And a matching StepDefinition:
#
# Given /I have:/ do |table|
# data = table.raw
# end
#
# This will store <tt>[['a', 'b'], ['c', 'd']]</tt> in the <tt>data</tt> variable.
#
class DataTable
def self.default_arg_name
'table'
end
def describe_to(visitor, *args)
visitor.legacy_table(self, *args)
end
class << self
def from(data)
case data
when Array
from_array(data)
when String
parse(data)
else
raise ArgumentError, 'expected data to be a String or an Array.'
end
end
private
def parse(text)
builder = Builder.new
parser = Cucumber::Gherkin::DataTableParser.new(builder)
parser.parse(text)
from_array(builder.rows)
end
def from_array(data)
new Core::Test::DataTable.new(data)
end
end
class Builder
attr_reader :rows
def initialize
@rows = []
end
def row(row)
@rows << row
end
def eof; end
end
# This is a Hash being initialized with a default value of a Hash
# DO NOT REFORMAT TO REMOVE {} - Ruby 3.4+ will interpret these as keywords and cucumber will not work
NULL_CONVERSIONS = Hash.new({ strict: false, proc: ->(cell_value) { cell_value } }).freeze
# @param data [Core::Test::DataTable] the data for the table
# @param conversion_procs [Hash] see map_column
# @param header_mappings [Hash] see map_headers
# @param header_conversion_proc [Proc] see map_headers
def initialize(data, conversion_procs = NULL_CONVERSIONS.dup, header_mappings = {}, header_conversion_proc = nil)
raise ArgumentError, 'data must be a Core::Test::DataTable' unless data.is_a? Core::Test::DataTable
ast_table = data
# Verify that it's square
ast_table.transpose
@cell_matrix = create_cell_matrix(ast_table)
@conversion_procs = conversion_procs
@header_mappings = header_mappings
@header_conversion_proc = header_conversion_proc
@ast_table = ast_table
end
def append_to(array)
array << self
end
def to_step_definition_arg
dup
end
attr_accessor :file
def location
@ast_table.location
end
# Returns a new, transposed table. Example:
#
# | a | 7 | 4 |
# | b | 9 | 2 |
#
# Gets converted into the following:
#
# | a | b |
# | 7 | 9 |
# | 4 | 2 |
#
def transpose
self.class.new(Core::Test::DataTable.new(raw.transpose), @conversion_procs.dup, @header_mappings.dup, @header_conversion_proc)
end
# Converts this table into an Array of Hash where the keys of each
# Hash are the headers in the table. For example, a Table built from
# the following plain text:
#
# | a | b | sum |
# | 2 | 3 | 5 |
# | 7 | 9 | 16 |
#
# Gets converted into the following:
#
# [{'a' => '2', 'b' => '3', 'sum' => '5'}, {'a' => '7', 'b' => '9', 'sum' => '16'}]
#
# Use #map_column to specify how values in a column are converted.
#
def hashes
@hashes ||= build_hashes
end
# Converts this table into an Array of Hashes where the keys are symbols.
# For example, a Table built from the following plain text:
#
# | foo | Bar | Foo Bar |
# | 2 | 3 | 5 |
# | 7 | 9 | 16 |
#
# Gets converted into the following:
#
# [{:foo => '2', :bar => '3', :foo_bar => '5'}, {:foo => '7', :bar => '9', :foo_bar => '16'}]
#
def symbolic_hashes
@symbolic_hashes ||=
hashes.map do |string_hash|
string_hash.transform_keys { |a| symbolize_key(a) }
end
end
# Converts this table into a Hash where the first column is
# used as keys and the second column is used as values
#
# | a | 2 |
# | b | 3 |
#
# Gets converted into the following:
#
# {'a' => '2', 'b' => '3'}
#
# The table must be exactly two columns wide
#
def rows_hash
return @rows_hash if @rows_hash
verify_table_width(2)
@rows_hash = transpose.hashes[0]
end
# Gets the raw data of this table. For example, a Table built from
# the following plain text:
#
# | a | b |
# | c | d |
#
# gets converted into the following:
#
# [['a', 'b'], ['c', 'd']]
#
def raw
cell_matrix.map do |row|
row.map(&:value)
end
end
def column_names
@column_names ||= cell_matrix[0].map(&:value)
end
def rows
hashes.map do |hash|
hash.values_at(*headers)
end
end
def each_cells_row(&proc)
cells_rows.each(&proc)
end
# Matches +pattern+ against the header row of the table.
# This is used especially for argument transforms.
#
# Example:
# | column_1_name | column_2_name |
# | x | y |
#
# table.match(/table:column_1_name,column_2_name/) #=> non-nil
#
# Note: must use 'table:' prefix on match
def match(pattern)
header_to_match = "table:#{headers.join(',')}"
pattern.match(header_to_match)
end
# Returns a new Table where the headers are redefined.
# This makes it possible to use
# prettier and more flexible header names in the features. The
# keys of +mappings+ are Strings or regular expressions
# (anything that responds to #=== will work) that may match
# column headings in the table. The values of +mappings+ are
# desired names for the columns.
#
# Example:
#
# | Phone Number | Address |
# | 123456 | xyz |
# | 345678 | abc |
#
# A StepDefinition receiving this table can then map the columns
# with both Regexp and String:
#
# table.map_headers(/phone( number)?/i => :phone, 'Address' => :address)
# table.hashes
# # => [{:phone => '123456', :address => 'xyz'}, {:phone => '345678', :address => 'abc'}]
#
# You may also pass in a block if you wish to convert all of the headers:
#
# table.map_headers { |header| header.downcase }
# table.hashes.keys
# # => ['phone number', 'address']
#
# When a block is passed in along with a hash then the mappings in the hash take precendence:
#
# table.map_headers('Address' => 'ADDRESS') { |header| header.downcase }
# table.hashes.keys
# # => ['phone number', 'ADDRESS']
#
def map_headers(mappings = {}, &block)
self.class.new(Core::Test::DataTable.new(raw), @conversion_procs.dup, mappings, block)
end
# Returns a new Table with an additional column mapping.
#
# Change how #hashes converts column values. The +column_name+ argument identifies the column
# and +conversion_proc+ performs the conversion for each cell in that column. If +strict+ is
# true, an error will be raised if the column named +column_name+ is not found. If +strict+
# is false, no error will be raised. Example:
#
# Given /^an expense report for (.*) with the following posts:$/ do |table|
# posts_table = posts_table.map_column('amount') { |a| a.to_i }
# posts_table.hashes.each do |post|
# # post['amount'] is a Fixnum, rather than a String
# end
# end
#
def map_column(column_name, strict: true, &conversion_proc)
conversion_procs = @conversion_procs.dup
conversion_procs[column_name.to_s] = { strict: strict, proc: conversion_proc }
self.class.new(Core::Test::DataTable.new(raw), conversion_procs, @header_mappings.dup, @header_conversion_proc)
end
# Compares +other_table+ to self. If +other_table+ contains columns
# and/or rows that are not in self, new columns/rows are added at the
# relevant positions, marking the cells in those rows/columns as
# <tt>surplus</tt>. Likewise, if +other_table+ lacks columns and/or
# rows that are present in self, these are marked as <tt>missing</tt>.
#
# <tt>surplus</tt> and <tt>missing</tt> cells are recognised by formatters
# and displayed so that it's easy to read the differences.
#
# Cells that are different, but <em>look</em> identical (for example the
# boolean true and the string "true") are converted to their Object#inspect
# representation and preceded with (i) - to make it easier to identify
# where the difference actually is.
#
# Since all tables that are passed to StepDefinitions always have String
# objects in their cells, you may want to use #map_column before calling
# #diff!. You can use #map_column on either of the tables.
#
# A Different error is raised if there are missing rows or columns, or
# surplus rows. An error is <em>not</em> raised for surplus columns. An
# error is <em>not</em> raised for misplaced (out of sequence) columns.
# Whether to raise or not raise can be changed by setting values in
# +options+ to true or false:
#
# * <tt>missing_row</tt> : Raise on missing rows (defaults to true)
# * <tt>surplus_row</tt> : Raise on surplus rows (defaults to true)
# * <tt>missing_col</tt> : Raise on missing columns (defaults to true)
# * <tt>surplus_col</tt> : Raise on surplus columns (defaults to false)
# * <tt>misplaced_col</tt> : Raise on misplaced columns (defaults to false)
#
# The +other_table+ argument can be another Table, an Array of Array or
# an Array of Hash (similar to the structure returned by #hashes).
#
# Calling this method is particularly useful in <tt>Then</tt> steps that take
# a Table argument, if you want to compare that table to some actual values.
#
def diff!(other_table, options = {})
other_table = ensure_table(other_table)
other_table.convert_headers!
other_table.convert_columns!
convert_headers!
convert_columns!
DiffMatrices.new(cell_matrix, other_table.cell_matrix, options).call
end
class Different < StandardError
attr_reader :table
def initialize(table)
@table = table
super("Tables were not identical:\n#{table}")
end
end
def to_hash
cells_rows.map { |cells| cells.map(&:value) }
end
def cells_to_hash(cells)
hash = Hash.new do |hash_inner, key|
hash_inner[key.to_s] if key.is_a?(Symbol)
end
column_names.each_with_index do |column_name, column_index|
hash[column_name] = cells.value(column_index)
end
hash
end
def index(cells)
cells_rows.index(cells)
end
def verify_column(column_name)
raise %(The column named "#{column_name}" does not exist) unless raw[0].include?(column_name)
end
def verify_table_width(width)
raise %(The table must have exactly #{width} columns) unless raw[0].size == width
end
# TODO: remove the below function if it's not actually being used.
# Nothing else in this repo calls it.
def text?(text)
Cucumber.deprecate(
'This method is no longer supported for checking text',
'#text?',
'11.0.0'
)
raw.flatten.compact.detect { |cell_value| cell_value.index(text) }
end
def cells_rows
@rows ||= cell_matrix.map do |cell_row|
Cells.new(self, cell_row)
end
end
def headers
raw.first
end
def header_cell(col)
cells_rows[0][col]
end
attr_reader :cell_matrix
def col_width(col)
columns[col].__send__(:width)
end
def to_s(options = {})
indentation = options.key?(:indent) ? options[:indent] : 2
prefixes = options.key?(:prefixes) ? options[:prefixes] : TO_S_PREFIXES
DataTablePrinter.new(self, indentation, prefixes).to_s
end
class DataTablePrinter
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :data_table, :indentation, :prefixes
private :data_table, :indentation, :prefixes
def initialize(data_table, indentation, prefixes)
@data_table = data_table
@indentation = indentation
@prefixes = prefixes
end
def to_s
leading_row = "\n"
end_indentation = indentation - 2
trailing_row = "\n#{' ' * end_indentation}"
table_rows = data_table.cell_matrix.map { |row| format_row(row) }
leading_row + table_rows.join("\n") + trailing_row
end
private
def format_row(row)
row_start = "#{' ' * indentation}| "
row_end = '|'
cells = row.map.with_index do |cell, i|
format_cell(cell, data_table.col_width(i))
end
row_start + cells.join('| ') + row_end
end
def format_cell(cell, col_width)
cell_text = escape_cell(cell.value.to_s)
cell_text_width = cell_text.unpack('U*').length
padded_text = cell_text + (' ' * (col_width - cell_text_width))
prefix = prefixes[cell.status]
"#{prefix}#{padded_text} "
end
end
def columns
@columns ||= cell_matrix.transpose.map do |cell_row|
Cells.new(self, cell_row)
end
end
def to_json(*args)
raw.to_json(*args)
end
TO_S_PREFIXES = Hash.new(' ')
TO_S_PREFIXES[:comment] = '(+) '
TO_S_PREFIXES[:undefined] = '(-) '
private_constant :TO_S_PREFIXES
protected
def build_hashes
convert_headers!
convert_columns!
cells_rows[1..].map(&:to_hash)
end
def create_cell_matrix(ast_table)
ast_table.raw.map do |raw_row|
line = begin
raw_row.line
rescue StandardError
-1
end
raw_row.map do |raw_cell|
Cell.new(raw_cell, self, line)
end
end
end
def convert_columns!
@conversion_procs.each do |column_name, conversion_proc|
verify_column(column_name) if conversion_proc[:strict]
end
cell_matrix.transpose.each do |col|
column_name = col[0].value
conversion_proc = @conversion_procs[column_name][:proc]
col[1..].each do |cell|
cell.value = conversion_proc.call(cell.value)
end
end
end
def convert_headers!
header_cells = cell_matrix[0]
if @header_conversion_proc
header_values = header_cells.map(&:value) - @header_mappings.keys
@header_mappings = @header_mappings.merge(Hash[*header_values.zip(header_values.map(&@header_conversion_proc)).flatten])
end
@header_mappings.each_pair do |pre, post|
mapped_cells = header_cells.select { |cell| pre.is_a?(Regexp) ? cell.value.match?(pre) : cell.value == pre }
raise "No headers matched #{pre.inspect}" if mapped_cells.empty?
raise "#{mapped_cells.length} headers matched #{pre.inspect}: #{mapped_cells.map(&:value).inspect}" if mapped_cells.length > 1
mapped_cells[0].value = post
@conversion_procs[post] = @conversion_procs.delete(pre) if @conversion_procs.key?(pre)
end
end
def clear_cache!
@hashes = @rows_hash = @column_names = @rows = @columns = nil
end
def ensure_table(table_or_array)
return table_or_array if table_or_array.instance_of?(DataTable)
DataTable.from(table_or_array)
end
def symbolize_key(key)
key.downcase.tr(' ', '_').to_sym
end
# Represents a row of cells or columns of cells
class Cells
include Enumerable
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :exception
def initialize(table, cells)
@table = table
@cells = cells
end
def accept(visitor)
return if Cucumber.wants_to_quit
each do |cell|
visitor.visit_table_cell(cell)
end
nil
end
def to_sexp
[:row, line, *@cells.map(&:to_sexp)]
end
def to_hash
@to_hash ||= @table.cells_to_hash(self)
end
def value(index)
self[index].value
end
def [](index)
@cells[index]
end
def line
@cells[0].line
end
def dom_id
"row_#{line}"
end
def each(&proc)
@cells.each(&proc)
end
private
def index
@table.index(self)
end
def width
map { |cell| cell.value ? escape_cell(cell.value.to_s).unpack('U*').length : 0 }.max
end
end
class Cell
attr_reader :line, :table
attr_accessor :status, :value
def initialize(value, table, line)
@value = value
@table = table
@line = line
end
def inspect!
@value = "(i) #{value.inspect}"
end
def ==(other)
other.class == SurplusCell || value == other.value
end
def eql?(other)
self == other
end
def hash
0
end
# For testing only
def to_sexp
[:cell, @value]
end
end
class SurplusCell < Cell
def status
:comment
end
def ==(_other)
true
end
def hash
0
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/multiline_argument/doc_string.rb | lib/cucumber/multiline_argument/doc_string.rb | # frozen_string_literal: true
module Cucumber
module MultilineArgument
class DocString < SimpleDelegator
def append_to(array)
array << to_s
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/multiline_argument/data_table/diff_matrices.rb | lib/cucumber/multiline_argument/data_table/diff_matrices.rb | # frozen_string_literal: true
module Cucumber
module MultilineArgument
class DataTable
class DiffMatrices # :nodoc:
attr_accessor :cell_matrix, :other_table_cell_matrix, :options
def initialize(cell_matrix, other_table_cell_matrix, options)
@cell_matrix = cell_matrix
@other_table_cell_matrix = other_table_cell_matrix
@options = options
end
def call
prepare_diff
perform_diff
fill_in_missing_values
raise_error if should_raise?
end
private
attr_reader :row_indices, :original_width, :original_header, :padded_width, :missing_row_pos, :insert_row_pos
def prepare_diff
@original_width = cell_matrix[0].length
@original_header = other_table_cell_matrix[0]
pad_and_match
@padded_width = cell_matrix[0].length
@row_indices = Array.new(other_table_cell_matrix.length) { |n| n }
end
# Pads two cell matrices to same column width and matches columns according to header value.
def pad_and_match
cols = cell_matrix.transpose
unmatched_cols = other_table_cell_matrix.transpose
header_values = cols.map(&:first)
matched_cols = []
header_values.each_with_index do |v, i|
mapped_index = unmatched_cols.index { |unmapped_col| unmapped_col.first == v }
if mapped_index
matched_cols << unmatched_cols.delete_at(mapped_index)
else
mark_as_missing(cols[i])
empty_col = ensure_2d(other_table_cell_matrix).collect { SurplusCell.new(nil, self, -1) }
empty_col.first.value = v
matched_cols << empty_col
end
end
unmatched_cols.each do
empty_col = cell_matrix.collect { SurplusCell.new(nil, self, -1) }
cols << empty_col
end
self.cell_matrix = ensure_2d(cols.transpose)
self.other_table_cell_matrix = ensure_2d((matched_cols + unmatched_cols).transpose)
end
def mark_as_missing(col)
col.each do |cell|
cell.status = :undefined
end
end
def ensure_2d(array)
array[0].is_a?(Array) ? array : [array]
end
def perform_diff
inserted = 0
missing = 0
last_change = nil
changes.each do |change|
if change.action == '-'
@missing_row_pos = change.position + inserted
cell_matrix[missing_row_pos].each { |cell| cell.status = :undefined }
row_indices.insert(missing_row_pos, nil)
missing += 1
else # '+'
@insert_row_pos = change.position + missing
inserted_row = change.element
inserted_row.each { |cell| cell.status = :comment }
cell_matrix.insert(insert_row_pos, inserted_row)
row_indices[insert_row_pos] = nil
inspect_rows(cell_matrix[missing_row_pos], inserted_row) if last_change == '-'
inserted += 1
end
last_change = change.action
end
end
def changes
require 'diff/lcs'
diffable_cell_matrix = cell_matrix.dup.extend(::Diff::LCS)
diffable_cell_matrix.diff(other_table_cell_matrix).flatten(1)
end
def inspect_rows(missing_row, inserted_row)
missing_row.each_with_index do |missing_cell, col|
inserted_cell = inserted_row[col]
if missing_cell.value != inserted_cell.value && missing_cell.value.to_s == inserted_cell.value.to_s
missing_cell.inspect!
inserted_cell.inspect!
end
end
end
def fill_in_missing_values
other_table_cell_matrix.each_with_index do |other_row, i|
row_index = row_indices.index(i)
row = cell_matrix[row_index] if row_index
next unless row
(original_width..padded_width).each do |col_index|
surplus_cell = other_row[col_index]
row[col_index].value = surplus_cell.value if row[col_index]
end
end
end
def missing_col
cell_matrix[0].find { |cell| cell.status == :undefined }
end
def surplus_col
padded_width > original_width
end
def misplaced_col
cell_matrix[0] != original_header
end
def raise_error
table = DataTable.from([[]])
table.instance_variable_set :@cell_matrix, cell_matrix
raise Different, table if should_raise?
end
def should_raise?
[
missing_row_pos && options.fetch(:missing_row, true),
insert_row_pos && options.fetch(:surplus_row, true),
missing_col && options.fetch(:missing_col, true),
surplus_col && options.fetch(:surplus_col, false),
misplaced_col && options.fetch(:misplaced_col, false)
].any?
end
end
private_constant :DiffMatrices
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/publish_banner_printer.rb | lib/cucumber/formatter/publish_banner_printer.rb | # frozen_string_literal: true
require 'cucumber/term/banner'
module Cucumber
module Formatter
class PublishBannerPrinter
include Term::Banner
def initialize(configuration)
return if configuration.publish_enabled?
configuration.on_event :test_run_finished do |_event|
display_publish_ad(configuration.error_stream)
end
end
def display_publish_ad(io)
display_banner(
[
[
'Share your Cucumber Report with your team at ',
link('https://reports.cucumber.io')
],
'',
[
'Command line option: ',
highlight('--publish')
],
[
'Environment variable: ',
highlight('CUCUMBER_PUBLISH_ENABLED'),
'=',
highlight('true')
],
[
'cucumber.yml: ',
highlight('default: --publish')
],
'',
[
'More information at ',
link('https://cucumber.io/docs/cucumber/environment-variables/')
],
'',
[
'To disable this message, specify ',
pre('CUCUMBER_PUBLISH_QUIET=true'),
' or use the '
],
[
pre('--publish-quiet'),
' option. You can also add this to your ',
pre('cucumber.yml:')
],
[pre('default: --publish-quiet')]
],
io
)
end
def highlight(text)
[text, :cyan]
end
def link(text)
[text, :cyan, :bold, :underline]
end
def pre(text)
[text, :bold]
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/stepdefs.rb | lib/cucumber/formatter/stepdefs.rb | # frozen_string_literal: true
require 'cucumber/formatter/usage'
module Cucumber
module Formatter
class Stepdefs < Usage
def print_steps(stepdef_key); end
def max_step_length
0
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/rerun.rb | lib/cucumber/formatter/rerun.rb | # frozen_string_literal: true
require 'cucumber/formatter/io'
module Cucumber
module Formatter
class Rerun
include Formatter::Io
def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
@config = config
@failures = {}
config.on_event :test_case_finished do |event|
test_case, result = *event.attributes
if @config.strict.strict?(:flaky)
next if result.ok?(strict: @config.strict)
add_to_failures(test_case)
else
unless @latest_failed_test_case.nil?
if @latest_failed_test_case != test_case
add_to_failures(@latest_failed_test_case)
@latest_failed_test_case = nil
elsif result.ok?(strict: @config.strict)
@latest_failed_test_case = nil
end
end
@latest_failed_test_case = test_case unless result.ok?(strict: @config.strict)
end
end
config.on_event :test_run_finished do
add_to_failures(@latest_failed_test_case) unless @latest_failed_test_case.nil?
next if @failures.empty?
@io.print file_failures.join("\n")
end
end
private
def file_failures
@failures.map { |file, lines| [file, lines].join(':') }
end
def add_to_failures(test_case)
location = test_case.location
@failures[location.file] ||= []
@failures[location.file] << location.lines.max unless @failures[location.file].include?(location.lines.max)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/io.rb | lib/cucumber/formatter/io.rb | # frozen_string_literal: true
require 'cucumber/formatter/http_io'
require 'cucumber/formatter/url_reporter'
require 'cucumber/cli/options'
module Cucumber
module Formatter
module Io
module_function
def ensure_io(path_or_url_or_io, error_stream)
return nil if path_or_url_or_io.nil?
return path_or_url_or_io if io?(path_or_url_or_io)
io = if url?(path_or_url_or_io)
url = path_or_url_or_io
reporter = url.start_with?(Cucumber::Cli::Options::CUCUMBER_PUBLISH_URL) ? URLReporter.new(error_stream) : NoReporter.new
HTTPIO.open(url, nil, reporter)
else
File.open(path_or_url_or_io, Cucumber.file_mode('w'))
end
@io_objects_to_close ||= []
@io_objects_to_close.push(io)
io
end
module ClassMethods
def new(*args, &block)
instance = super
config = args[0]
if config.respond_to? :on_event
config.on_event :test_run_finished do
ios = instance.instance_variable_get(:@io_objects_to_close) || []
ios.each do |io|
at_exit do
unless io.closed?
io.flush
io.close
end
end
end
end
end
instance
end
end
def self.included(formatter_class)
formatter_class.extend(ClassMethods)
end
def io?(path_or_url_or_io)
path_or_url_or_io.respond_to?(:write)
end
def url?(path_or_url_or_io)
path_or_url_or_io.match(/^https?:\/\//)
end
def ensure_file(path, name)
raise "You *must* specify --out FILE for the #{name} formatter" unless path.instance_of? String
raise "I can't write #{name} to a directory - it has to be a file" if File.directory?(path)
raise "I can't write #{name} to a file in the non-existing directory #{File.dirname(path)}" unless File.directory?(File.dirname(path))
ensure_io(path, nil)
end
def ensure_dir(path, name)
raise "You *must* specify --out DIR for the #{name} formatter" unless path.instance_of? String
raise "I can't write #{name} reports to a file - it has to be a directory" if File.file?(path)
FileUtils.mkdir_p(path) unless File.directory?(path)
File.absolute_path path
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/fanout.rb | lib/cucumber/formatter/fanout.rb | # frozen_string_literal: true
module Cucumber
module Formatter
# Forwards any messages sent to this object to all recipients
# that respond to that message.
class Fanout < BasicObject
attr_reader :recipients
private :recipients
def initialize(recipients)
@recipients = recipients
end
def method_missing(message, *args)
super unless recipients
recipients.each do |recipient|
recipient.send(message, *args) if recipient.respond_to?(message)
end
end
def respond_to_missing?(name, include_private = false)
recipients.any? { |recipient| recipient.respond_to?(name, include_private) } || super(name, include_private)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/usage.rb | lib/cucumber/formatter/usage.rb | # frozen_string_literal: true
require 'cucumber/formatter/progress'
require 'cucumber/step_definition_light'
require 'cucumber/formatter/console'
module Cucumber
module Formatter
class Usage < Progress
include Console
class StepDefKey
attr_accessor :mean_duration, :status
attr_reader :regexp_source, :location
def initialize(regexp_source, location)
@regexp_source = regexp_source
@location = location
end
def eql?(other)
regexp_source == other.regexp_source && location == other.location
end
def hash
regexp_source.hash + 31 * location.to_s.hash
end
end
def initialize(config)
super
@stepdef_to_match = Hash.new { |h, stepdef_key| h[stepdef_key] = [] }
@total_duration = 0
@matches = {}
config.on_event :step_activated do |event|
test_step, step_match = *event.attributes
@matches[test_step.to_s] = step_match
end
config.on_event :step_definition_registered, &method(:on_step_definition_registered)
end
def on_step_definition_registered(event)
stepdef_key = StepDefKey.new(event.step_definition.expression.to_s, event.step_definition.location)
@stepdef_to_match[stepdef_key] = []
end
def on_step_match(event)
@matches[event.test_step.to_s] = event.step_match
super
end
def on_test_step_finished(event)
return if event.test_step.hook?
test_step = event.test_step
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
step_match = @matches[test_step.to_s]
unless step_match.nil?
step_definition = step_match.step_definition
stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location)
unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location
duration = DurationExtractor.new(result).result_duration
keyword = @ast_lookup.step_source(test_step).step.keyword
@stepdef_to_match[stepdef_key] << {
keyword: keyword,
step_match: step_match,
status: result.to_sym,
location: test_step.location,
duration: duration
}
end
end
super
end
private
def print_summary
aggregate_info
keys = if config.dry_run?
@stepdef_to_match.keys.sort_by(&:regexp_source)
else
@stepdef_to_match.keys.sort_by(&:mean_duration).reverse
end
keys.each do |stepdef_key|
print_step_definition(stepdef_key)
if @stepdef_to_match[stepdef_key].any?
print_steps(stepdef_key)
else
@io.puts(" #{format_string('NOT MATCHED BY ANY STEPS', :failed)}")
end
end
@io.puts
super
end
def print_step_definition(stepdef_key)
@io.print "#{format_string(format('%<duration>.7f', duration: stepdef_key.mean_duration), :skipped)} " unless config.dry_run?
@io.print format_string(stepdef_key.regexp_source, stepdef_key.status)
if config.source?
indent_amount = max_length - stepdef_key.regexp_source.unpack('U*').length
line_comment = indent(" # #{stepdef_key.location}", indent_amount)
@io.print(format_string(line_comment, :comment))
end
@io.puts
end
def print_steps(stepdef_key)
@stepdef_to_match[stepdef_key].each do |step|
@io.print ' '
@io.print "#{format_string(format('%<duration>.7f', duration: step[:duration]), :skipped)} " unless config.dry_run?
@io.print format_step(step[:keyword], step[:step_match], step[:status], nil)
if config.source?
indent_amount = max_length - (step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length)
line_comment = indent(" # #{step[:location]}", indent_amount)
@io.print(format_string(line_comment, :comment))
end
@io.puts
end
end
def max_length
[max_stepdef_length, max_step_length].compact.max
end
def max_stepdef_length
@stepdef_to_match.keys.flatten.map { |key| key.regexp_source.unpack('U*').length }.max
end
def max_step_length
@stepdef_to_match.values.to_a.flatten.map do |step|
step[:keyword].unpack('U*').length + step[:step_match].format_args.unpack('U*').length
end.max
end
def aggregate_info
@stepdef_to_match.each do |key, steps|
if steps.empty?
key.status = :skipped
key.mean_duration = 0
else
key.status = worst_status(steps.map { |step| step[:status] })
total_duration = steps.inject(0) { |sum, step| step[:duration] + sum }
key.mean_duration = total_duration / steps.length
end
end
end
def worst_status(statuses)
%i[passed undefined pending skipped failed].find do |status|
statuses.include?(status)
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/duration.rb | lib/cucumber/formatter/duration.rb | # frozen_string_literal: true
module Cucumber
module Formatter
module Duration
# Helper method for formatters that need to
# format a duration in seconds to the UNIX
# <tt>time</tt> format.
def format_duration(seconds)
m, s = seconds.divmod(60)
"#{m}m#{format('%<seconds>.3f', seconds: s)}s"
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/interceptor.rb | lib/cucumber/formatter/interceptor.rb | # frozen_string_literal: true
module Cucumber
module Formatter
module Interceptor
class Pipe
attr_reader :pipe
def initialize(pipe)
@pipe = pipe
@buffer = StringIO.new
@wrapped = true
@lock = Mutex.new
end
def write(str)
@lock.synchronize do
@buffer << str if @wrapped
return @pipe.write(str)
end
end
def buffer_string
@lock.synchronize do
return @buffer.string.dup
end
end
def unwrap!
@wrapped = false
@pipe
end
def method_missing(method, *args, &blk)
@pipe.respond_to?(method) ? @pipe.send(method, *args, &blk) : super
end
def respond_to_missing?(method, include_private = false)
super || @pipe.respond_to?(method, include_private)
end
def self.validate_pipe(pipe)
raise ArgumentError, '#wrap only accepts :stderr or :stdout' unless %i[stdout stderr].include? pipe
end
def self.unwrap!(pipe)
validate_pipe pipe
wrapped = nil
case pipe
when :stdout
wrapped = $stdout
$stdout = wrapped.unwrap! if $stdout.respond_to?(:unwrap!)
when :stderr
wrapped = $stderr
$stderr = wrapped.unwrap! if $stderr.respond_to?(:unwrap!)
end
wrapped
end
def self.wrap(pipe)
validate_pipe pipe
case pipe
when :stderr
$stderr = new($stderr)
$stderr
when :stdout
$stdout = new($stdout)
$stdout
end
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/steps.rb | lib/cucumber/formatter/steps.rb | # frozen_string_literal: true
require 'cucumber/formatter/console'
module Cucumber
module Formatter
# The formatter used for <tt>--format steps</tt>
class Steps
include Console
def initialize(runtime, path_or_io, options)
@io = ensure_io(path_or_io, nil)
@options = options
@step_definition_files = collect_steps(runtime)
end
def after_features(_features)
print_summary
end
private
def print_summary
count = 0
@step_definition_files.keys.sort.each do |step_definition_file|
@io.puts step_definition_file
sources = @step_definition_files[step_definition_file]
source_indent = source_indent(sources)
sources.sort.each do |file_colon_line, regexp_source|
@io.print indent(regexp_source, 2)
@io.print indent(" # #{file_colon_line}", source_indent - regexp_source.unpack('U*').length)
@io.puts
end
@io.puts
count += sources.size
end
@io.puts "#{count} step definition(s) in #{@step_definition_files.size} source file(s)."
end
def collect_steps(runtime)
runtime.step_definitions.each_with_object({}) do |step_definition, step_definitions|
step_definitions[step_definition.file] ||= []
step_definitions[step_definition.file] << [step_definition.file_colon_line, step_definition.regexp_source]
end
end
def source_indent(sources)
sources.map { |_file_colon_line, regexp| regexp.size }.max + 1
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/errors.rb | lib/cucumber/formatter/errors.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class TestCaseUnknownError < StandardError; end
class TestStepUnknownError < StandardError; end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/fail_fast.rb | lib/cucumber/formatter/fail_fast.rb | # frozen_string_literal: true
require 'cucumber/formatter/io'
require 'cucumber/formatter/console'
module Cucumber
module Formatter
class FailFast
def initialize(configuration)
@previous_test_case = nil
configuration.on_event :test_case_finished do |event|
test_case, result = *event.attributes
if test_case != @previous_test_case
@previous_test_case = event.test_case
Cucumber.wants_to_quit = true unless result.ok?(strict: configuration.strict)
elsif result.passed?
Cucumber.wants_to_quit = false
end
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/io_http_buffer.rb | lib/cucumber/formatter/io_http_buffer.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class IOHTTPBuffer
attr_reader :uri, :method, :headers
def initialize(uri, method, headers = {}, https_verify_mode = nil, reporter = nil)
@uri = URI(uri)
@method = method
@headers = headers
@write_io = Tempfile.new('cucumber', encoding: 'UTF-8')
@https_verify_mode = https_verify_mode
@reporter = reporter || NoReporter.new
end
def close
@reporter.report(response.body)
@write_io.close
return if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
raise StandardError, "request to #{uri} failed with status #{response.code}"
end
def write(data)
@write_io.write(data)
end
def flush
@write_io.flush
end
def closed?
@write_io.closed?
end
private
def response
@response ||= send_content(uri, method, headers)
end
def send_content(uri, method, headers, attempts_remaining = 10)
content = (method == 'GET' ? StringIO.new : @write_io)
http = build_client(uri)
raise StandardError, "request to #{uri} failed (too many redirections)" if attempts_remaining <= 0
request = build_request(uri, method, headers.merge('Content-Length' => content.size.to_s))
content.rewind
request.body_stream = content
begin
response = http.request(request)
rescue SystemCallError
# We may get the redirect response before pushing the file.
response = http.request(build_request(uri, method, headers))
end
case response
when Net::HTTPAccepted
send_content(URI(response['Location']), 'PUT', {}, attempts_remaining - 1) if response['Location']
when Net::HTTPRedirection
send_content(URI(response['Location']), method, headers, attempts_remaining - 1)
end
response
end
def build_request(uri, method, headers)
method_class_name = "#{method[0].upcase}#{method[1..].downcase}"
Net::HTTP.const_get(method_class_name).new(uri).tap do |request|
headers.each do |header, value|
request[header] = value
end
end
end
def build_client(uri)
Net::HTTP.new(uri.hostname, uri.port).tap do |http|
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = @https_verify_mode if @https_verify_mode
end
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/message_builder.rb | lib/cucumber/formatter/message_builder.rb | # frozen_string_literal: true
require 'base64'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/query/hook_by_test_step'
require 'cucumber/formatter/query/pickle_by_test'
require 'cucumber/formatter/query/pickle_step_by_test_step'
require 'cucumber/formatter/query/step_definitions_by_test_step'
require 'cucumber/formatter/query/test_case_started_by_test_case'
require 'cucumber/formatter/query/test_run_started'
require 'cucumber/query'
module Cucumber
module Formatter
class MessageBuilder
include Cucumber::Messages::Helpers::TimeConversion
def initialize(config)
@config = config
@hook_by_test_step = Query::HookByTestStep.new(config)
@pickle_by_test = Query::PickleByTest.new(config)
@pickle_step_by_test_step = Query::PickleStepByTestStep.new(config)
@step_definitions_by_test_step = Query::StepDefinitionsByTestStep.new(config)
@test_case_started_by_test_case = Query::TestCaseStartedByTestCase.new(config)
@test_run_started = Query::TestRunStarted.new(config)
config.on_event :envelope, &method(:on_envelope)
config.on_event :gherkin_source_read, &method(:on_gherkin_source_read)
config.on_event :test_case_ready, &method(:on_test_case_ready)
config.on_event :test_run_started, &method(:on_test_run_started)
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_step_started, &method(:on_test_step_started)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
config.on_event :undefined_parameter_type, &method(:on_undefined_parameter_type)
@test_case_by_step_id = {}
@current_test_run_started_id = nil
@current_test_case_started_id = nil
@current_test_step_id = nil
@repository = Cucumber::Repository.new
@query = Cucumber::Query.new(@repository)
end
def attach(src, media_type, filename)
attachment_data = {
test_step_id: @current_test_step_id,
test_case_started_id: @current_test_case_started_id,
media_type: media_type,
file_name: filename,
timestamp: time_to_timestamp(Time.now)
}
if media_type&.start_with?('text/')
attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::IDENTITY
attachment_data[:body] = src
else
body = src.respond_to?(:read) ? src.read : src
attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::BASE64
attachment_data[:body] = Base64.strict_encode64(body)
end
message = Cucumber::Messages::Envelope.new(attachment: Cucumber::Messages::Attachment.new(**attachment_data))
output_envelope(message)
end
private
def on_envelope(event)
output_envelope(event.envelope)
end
def on_gherkin_source_read(event)
message = Cucumber::Messages::Envelope.new(
source: Cucumber::Messages::Source.new(
uri: event.path,
data: event.body,
media_type: 'text/x.cucumber.gherkin+plain'
)
)
output_envelope(message)
end
def on_test_case_ready(event)
event.test_case.test_steps.each do |step|
@test_case_by_step_id[step.id] = event.test_case
end
message = Cucumber::Messages::Envelope.new(
test_case: Cucumber::Messages::TestCase.new(
id: event.test_case.id,
pickle_id: @pickle_by_test.pickle_id(event.test_case),
test_steps: event.test_case.test_steps.map { |step| test_step_to_message(step) },
test_run_started_id: @current_test_run_started_id
)
)
output_envelope(message)
end
def test_step_to_message(step)
return hook_step_to_message(step) if step.hook?
Cucumber::Messages::TestStep.new(
id: step.id,
pickle_step_id: @pickle_step_by_test_step.pickle_step_id(step),
step_definition_ids: @step_definitions_by_test_step.step_definition_ids(step),
step_match_arguments_lists: step_match_arguments_lists(step)
)
end
def hook_step_to_message(step)
Cucumber::Messages::TestStep.new(
id: step.id,
hook_id: @hook_by_test_step.hook_id(step)
)
end
def step_match_arguments_lists(step)
match_arguments = step_match_arguments(step)
[Cucumber::Messages::StepMatchArgumentsList.new(
step_match_arguments: match_arguments
)]
rescue Cucumber::Formatter::TestStepUnknownError
[]
end
def step_match_arguments(step)
@step_definitions_by_test_step.step_match_arguments(step).map do |argument|
Cucumber::Messages::StepMatchArgument.new(
group: argument_group_to_message(argument.group),
parameter_type_name: parameter_type_name(argument)
)
end
end
def argument_group_to_message(group)
Cucumber::Messages::Group.new(
start: group.start,
value: group.value,
children: group.children.map { |child| argument_group_to_message(child) }
)
end
def parameter_type_name(step_match_argument)
step_match_argument.parameter_type&.name if step_match_argument.respond_to?(:parameter_type)
end
def on_test_run_started(*)
@current_test_run_started_id = @test_run_started.id
message = Cucumber::Messages::Envelope.new(
test_run_started: Cucumber::Messages::TestRunStarted.new(
timestamp: time_to_timestamp(Time.now),
id: @current_test_run_started_id
)
)
output_envelope(message)
end
def on_test_case_started(event)
@current_test_case_started_id = test_case_started_id(event.test_case)
message = Cucumber::Messages::Envelope.new(
test_case_started: Cucumber::Messages::TestCaseStarted.new(
id: test_case_started_id(event.test_case),
test_case_id: event.test_case.id,
timestamp: time_to_timestamp(Time.now),
attempt: @test_case_started_by_test_case.attempt_by_test_case(event.test_case)
)
)
output_envelope(message)
end
def on_test_step_started(event)
@current_test_step_id = event.test_step.id
test_case = @test_case_by_step_id[event.test_step.id]
message = Cucumber::Messages::Envelope.new(
test_step_started: Cucumber::Messages::TestStepStarted.new(
test_step_id: event.test_step.id,
test_case_started_id: test_case_started_id(test_case),
timestamp: time_to_timestamp(Time.now)
)
)
output_envelope(message)
end
def on_test_step_finished(event)
test_case = @test_case_by_step_id[event.test_step.id]
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
result_message = result.to_message
if result.failed? || result.pending?
message_element = result.failed? ? result.exception : result
result_message = Cucumber::Messages::TestStepResult.new(
status: result_message.status,
duration: result_message.duration,
message: create_error_message(message_element),
exception: create_exception_object(result, message_element)
)
end
message = Cucumber::Messages::Envelope.new(
test_step_finished: Cucumber::Messages::TestStepFinished.new(
test_step_id: event.test_step.id,
test_case_started_id: test_case_started_id(test_case),
test_step_result: result_message,
timestamp: time_to_timestamp(Time.now)
)
)
output_envelope(message)
end
def create_error_message(message_element)
<<~ERROR_MESSAGE
#{message_element.message} (#{message_element.class})
#{message_element.backtrace}
ERROR_MESSAGE
end
def create_exception_object(result, message_element)
return unless result.failed?
Cucumber::Messages::Exception.new(
type: message_element.class,
message: message_element.message,
stack_trace: message_element.backtrace.join("\n")
)
end
def on_test_case_finished(event)
message = Cucumber::Messages::Envelope.new(
test_case_finished: Cucumber::Messages::TestCaseFinished.new(
test_case_started_id: test_case_started_id(event.test_case),
timestamp: time_to_timestamp(Time.now)
)
)
output_envelope(message)
end
def on_test_run_finished(event)
message = Cucumber::Messages::Envelope.new(
test_run_finished: Cucumber::Messages::TestRunFinished.new(
timestamp: time_to_timestamp(Time.now),
success: event.success,
test_run_started_id: @current_test_run_started_id
)
)
output_envelope(message)
end
def on_undefined_parameter_type(event)
message = Cucumber::Messages::Envelope.new(
undefined_parameter_type: Cucumber::Messages::UndefinedParameterType.new(
name: event.type_name,
expression: event.expression
)
)
output_envelope(message)
end
def test_case_started_id(test_case)
@test_case_started_by_test_case.test_case_started_id_by_test_case(test_case)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/console.rb | lib/cucumber/formatter/console.rb | # frozen_string_literal: true
require 'cucumber/formatter/ansicolor'
require 'cucumber/formatter/duration'
require 'cucumber/gherkin/i18n'
module Cucumber
module Formatter
# This module contains helper methods that are used by formatters that
# print output to the terminal.
#
# FORMAT is a hash of Proc objects, keyed by step-definition types, e.g.
# "FORMAT[:passed]". The Proc is called for each line of the step's
# output.
#
# format_step calls format_string, format_string calls format_for to obtain
# the formatting Proc.
#
# Example:
#
# The ANSI color console formatter defines a map of step-type to output
# color (e.g. "passed" to "green"), then builds methods named for the
# step-types (e.g. "def passed"), which themselves wrap the corresponding
# color-named methods provided by Term::ANSIColor (e.g. "def red").
#
# During output, each line is processed by passing it to the formatter Proc
# which returns the formatted (e.g. colored) string.
module Console
extend ANSIColor
include Duration
def format_step(keyword, step_match, status, source_indent)
comment = if source_indent
c = indent("# #{step_match.location}", source_indent)
format_string(c, :comment)
else
''
end
format = format_for(status, :param)
line = keyword + step_match.format_args(format) + comment
format_string(line, status)
end
def format_string(input, status)
fmt = format_for(status)
input.to_s.split("\n").map do |line|
if fmt.instance_of?(Proc)
fmt.call(line)
else
fmt % line
end
end.join("\n")
end
def print_elements(elements, status, kind)
return if elements.empty?
element_messages = element_messages(elements, status)
print_element_messages(element_messages, status, kind)
end
def print_element_messages(element_messages, status, kind)
if element_messages.any?
@io.puts(format_string("(::) #{status} #{kind} (::)", status))
@io.puts
@io.flush
end
element_messages.each do |message|
@io.puts(format_string(message, status))
@io.puts
@io.flush
end
end
def print_statistics(duration, config, counts, issues)
if issues.any?
@io.puts issues.to_s
@io.puts
end
@io.puts counts.to_s
@io.puts(format_duration(duration)) if duration && config.duration?
if config.randomize?
@io.puts
@io.puts "Randomized with seed #{config.seed}"
end
@io.flush
end
def print_exception(exception, status, indent)
string = exception_message_string(exception, indent)
@io.puts(format_string(string, status))
end
def exception_message_string(exception, indent_amount)
message = "#{exception.message} (#{exception.class})".dup.force_encoding('UTF-8')
message = linebreaks(message, ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i)
indent("#{message}\n#{exception.backtrace.join("\n")}", indent_amount)
end
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/10655
def linebreaks(msg, max)
return msg unless max.positive?
msg.gsub(/.{1,#{max}}(?:\s|\Z)/) do
(Regexp.last_match(0) + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n")
end.rstrip
end
def collect_snippet_data(test_step, ast_lookup)
# collect snippet data for undefined steps
keyword = ast_lookup.snippet_step_keyword(test_step)
@snippets_input << Console::SnippetData.new(keyword, test_step)
end
def collect_undefined_parameter_type_names(undefined_parameter_type)
@undefined_parameter_types << undefined_parameter_type.type_name
end
def print_snippets(options)
return unless options[:snippets]
snippet_text_proc = lambda do |step_keyword, step_name, multiline_arg|
snippet_text(step_keyword, step_name, multiline_arg)
end
do_print_snippets(snippet_text_proc) unless @snippets_input.empty?
@undefined_parameter_types.map do |type_name|
do_print_undefined_parameter_type_snippet(type_name)
end
end
def do_print_snippets(snippet_text_proc)
snippets = @snippets_input.map do |data|
snippet_text_proc.call(data.actual_keyword, data.step.text, data.step.multiline_arg)
end.uniq
text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n"
text += snippets.join("\n\n")
@io.puts format_string(text, :undefined)
@io.puts
@io.flush
end
def print_passing_wip(config, passed_test_cases, ast_lookup)
return unless config.wip?
messages = passed_test_cases.map do |test_case|
scenario_source = ast_lookup.scenario_source(test_case)
keyword = scenario_source.type == :Scenario ? scenario_source.scenario.keyword : scenario_source.scenario_outline.keyword
linebreaks("#{test_case.location.on_line(test_case.location.lines.max)}:in `#{keyword}: #{test_case.name}'", ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i)
end
do_print_passing_wip(messages)
end
def do_print_passing_wip(passed_messages)
if passed_messages.any?
@io.puts format_string("\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:", :failed)
print_element_messages(passed_messages, :passed, 'scenarios')
else
@io.puts format_string("\nThe --wip switch was used, so the failures were expected. All is good.\n", :passed)
end
end
def attach(src, media_type, filename)
return unless media_type == 'text/x.cucumber.log+plain'
return unless @io
@io.puts
if filename
@io.puts("#{filename}: #{format_string(src, :tag)}")
else
@io.puts(format_string(src, :tag))
end
@io.flush
end
def print_profile_information
return if @options[:skip_profile_information] || @options[:profiles].nil? || @options[:profiles].empty?
do_print_profile_information(@options[:profiles])
end
def do_print_profile_information(profiles)
profiles_sentence = if profiles.size == 1
profiles.first
else
"#{profiles[0...-1].join(', ')} and #{profiles.last}"
end
@io.puts "Using the #{profiles_sentence} profile#{'s' if profiles.size > 1}..."
end
def do_print_undefined_parameter_type_snippet(type_name)
camelized = type_name.split(/_|-/).collect(&:capitalize).join
@io.puts [
"The parameter #{type_name} is not defined. You can define a new one with:",
'',
'ParameterType(',
" name: '#{type_name}',",
' regexp: /some regexp here/,',
" type: #{camelized},",
' # The transformer takes as many arguments as there are capture groups in the regexp,',
' # or just one if there are none.',
" transformer: ->(s) { #{camelized}.new(s) }",
')',
''
].join("\n")
end
def indent(string, padding)
if padding >= 0
string.gsub(/^/, ' ' * padding)
else
string.gsub(/^ {0,#{-padding}}/, '')
end
end
private
FORMATS = Hash.new { |hash, format| hash[format] = method(format).to_proc }
def format_for(*keys)
key = keys.join('_').to_sym
fmt = FORMATS[key]
raise "No format for #{key.inspect}: #{FORMATS.inspect}" if fmt.nil?
fmt
end
def element_messages(elements, status)
elements.map do |element|
if status == :failed
exception_message_string(element.exception, 0)
else
linebreaks(element.backtrace_line, ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i)
end
end
end
def snippet_text(step_keyword, step_name, multiline_arg)
keyword = Cucumber::Gherkin::I18n.code_keyword_for(step_keyword).strip
config.snippet_generators.map do |generator|
generator.call(keyword, step_name, multiline_arg, config.snippet_type)
end.join("\n")
end
class SnippetData
attr_reader :actual_keyword, :step
def initialize(actual_keyword, step)
@actual_keyword = actual_keyword
@step = step
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/http_io.rb | lib/cucumber/formatter/http_io.rb | # frozen_string_literal: true
require 'net/http'
require 'tempfile'
require_relative 'curl_option_parser'
require_relative 'io_http_buffer'
module Cucumber
module Formatter
class HTTPIO
# Returns an IO that will write to a HTTP request's body
# https_verify_mode can be set to OpenSSL::SSL::VERIFY_NONE
# to ignore unsigned certificate - setting to nil will verify the certificate
def self.open(url, https_verify_mode = nil, reporter = nil)
uri, method, headers = CurlOptionParser.parse(url)
IOHTTPBuffer.new(uri, method, headers, https_verify_mode, reporter)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/json.rb | lib/cucumber/formatter/json.rb | # frozen_string_literal: true
require 'json'
require 'base64'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/io'
require 'cucumber/formatter/ast_lookup'
module Cucumber
module Formatter
# The formatter used for <tt>--format json</tt>
class Json
include Io
def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
@ast_lookup = AstLookup.new(config)
@feature_hashes = []
@step_or_hook_hash = {}
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_step_started, &method(:on_test_step_started)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
end
def on_test_case_started(event)
test_case = event.test_case
builder = Builder.new(test_case, @ast_lookup)
unless same_feature_as_previous_test_case?(test_case)
@feature_hash = builder.feature_hash
@feature_hashes << @feature_hash
end
@test_case_hash = builder.test_case_hash
@element_hash = nil
@element_background_hash = builder.background_hash
@in_background = builder.background?
@any_step_failed = false
end
def on_test_step_started(event)
test_step = event.test_step
return if internal_hook?(test_step)
if @element_hash.nil?
@element_hash = create_element_hash(test_step)
feature_elements << @element_hash
end
if test_step.hook?
@step_or_hook_hash = {}
hooks_of_type(test_step) << @step_or_hook_hash
return
end
if first_step_after_background?(test_step)
@in_background = false
feature_elements << @test_case_hash
@element_hash = @test_case_hash
end
@step_or_hook_hash = create_step_hash(test_step)
steps << @step_or_hook_hash
@step_hash = @step_or_hook_hash
end
def on_test_step_finished(event)
test_step, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
return if internal_hook?(test_step)
add_match_and_result(test_step, result)
@any_step_failed = true if result.failed?
end
def on_test_case_finished(event)
feature_elements << @test_case_hash if @in_background
_test_case, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
add_failed_around_hook(result) if result.failed? && !@any_step_failed
end
def on_test_run_finished(_event)
@io.write(JSON.pretty_generate(@feature_hashes))
end
def attach(src, mime_type, _filename)
if mime_type == 'text/x.cucumber.log+plain'
test_step_output << src
return
end
if mime_type =~ /;base64$/
mime_type = mime_type[0..-8]
data = src
else
data = encode64(src)
end
test_step_embeddings << { mime_type: mime_type, data: data }
end
private
def same_feature_as_previous_test_case?(test_case)
@feature_hash&.fetch(:uri, nil) == test_case.location.file
end
def first_step_after_background?(test_step)
@in_background && test_step.location.file == @feature_hash[:uri] && test_step.location.lines.max >= @test_case_hash[:line]
end
def internal_hook?(test_step)
test_step.location.file.include?('lib/cucumber/')
end
def feature_elements
@feature_hash[:elements] ||= []
end
def steps
@element_hash[:steps] ||= []
end
def hooks_of_type(hook_step)
case hook_step.text
when 'Before hook'
before_hooks
when 'After hook'
after_hooks
when 'AfterStep hook'
after_step_hooks
else
raise "Unknown hook type #{hook_step}"
end
end
def before_hooks
@element_hash[:before] ||= []
end
def after_hooks
@element_hash[:after] ||= []
end
def around_hooks
@element_hash[:around] ||= []
end
def after_step_hooks
@step_hash[:after] ||= []
end
def test_step_output
@step_or_hook_hash[:output] ||= []
end
def test_step_embeddings
@step_or_hook_hash[:embeddings] ||= []
end
def create_element_hash(test_step)
return @element_background_hash if @in_background && !first_step_after_background?(test_step)
@in_background = false
@test_case_hash
end
def create_step_hash(test_step)
step_source = @ast_lookup.step_source(test_step).step
step_hash = {
keyword: step_source.keyword,
name: test_step.text,
line: test_step.location.lines.min
}
step_hash[:doc_string] = create_doc_string_hash(step_source.doc_string, test_step.multiline_arg.content) unless step_source.doc_string.nil?
step_hash[:rows] = create_data_table_value(step_source.data_table) unless step_source.data_table.nil?
step_hash
end
def create_doc_string_hash(doc_string, doc_string_content)
content_type = doc_string.media_type || ''
{
value: doc_string_content,
content_type: content_type,
line: doc_string.location.line
}
end
def create_data_table_value(data_table)
data_table.rows.map do |row|
{ cells: row.cells.map(&:value) }
end
end
def add_match_and_result(test_step, result)
@step_or_hook_hash[:match] = create_match_hash(test_step, result)
@step_or_hook_hash[:result] = create_result_hash(result)
result.embeddings.each { |e| embed(e['src'], e['mime_type'], e['label']) } if result.respond_to?(:embeddings)
end
def add_failed_around_hook(result)
@step_or_hook_hash = {}
around_hooks << @step_or_hook_hash
@step_or_hook_hash[:match] = { location: 'unknown_hook_location:1' }
@step_or_hook_hash[:result] = create_result_hash(result)
end
def create_match_hash(test_step, _result)
{ location: test_step.action_location.to_s }
end
def create_result_hash(result)
result_hash = {
status: result.to_sym
}
result_hash[:error_message] = create_error_message(result) if result.failed? || result.pending?
result.duration.tap { |duration| result_hash[:duration] = duration.nanoseconds }
result_hash
end
def create_error_message(result)
message_element = result.failed? ? result.exception : result
message = "#{message_element.message} (#{message_element.class})"
([message] + message_element.backtrace).join("\n")
end
def encode64(data)
# strip newlines from the encoded data
Base64.encode64(data).delete("\n")
end
class Builder
attr_reader :feature_hash, :background_hash, :test_case_hash
def initialize(test_case, ast_lookup)
@background_hash = nil
uri = test_case.location.file
feature = ast_lookup.gherkin_document(uri).feature
feature(feature, uri)
background(feature.children.first.background) unless feature.children.first.background.nil?
scenario(ast_lookup.scenario_source(test_case), test_case)
end
def background?
@background_hash != nil
end
def feature(feature, uri)
@feature_hash = {
id: create_id(feature.name),
uri: uri,
keyword: feature.keyword,
name: feature.name,
description: value_or_empty_string(feature.description),
line: feature.location.line
}
return if feature.tags.empty?
@feature_hash[:tags] = create_tags_array_from_hash_array(feature.tags)
end
def background(background)
@background_hash = {
keyword: background.keyword,
name: background.name,
description: value_or_empty_string(background.description),
line: background.location.line,
type: 'background',
steps: []
}
end
def scenario(scenario_source, test_case)
scenario = scenario_source.type == :Scenario ? scenario_source.scenario : scenario_source.scenario_outline
@test_case_hash = {
id: "#{@feature_hash[:id]};#{create_id_from_scenario_source(scenario_source)}",
keyword: scenario.keyword,
name: test_case.name,
description: value_or_empty_string(scenario.description),
line: test_case.location.lines.max,
type: 'scenario',
steps: []
}
@test_case_hash[:tags] = create_tags_array_from_tags_array(test_case.tags) unless test_case.tags.empty?
end
private
def value_or_empty_string(value)
value.nil? ? '' : value
end
def create_id(name)
name.downcase.tr(' ', '-')
end
def create_id_from_scenario_source(scenario_source)
if scenario_source.type == :Scenario
create_id(scenario_source.scenario.name)
else
scenario_outline_name = scenario_source.scenario_outline.name
examples_name = scenario_source.examples.name
row_number = calculate_row_number(scenario_source)
"#{create_id(scenario_outline_name)};#{create_id(examples_name)};#{row_number}"
end
end
def calculate_row_number(scenario_source)
scenario_source.examples.table_body.each_with_index do |row, index|
return index + 2 if row == scenario_source.row
end
end
def create_tags_array_from_hash_array(tags)
tags_array = []
tags.each { |tag| tags_array << { name: tag.name, line: tag.location.line } }
tags_array
end
def create_tags_array_from_tags_array(tags)
tags_array = []
tags.each { |tag| tags_array << { name: tag.name, line: tag.location.line } }
tags_array
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/console_issues.rb | lib/cucumber/formatter/console_issues.rb | # frozen_string_literal: true
require 'cucumber/formatter/console'
module Cucumber
module Formatter
class ConsoleIssues
include Console
def initialize(config, ast_lookup = AstLookup.new(config))
@previous_test_case = nil
@issues = Hash.new { |h, k| h[k] = [] }
@config = config
@config.on_event(:test_case_finished) do |event|
if event.test_case != @previous_test_case
@previous_test_case = event.test_case
@issues[event.result.to_sym] << event.test_case unless event.result.ok?(strict: @config.strict)
elsif event.result.passed?
@issues[:flaky] << event.test_case unless Core::Test::Result::Flaky.ok?(strict: @config.strict.strict?(:flaky))
@issues[:failed].delete(event.test_case)
end
end
@ast_lookup = ast_lookup
end
def to_s
return if @issues.empty?
result = Core::Test::Result::TYPES.map { |type| scenario_listing(type, @issues[type]) }
result.flatten.join("\n")
end
def any?
@issues.any?
end
private
def scenario_listing(type, test_cases)
return [] if test_cases.empty?
[format_string("#{type_heading(type)} Scenarios:", type)] + test_cases.map do |test_case|
scenario_source = @ast_lookup.scenario_source(test_case)
keyword = scenario_source.type == :Scenario ? scenario_source.scenario.keyword : scenario_source.scenario_outline.keyword
source = @config.source? ? format_string(" # #{keyword}: #{test_case.name}", :comment) : ''
format_string("cucumber #{profiles_string}#{test_case.location.file}:#{test_case.location.lines.max}", type) + source
end
end
def type_heading(type)
case type
when :failed
'Failing'
else
type.to_s.slice(0, 1).capitalize + type.to_s.slice(1..-1)
end
end
def profiles_string
return if @config.custom_profiles.empty?
profiles = @config.custom_profiles.map { |profile| "-p #{profile}" }.join(' ')
"#{profiles} "
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/ast_lookup.rb | lib/cucumber/formatter/ast_lookup.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class AstLookup
def initialize(config)
@gherkin_documents = {}
@test_case_lookups = {}
@test_step_lookups = {}
@step_keyword_lookups = {}
config.on_event :gherkin_source_parsed, &method(:on_gherkin_source_parsed)
end
def on_gherkin_source_parsed(event)
@gherkin_documents[event.gherkin_document.uri] = event.gherkin_document
end
def gherkin_document(uri)
@gherkin_documents[uri]
end
def scenario_source(test_case)
uri = test_case.location.file
@test_case_lookups[uri] ||= TestCaseLookupBuilder.new(gherkin_document(uri)).lookup_hash
@test_case_lookups[uri][test_case.location.lines.max]
end
def step_source(test_step)
uri = test_step.location.file
@test_step_lookups[uri] ||= TestStepLookupBuilder.new(gherkin_document(uri)).lookup_hash
@test_step_lookups[uri][test_step.location.lines.min]
end
def snippet_step_keyword(test_step)
uri = test_step.location.file
document = gherkin_document(uri)
dialect = ::Gherkin::Dialect.for(document.feature.language)
given_when_then_keywords = [dialect.given_keywords, dialect.when_keywords, dialect.then_keywords].flatten.uniq.reject { |kw| kw == '* ' }
keyword_lookup = step_keyword_lookup(uri)
keyword = nil
node = keyword_lookup[test_step.location.lines.min]
while keyword.nil?
if given_when_then_keywords.include?(node.keyword)
keyword = node.keyword
break
end
break if node.previous_node.nil?
node = node.previous_node
end
keyword = dialect.given_keywords.reject { |kw| kw == '* ' }[0] if keyword.nil?
Cucumber::Gherkin::I18n.code_keyword_for(keyword)
end
ScenarioSource = Struct.new(:type, :scenario)
ScenarioOutlineSource = Struct.new(:type, :scenario_outline, :examples, :row)
StepSource = Struct.new(:type, :step)
private
def step_keyword_lookup(uri)
@step_keyword_lookups[uri] ||= KeywordLookupBuilder.new(gherkin_document(uri)).lookup_hash
end
class TestCaseLookupBuilder
attr_reader :lookup_hash
def initialize(gherkin_document)
@lookup_hash = {}
process_scenario_container(gherkin_document.feature)
end
private
def process_scenario_container(container)
container.children.each do |child|
if child.respond_to?(:rule) && child.rule
process_scenario_container(child.rule)
elsif child.respond_to?(:scenario) && child.scenario
process_scenario(child)
end
end
end
def process_scenario(child)
if child.scenario.examples.empty?
@lookup_hash[child.scenario.location.line] = ScenarioSource.new(:Scenario, child.scenario)
else
child.scenario.examples.each do |examples|
examples.table_body.each do |row|
@lookup_hash[row.location.line] = ScenarioOutlineSource.new(:ScenarioOutline, child.scenario, examples, row)
end
end
end
end
end
class TestStepLookupBuilder
attr_reader :lookup_hash
def initialize(gherkin_document)
@lookup_hash = {}
process_scenario_container(gherkin_document.feature)
end
private
def process_scenario_container(container)
container.children.each do |child|
if child.respond_to?(:rule) && child.rule
process_scenario_container(child.rule)
elsif child.respond_to?(:scenario) && child.scenario
store_scenario_source_steps(child.scenario)
elsif !child.background.nil?
store_background_source_steps(child.background)
end
end
end
def store_scenario_source_steps(scenario)
scenario.steps.each do |step|
@lookup_hash[step.location.line] = StepSource.new(:Step, step)
end
end
def store_background_source_steps(background)
background.steps.each do |step|
@lookup_hash[step.location.line] = StepSource.new(:Step, step)
end
end
end
KeywordSearchNode = Struct.new(:keyword, :previous_node)
class KeywordLookupBuilder
attr_reader :lookup_hash
def initialize(gherkin_document)
@lookup_hash = {}
process_scenario_container(gherkin_document.feature, nil)
end
private
def process_scenario_container(container, original_previous_node)
container.children.each do |child|
previous_node = original_previous_node
if child.respond_to?(:rule) && child.rule
process_scenario_container(child.rule, original_previous_node)
elsif child.respond_to?(:scenario) && child.scenario
child.scenario.steps.each do |step|
node = KeywordSearchNode.new(step.keyword, previous_node)
@lookup_hash[step.location.line] = node
previous_node = node
end
elsif child.respond_to?(:background) && child.background
child.background.steps.each do |step|
node = KeywordSearchNode.new(step.keyword, previous_node)
@lookup_hash[step.location.line] = node
previous_node = node
original_previous_node = previous_node
end
end
end
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/url_reporter.rb | lib/cucumber/formatter/url_reporter.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class URLReporter
def initialize(io)
@io = io
end
def report(banner)
@io.puts(banner)
end
end
class NoReporter
def report(_banner); end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/message.rb | lib/cucumber/formatter/message.rb | # frozen_string_literal: true
require 'cucumber/formatter/io'
require 'cucumber/formatter/message_builder'
module Cucumber
module Formatter
# The formatter used for <tt>--format message</tt>
class Message < MessageBuilder
include Io
def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
super(config)
end
def output_envelope(envelope)
@io.write(envelope.to_json)
@io.write("\n")
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/pretty.rb | lib/cucumber/formatter/pretty.rb | # frozen_string_literal: true
require 'fileutils'
require 'gherkin/dialect'
require 'cucumber/formatter/console'
require 'cucumber/formatter/io'
require 'cucumber/gherkin/formatter/escaping'
require 'cucumber/formatter/console_counts'
require 'cucumber/formatter/console_issues'
require 'cucumber/formatter/duration_extractor'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/ast_lookup'
module Cucumber
module Formatter
# The formatter used for <tt>--format pretty</tt> (the default formatter).
#
# This formatter prints the result of the feature executions to plain text - exactly how they were parsed.
#
# If the output is STDOUT (and not a file), there are bright colours to watch too.
#
class Pretty
include FileUtils
include Console
include Io
include Cucumber::Gherkin::Formatter::Escaping
attr_reader :config, :options, :current_feature_uri, :current_scenario_outline, :current_examples, :current_test_case, :in_scenario_outline, :print_background_steps
private :config, :options
private :current_feature_uri, :current_scenario_outline, :current_examples, :current_test_case
private :in_scenario_outline, :print_background_steps
def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
@config = config
@options = config.to_hash
@snippets_input = []
@undefined_parameter_types = []
@total_duration = 0
@exceptions = []
@gherkin_sources = {}
@step_matches = {}
@ast_lookup = AstLookup.new(config)
@counts = ConsoleCounts.new(config)
@issues = ConsoleIssues.new(config, @ast_lookup)
@first_feature = true
@current_feature_uri = ''
@current_scenario_outline = nil
@current_examples = nil
@current_test_case = nil
@in_scenario_outline = false
@print_background_steps = false
@test_step_output = []
@passed_test_cases = []
@source_indent = 0
@next_comment_to_be_printed = 0
bind_events(config)
end
def bind_events(config)
config.on_event :gherkin_source_read, &method(:on_gherkin_source_read)
config.on_event :step_activated, &method(:on_step_activated)
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_step_started, &method(:on_test_step_started)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
config.on_event :undefined_parameter_type, &method(:collect_undefined_parameter_type_names)
end
def on_gherkin_source_read(event)
@gherkin_sources[event.path] = event.body
end
def on_step_activated(event)
test_step, step_match = *event.attributes
@step_matches[test_step.to_s] = step_match
end
def on_test_case_started(event)
if !same_feature_as_previous_test_case?(event.test_case.location)
if first_feature?
@first_feature = false
print_profile_information
else
print_comments(gherkin_source.split("\n").length, 0)
@io.puts
end
@current_feature_uri = event.test_case.location.file
@exceptions = []
print_feature_data
if feature_has_background?
print_background_data
@print_background_steps = true
@in_scenario_outline = false
end
else
@print_background_steps = false
end
@current_test_case = event.test_case
print_step_header(current_test_case) unless print_background_steps
end
def on_test_step_started(event)
return if event.test_step.hook?
print_step_header(current_test_case) if first_step_after_printing_background_steps?(event.test_step)
end
def on_test_step_finished(event)
collect_snippet_data(event.test_step, @ast_lookup) if event.result.undefined?
return if in_scenario_outline && !options[:expand]
exception_to_be_printed = find_exception_to_be_printed(event.result)
print_step_data(event.test_step, event.result) if print_step_data?(event, exception_to_be_printed)
print_step_output
return unless exception_to_be_printed
print_exception(exception_to_be_printed, event.result.to_sym, 6)
@exceptions << exception_to_be_printed
end
def on_test_case_finished(event)
@total_duration += DurationExtractor.new(event.result).result_duration
@passed_test_cases << event.test_case if config.wip? && event.result.passed?
if in_scenario_outline && !options[:expand]
print_row_data(event.test_case, event.result)
else
exception_to_be_printed = find_exception_to_be_printed(event.result)
return unless exception_to_be_printed
print_exception(exception_to_be_printed, event.result.to_sym, 6)
@exceptions << exception_to_be_printed
end
end
def on_test_run_finished(_event)
print_comments(gherkin_source.split("\n").length, 0) unless current_feature_uri.empty?
@io.puts
print_summary
end
def attach(src, media_type, filename)
return unless media_type == 'text/x.cucumber.log+plain'
if filename
@test_step_output.push("#{filename}: #{src}")
else
@test_step_output.push(src)
end
end
private
def find_exception_to_be_printed(result)
return nil if result.ok?(strict: options[:strict])
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
exception = result.failed? ? result.exception : result
return nil if @exceptions.include?(exception)
exception
end
def calculate_source_indent(test_case)
scenario = scenario_source(test_case).scenario
@source_indent = calculate_source_indent_for_ast_node(scenario)
end
def calculate_source_indent_for_ast_node(ast_node)
indent = 4 + ast_node.keyword.length
indent += 1 + ast_node.name.length
ast_node.steps.each do |step|
step_indent = 5 + step.keyword.length + step.text.length
indent = step_indent if step_indent > indent
end
indent
end
def calculate_source_indent_for_expanded_test_case(test_case, scenario_keyword, expanded_name)
indent = 7 + scenario_keyword.length
indent += 2 + expanded_name.length
test_case.test_steps.each do |step|
if !step.hook? && step.location.lines.max >= test_case.location.lines.max
step_indent = 9 + test_step_keyword(step).length + step.text.length
indent = step_indent if step_indent > indent
end
end
indent
end
def print_step_output
@test_step_output.each { |message| @io.puts(indent(format_string(message, :tag), 6)) }
@test_step_output = []
end
def first_feature?
@first_feature
end
def same_feature_as_previous_test_case?(location)
location.file == current_feature_uri
end
def feature_has_background?
feature_children = gherkin_document.feature.children
return false if feature_children.empty?
!feature_children.first.background.nil?
end
def print_step_header(test_case)
if from_scenario_outline?(test_case)
@in_scenario_outline = true
unless same_outline_as_previous_test_case?(test_case)
@current_scenario_outline = scenario_source(test_case).scenario_outline
@io.puts
print_outline_data(current_scenario_outline)
end
unless same_examples_as_previous_test_case?(test_case)
@current_examples = scenario_source(test_case).examples
@io.puts
print_examples_data(current_examples)
end
print_expanded_row_data(current_test_case) if options[:expand]
else
@in_scenario_outline = false
@current_scenario_outline = nil
@current_examples = nil
@io.puts
@source_indent = calculate_source_indent(current_test_case)
print_scenario_data(test_case)
end
end
def same_outline_as_previous_test_case?(test_case)
scenario_source(test_case).scenario_outline == current_scenario_outline
end
def same_examples_as_previous_test_case?(test_case)
scenario_source(test_case).examples == current_examples
end
def from_scenario_outline?(test_case)
scenario = scenario_source(test_case)
scenario.type != :Scenario
end
def first_step_after_printing_background_steps?(test_step)
return false unless print_background_steps
return false unless test_step.location.lines.max >= current_test_case.location.lines.max
@print_background_steps = false
true
end
def print_feature_data
feature = gherkin_document.feature
print_language_comment(feature.location.line)
print_comments(feature.location.line, 0)
print_tags(feature.tags, 0)
print_feature_line(feature)
print_description(feature.description)
@io.flush
end
def print_language_comment(feature_line)
gherkin_source.split("\n")[0..feature_line].each do |line|
@io.puts(format_string(line, :comment)) if /# *language *:/ =~ line
end
end
def print_comments(up_to_line, indent_amount)
comments = gherkin_document.comments
return if comments.empty? || comments.length <= @next_comment_to_be_printed
comments[@next_comment_to_be_printed..].each do |comment|
if comment.location.line <= up_to_line
@io.puts(indent(format_string(comment.text.strip, :comment), indent_amount))
@next_comment_to_be_printed += 1
end
break if @next_comment_to_be_printed >= comments.length
end
end
def print_tags(tags, indent_amount)
return if !tags || tags.empty?
@io.puts(indent(tags.map { |tag| format_string(tag.name, :tag) }.join(' '), indent_amount))
end
def print_feature_line(feature)
print_keyword_name(feature.keyword, feature.name, 0)
end
def print_keyword_name(keyword, name, indent_amount, location = nil)
line = "#{keyword}:"
line += " #{name}"
@io.print(indent(line, indent_amount))
if location && options[:source]
line_comment = indent(format_string("# #{location}", :comment), @source_indent - line.length - indent_amount)
@io.print(line_comment)
end
@io.puts
end
def print_description(description)
return unless description
description.split("\n").each do |line|
@io.puts(line)
end
end
def print_background_data
@io.puts
background = gherkin_document.feature.children.first.background
@source_indent = calculate_source_indent_for_ast_node(background) if options[:source]
print_comments(background.location.line, 2)
print_background_line(background)
print_description(background.description)
@io.flush
end
def print_background_line(background)
print_keyword_name(background.keyword, background.name, 2, "#{current_feature_uri}:#{background.location.line}")
end
def print_scenario_data(test_case)
scenario = scenario_source(test_case).scenario
print_comments(scenario.location.line, 2)
print_tags(scenario.tags, 2)
print_scenario_line(scenario, test_case.location)
print_description(scenario.description)
@io.flush
end
def print_scenario_line(scenario, location = nil)
print_keyword_name(scenario.keyword, scenario.name, 2, location)
end
def print_step_data?(event, exception_to_be_printed)
!event.test_step.hook? && (
print_background_steps ||
event.test_step.location.lines.max >= current_test_case.location.lines.max ||
exception_to_be_printed
)
end
def print_step_data(test_step, result)
base_indent = options[:expand] && in_scenario_outline ? 8 : 4
step_keyword = test_step_keyword(test_step)
indent = options[:source] ? @source_indent - step_keyword.length - test_step.text.length - base_indent : nil
print_comments(test_step.location.lines.max, base_indent)
name_to_report = format_step(step_keyword, @step_matches.fetch(test_step.to_s) { NoStepMatch.new(test_step, test_step.text) }, result.to_sym, indent)
@io.puts(indent(name_to_report, base_indent))
print_multiline_argument(test_step, result, base_indent + 2) unless options[:no_multiline]
@io.flush
end
def test_step_keyword(test_step)
step = step_source(test_step).step
step.keyword
end
def step_source(test_step)
@ast_lookup.step_source(test_step)
end
def scenario_source(test_case)
@ast_lookup.scenario_source(test_case)
end
def gherkin_source
@gherkin_sources[current_feature_uri]
end
def gherkin_document
@ast_lookup.gherkin_document(current_feature_uri)
end
def print_multiline_argument(test_step, result, indent)
step = step_source(test_step).step
if !step.doc_string.nil?
print_doc_string(step.doc_string.content, result.to_sym, indent)
elsif !step.data_table.nil?
print_data_table(step.data_table, result.to_sym, indent)
end
end
def print_data_table(data_table, status, indent_amount)
data_table.rows.each do |row|
print_comments(row.location.line, indent_amount)
@io.puts indent(format_string(gherkin_source.split("\n")[row.location.line - 1].strip, status), indent_amount)
end
end
def print_outline_data(scenario_outline)
print_comments(scenario_outline.location.line, 2)
print_tags(scenario_outline.tags, 2)
@source_indent = calculate_source_indent_for_ast_node(scenario_outline) if options[:source]
print_scenario_line(scenario_outline, "#{current_feature_uri}:#{scenario_outline.location.line}")
print_description(scenario_outline.description)
scenario_outline.steps.each do |step|
print_comments(step.location.line, 4)
step_line = " #{step.keyword}#{step.text}"
@io.print(format_string(step_line, :skipped))
if options[:source]
comment_line = format_string("# #{current_feature_uri}:#{step.location.line}", :comment)
@io.print(indent(comment_line, @source_indent - step_line.length))
end
@io.puts
next if options[:no_multiline]
print_doc_string(step.doc_string.content, :skipped, 6) unless step.doc_string.nil?
print_data_table(step.data_table, :skipped, 6) unless step.data_table.nil?
end
@io.flush
end
def print_doc_string(content, status, indent_amount)
s = indent(%("""\n#{content}\n"""), indent_amount)
s = s.split("\n").map { |l| l =~ /^\s+$/ ? '' : l }.join("\n")
@io.puts(format_string(s, status))
end
def print_examples_data(examples)
print_comments(examples.location.line, 4)
print_tags(examples.tags, 4)
print_keyword_name(examples.keyword, examples.name, 4)
print_description(examples.description)
unless options[:expand]
print_comments(examples.table_header.location.line, 6)
@io.puts(indent(gherkin_source.split("\n")[examples.table_header.location.line - 1].strip, 6))
end
@io.flush
end
def print_row_data(test_case, result)
print_comments(test_case.location.lines.max, 6)
@io.print(indent(format_string(gherkin_source.split("\n")[test_case.location.lines.max - 1].strip, result.to_sym), 6))
@io.print(indent(format_string(@test_step_output.join(', '), :tag), 2)) unless @test_step_output.empty?
@test_step_output = []
@io.puts
if result.failed? || result.pending?
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
exception = result.failed? ? result.exception : result
unless @exceptions.include?(exception)
print_exception(exception, result.to_sym, 6)
@exceptions << exception
end
end
@io.flush
end
def print_expanded_row_data(test_case)
feature = gherkin_document.feature
language_code = feature.language || 'en'
language = ::Gherkin::Dialect.for(language_code)
scenario_keyword = language.scenario_keywords[0]
row = scenario_source(test_case).row
expanded_name = "| #{row.cells.map(&:value).join(' | ')} |"
@source_indent = calculate_source_indent_for_expanded_test_case(test_case, scenario_keyword, expanded_name)
@io.puts
print_keyword_name(scenario_keyword, expanded_name, 6, test_case.location)
end
def print_summary
print_statistics(@total_duration, config, @counts, @issues)
print_snippets(options)
print_passing_wip(config, @passed_test_cases, @ast_lookup)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/junit.rb | lib/cucumber/formatter/junit.rb | # frozen_string_literal: true
require 'builder'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/io'
require 'cucumber/formatter/interceptor'
require 'fileutils'
require 'cucumber/formatter/ast_lookup'
module Cucumber
module Formatter
# The formatter used for <tt>--format junit</tt>
class Junit
include Io
class UnNamedFeatureError < StandardError
def initialize(feature_file)
super("The feature in '#{feature_file}' does not have a name. The JUnit XML format requires a name for the testsuite element.")
end
end
def initialize(config)
@ast_lookup = AstLookup.new(config)
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
@reportdir = ensure_dir(config.out_stream, 'junit')
@config = config
@features_data = Hash.new do |h, k|
h[k] = {
feature: nil,
failures: 0,
errors: 0,
tests: 0,
skipped: 0,
time: 0,
builder: Builder::XmlMarkup.new(indent: 2)
}
end
end
def on_test_case_started(event)
test_case = event.test_case
start_feature(test_case) unless same_feature_as_previous_test_case?(test_case)
@failing_test_step = nil
# In order to fill out <system-err/> and <system-out/>, we need to
# intercept the $stderr and $stdout
@interceptedout = Interceptor::Pipe.wrap(:stdout)
@interceptederr = Interceptor::Pipe.wrap(:stderr)
end
def on_test_step_finished(event)
test_step, result = *event.attributes
return if @failing_test_step
@failing_test_step = test_step unless result.ok?(strict: @config.strict)
end
def on_test_case_finished(event)
test_case, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
test_case_name = NameBuilder.new(test_case, @ast_lookup)
scenario = test_case_name.scenario_name
scenario_designation = "#{scenario}#{test_case_name.name_suffix}"
output = create_output_string(test_case, scenario, result, test_case_name.row_name)
build_testcase(result, scenario_designation, output)
Interceptor::Pipe.unwrap! :stdout
Interceptor::Pipe.unwrap! :stderr
end
def on_test_run_finished(_event)
@features_data.each_value { |data| end_feature(data) }
end
private
def same_feature_as_previous_test_case?(test_case)
@current_feature_data && @current_feature_data[:uri] == test_case.location.file
end
def start_feature(test_case)
uri = test_case.location.file
feature = @ast_lookup.gherkin_document(uri).feature
raise UnNamedFeatureError, uri if feature.name.empty?
@current_feature_data = @features_data[uri]
@current_feature_data[:uri] = uri unless @current_feature_data[:uri]
@current_feature_data[:feature] = feature unless @current_feature_data[:feature]
end
def end_feature(feature_data)
@testsuite = Builder::XmlMarkup.new(indent: 2)
@testsuite.instruct!
@testsuite.testsuite(
failures: feature_data[:failures],
errors: feature_data[:errors],
skipped: feature_data[:skipped],
tests: feature_data[:tests],
time: format('%<time>.6f', time: feature_data[:time]),
name: feature_data[:feature].name
) do
@testsuite << feature_data[:builder].target!
end
write_file(feature_result_filename(feature_data[:uri]), @testsuite.target!)
end
def create_output_string(test_case, scenario, result, row_name)
scenario_source = @ast_lookup.scenario_source(test_case)
keyword = scenario_source.type == :Scenario ? scenario_source.scenario.keyword : scenario_source.scenario_outline.keyword
output = "#{keyword}: #{scenario}\n\n"
return output if result.ok?(strict: @config.strict)
if scenario_source.type == :Scenario
if @failing_test_step
if @failing_test_step.hook?
output += "#{@failing_test_step.text} at #{@failing_test_step.location}\n"
else
step_source = @ast_lookup.step_source(@failing_test_step).step
output += "#{step_source.keyword}#{@failing_test_step.text}\n"
end
else # An Around hook has failed
output += "Around hook\n"
end
else
output += "Example row: #{row_name}\n"
end
"#{output}\nMessage:\n"
end
def build_testcase(result, scenario_designation, output)
duration = ResultBuilder.new(result).test_case_duration
@current_feature_data[:time] += duration
classname = @current_feature_data[:feature].name
filename = @current_feature_data[:uri]
name = scenario_designation
testcase_attributes = get_testcase_attributes(classname, name, duration, filename)
@current_feature_data[:builder].testcase(testcase_attributes) do
if !result.passed? && result.ok?(strict: @config.strict)
@current_feature_data[:builder].skipped
@current_feature_data[:skipped] += 1
elsif !result.passed?
status = result.to_sym
exception = get_backtrace_object(result)
@current_feature_data[:builder].failure(message: "#{status} #{name}", type: status) do
@current_feature_data[:builder].cdata! output
@current_feature_data[:builder].cdata!(format_exception(exception)) if exception
end
@current_feature_data[:failures] += 1
end
@current_feature_data[:builder].tag!('system-out') do
@current_feature_data[:builder].cdata! strip_control_chars(@interceptedout.buffer_string)
end
@current_feature_data[:builder].tag!('system-err') do
@current_feature_data[:builder].cdata! strip_control_chars(@interceptederr.buffer_string)
end
end
@current_feature_data[:tests] += 1
end
def get_testcase_attributes(classname, name, duration, filename)
{ classname: classname, name: name, time: format('%<duration>.6f', duration: duration) }.tap do |attributes|
attributes[:file] = filename if add_fileattribute?
end
end
def add_fileattribute?
return false if @config.formats.nil? || @config.formats.empty?
!!@config.formats.find do |format|
format.first == 'junit' && format.dig(1, 'fileattribute') == 'true'
end
end
def get_backtrace_object(result)
if result.failed?
result.exception
elsif result.backtrace
result
end
end
def format_exception(exception)
(["#{exception.message} (#{exception.class})"] + exception.backtrace).join("\n")
end
def feature_result_filename(feature_file)
File.join(@reportdir, "TEST-#{basename(feature_file)}.xml")
end
def basename(feature_file)
File.basename(feature_file.gsub(/[\\\/]/, '-'), '.feature')
end
def write_file(feature_filename, data)
File.open(feature_filename, 'w') { |file| file.write(data) }
end
# strip control chars from cdata, to make it safe for external parsers
def strip_control_chars(cdata)
cdata.scan(/[[:print:]\t\n\r]/).join
end
end
class NameBuilder
attr_reader :scenario_name, :name_suffix, :row_name
def initialize(test_case, ast_lookup)
@name_suffix = ''
@row_name = ''
scenario_source = ast_lookup.scenario_source(test_case)
if scenario_source.type == :Scenario
scenario(scenario_source.scenario)
else
scenario_outline(scenario_source.scenario_outline)
examples_table_row(scenario_source.row)
end
end
def scenario(scenario)
@scenario_name = scenario.name.empty? ? 'Unnamed scenario' : scenario.name
end
def scenario_outline(outline)
@scenario_name = outline.name.empty? ? 'Unnamed scenario outline' : outline.name
end
def examples_table_row(row)
@row_name = "| #{row.cells.map(&:value).join(' | ')} |"
@name_suffix = " (outline example : #{@row_name})"
end
end
class ResultBuilder
attr_reader :test_case_duration
def initialize(result)
@test_case_duration = 0
result.describe_to(self)
end
def passed(*) end
def failed(*) end
def undefined(*) end
def skipped(*) end
def pending(*) end
def exception(*) end
def duration(duration, *)
duration.tap { |dur| @test_case_duration = dur.nanoseconds / 10**9.0 }
end
def attach(*) end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/curl_option_parser.rb | lib/cucumber/formatter/curl_option_parser.rb | # frozen_string_literal: true
require 'shellwords'
module Cucumber
module Formatter
class CurlOptionParser
def self.parse(options)
args = Shellwords.split(options)
url = nil
http_method = 'PUT'
headers = {}
until args.empty?
arg = args.shift
case arg
when '-X', '--request'
http_method = remove_arg_for(args, arg)
when '-H'
header_arg = remove_arg_for(args, arg)
headers = headers.merge(parse_header(header_arg))
else
raise StandardError, "#{options} was not a valid curl command. Can't set url to #{arg} it is already set to #{url}" if url
url = arg
end
end
raise StandardError, "#{options} was not a valid curl command" unless url
[url, http_method, headers]
end
private
def self.remove_arg_for(args, arg)
return args.shift unless args.empty?
raise StandardError, "Missing argument for #{arg}"
end
def self.parse_header(header_arg)
parts = header_arg.split(':', 2)
raise StandardError, "#{header_arg} was not a valid header" unless parts.length == 2
{ parts[0].strip => parts[1].strip }
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/backtrace_filter.rb | lib/cucumber/formatter/backtrace_filter.rb | # frozen_string_literal: true
require 'cucumber/platform'
module Cucumber
module Formatter
class BacktraceFilter
def initialize(exception)
@exception = exception
@backtrace_filters = standard_ruby_paths + dynamic_ruby_paths
end
def exception
return @exception if ::Cucumber.use_full_backtrace
backtrace = @exception.backtrace.map { |line| line.gsub(pwd_pattern, './') }
filtered = backtrace.reject { |line| line.match?(backtrace_filter_patterns) }
if ::ENV['CUCUMBER_TRUNCATE_OUTPUT']
filtered = filtered.map do |line|
# Strip off file locations
match = regexp_filter.match(line)
match ? match[1] : line
end
end
@exception.tap { |error_object| error_object.set_backtrace(filtered) }
end
private
def backtrace_filter_patterns
Regexp.new(@backtrace_filters.join('|'))
end
def dynamic_ruby_paths
[].tap do |paths|
paths << RbConfig::CONFIG['rubyarchdir'] if RbConfig::CONFIG['rubyarchdir']
paths << RbConfig::CONFIG['rubylibdir'] if RbConfig::CONFIG['rubylibdir']
paths << 'org/jruby/' if ::Cucumber::JRUBY
paths << '<internal:' if RUBY_ENGINE == 'truffleruby'
end
end
def pwd_pattern
/#{::Regexp.escape(::Dir.pwd)}\//m
end
def regexp_filter
ruby_greater_than_three_four? ? three_four_filter : three_three_filter
end
def ruby_greater_than_three_four?
RUBY_VERSION.to_f >= 3.4
end
def standard_ruby_paths
%w[
/vendor/rails
lib/cucumber
bin/cucumber:
lib/rspec
gems/
site_ruby/
minitest
test/unit
.gem/ruby
bin/bundle
rdebug-ide
]
end
def three_four_filter
/(.*):in '/
end
def three_three_filter
/(.*):in `/
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/unicode.rb | lib/cucumber/formatter/unicode.rb | # frozen_string_literal: true
# Require this file if you need Unicode support.
# Tips for improvement - esp. ruby 1.9: http://www.ruby-forum.com/topic/184730
require 'cucumber/platform'
require 'cucumber/formatter/ansicolor'
if Cucumber::WINDOWS
if ENV['CUCUMBER_OUTPUT_ENCODING']
Cucumber::CODEPAGE = ENV['CUCUMBER_OUTPUT_ENCODING']
elsif `cmd /c chcp` =~ /(\d+)/
if [65_000, 65_001].include? Regexp.last_match(1).to_i
Cucumber::CODEPAGE = 'UTF-8'
ENV['ANSICON_API'] = 'ruby'
else
Cucumber::CODEPAGE = "cp#{Regexp.last_match(1).to_i}"
end
else
Cucumber::CODEPAGE = 'cp1252'
$stderr.puts("WARNING: Couldn't detect your output codepage. Assuming it is 1252. You may have to chcp 1252 or SET CUCUMBER_OUTPUT_ENCODING=cp1252.")
end
module Cucumber
# @private
module WindowsOutput
def self.extended(output)
output.instance_eval do
def cucumber_preprocess_output(*out)
out.map { |arg| arg.to_s.encode(Encoding.default_external) }
rescue Encoding::UndefinedConversionError => e
$stderr.cucumber_puts("WARNING: #{e.message}")
out
end
alias cucumber_print print
def print(*out)
cucumber_print(*cucumber_preprocess_output(*out))
end
alias cucumber_puts puts
def puts(*out)
cucumber_puts(*cucumber_preprocess_output(*out))
end
end
end
Kernel.extend(self)
$stdout.extend(self)
$stderr.extend(self)
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/ansicolor.rb | lib/cucumber/formatter/ansicolor.rb | # frozen_string_literal: true
require 'cucumber/platform'
require 'cucumber/term/ansicolor'
Cucumber::Term::ANSIColor.coloring = false unless $stdout.tty?
module Cucumber
module Formatter
# This module allows to format cucumber related outputs using ANSI escape sequences.
#
# For example, it provides a `passed` method which returns the string with
# the ANSI escape sequence to format it green per default.
#
# To use this, include or extend it in your class.
#
# Example:
#
# require 'cucumber/formatter/ansicolor'
#
# class MyFormatter
# extend Cucumber::Term::ANSIColor
#
# def on_test_step_finished(event)
# $stdout.puts undefined(event.test_step) if event.result.undefined?
# $stdout.puts passed(event.test_step) if event.result.passed?
# end
# end
#
# This module also allows the user to customize the format of cucumber outputs
# using environment variables.
#
# For instance, if your shell has a black background and a green font (like the
# "Homebrew" settings for OS X' Terminal.app), you may want to override passed
# steps to be white instead of green.
#
# Example:
#
# export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"
#
# The colours that you can change are:
#
# * <tt>undefined</tt> - defaults to <tt>yellow</tt>
# * <tt>pending</tt> - defaults to <tt>yellow</tt>
# * <tt>pending_param</tt> - defaults to <tt>yellow,bold</tt>
# * <tt>flaky</tt> - defaults to <tt>yellow</tt>
# * <tt>flaky_param</tt> - defaults to <tt>yellow,bold</tt>
# * <tt>failed</tt> - defaults to <tt>red</tt>
# * <tt>failed_param</tt> - defaults to <tt>red,bold</tt>
# * <tt>passed</tt> - defaults to <tt>green</tt>
# * <tt>passed_param</tt> - defaults to <tt>green,bold</tt>
# * <tt>outline</tt> - defaults to <tt>cyan</tt>
# * <tt>outline_param</tt> - defaults to <tt>cyan,bold</tt>
# * <tt>skipped</tt> - defaults to <tt>cyan</tt>
# * <tt>skipped_param</tt> - defaults to <tt>cyan,bold</tt>
# * <tt>comment</tt> - defaults to <tt>grey</tt>
# * <tt>tag</tt> - defaults to <tt>cyan</tt>
#
# To see what colours and effects are available, just run this in your shell:
#
# ruby -e "require 'rubygems'; require 'cucumber/term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"
#
module ANSIColor
include Cucumber::Term::ANSIColor
ALIASES = Hash.new do |h, k|
next unless k.to_s =~ /(.*)_param/
"#{h[Regexp.last_match(1)]},bold"
end.merge(
'undefined' => 'yellow',
'pending' => 'yellow',
'flaky' => 'yellow',
'failed' => 'red',
'passed' => 'green',
'outline' => 'cyan',
'skipped' => 'cyan',
'comment' => 'grey',
'tag' => 'cyan'
)
# Apply the custom color scheme -> i.e. apply_custom_colors('passed=white')
def self.apply_custom_colors(colors)
colors.split(':').each do |pair|
a = pair.split('=')
ALIASES[a[0]] = a[1]
end
end
apply_custom_colors(ENV['CUCUMBER_COLORS']) if ENV['CUCUMBER_COLORS']
# Define the color-named methods required by Term::ANSIColor.
#
# Examples:
#
# def failed(string=nil, &proc)
# red(string, &proc)
# end
#
# def failed_param(string=nil, &proc)
# red(bold(string, &proc)) + red
# end
ALIASES.each_key do |method_name|
next if method_name.end_with?('_param')
define_method(method_name) do |text = nil, &proc|
apply_styles(ALIASES[method_name], text, &proc)
end
define_method("#{method_name}_param") do |text = nil, &proc|
apply_styles(ALIASES["#{method_name}_param"], text, &proc) + apply_styles(ALIASES[method_name])
end
end
def cukes(amount)
('(::) ' * amount).strip
end
def green_cukes(amount)
blink(green(cukes(amount)))
end
def red_cukes(amount)
blink(red(cukes(amount)))
end
def yellow_cukes(amount)
blink(yellow(cukes(amount)))
end
private
def apply_styles(styles, text = nil, &proc)
styles.split(',').reverse.reduce(text) do |result, method_name|
send(method_name, result, &proc)
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/duration_extractor.rb | lib/cucumber/formatter/duration_extractor.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class DurationExtractor
attr_reader :result_duration
def initialize(result)
@result_duration = 0
result.describe_to(self)
end
def passed(*) end
def failed(*) end
def undefined(*) end
def skipped(*) end
def pending(*) end
def exception(*) end
def duration(duration, *)
duration.tap { |dur| @result_duration = dur.nanoseconds / 10**9.0 }
end
def attach(*) end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/console_counts.rb | lib/cucumber/formatter/console_counts.rb | # frozen_string_literal: true
require 'cucumber/formatter/console'
module Cucumber
module Formatter
class ConsoleCounts
include Console
def initialize(config)
@summary = Core::Report::Summary.new(config.event_bus)
end
def to_s
[
[scenario_count, status_counts(@summary.test_cases)].compact.join(' '),
[step_count, status_counts(@summary.test_steps)].compact.join(' ')
].join("\n")
end
private
def scenario_count
count = @summary.test_cases.total
"#{count} scenario" + (count == 1 ? '' : 's')
end
def step_count
count = @summary.test_steps.total
"#{count} step" + (count == 1 ? '' : 's')
end
def status_counts(summary)
counts = Core::Test::Result::TYPES.map { |status| [status, summary.total(status)] }
counts = counts.select { |_status, count| count.positive? }
counts = counts.map { |status, count| format_string("#{count} #{status}", status) }
"(#{counts.join(', ')})" if counts.any?
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/ignore_missing_messages.rb | lib/cucumber/formatter/ignore_missing_messages.rb | # frozen_string_literal: true
module Cucumber
module Formatter
class IgnoreMissingMessages < BasicObject
def initialize(receiver)
@receiver = receiver
end
def method_missing(message, *args)
@receiver.respond_to?(message) ? @receiver.send(message, *args) : super
end
def respond_to_missing?(name, include_private = false)
@receiver.respond_to?(name, include_private) || super(name, include_private)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/summary.rb | lib/cucumber/formatter/summary.rb | # frozen_string_literal: true
require 'cucumber/formatter/io'
require 'cucumber/formatter/console'
require 'cucumber/formatter/console_counts'
require 'cucumber/formatter/console_issues'
require 'cucumber/core/test/result'
require 'cucumber/formatter/ast_lookup'
module Cucumber
module Formatter
# Summary formatter, outputting only feature / scenario titles
class Summary
include Io
include Console
def initialize(config)
@config = config
@io = ensure_io(config.out_stream, config.error_stream)
@ast_lookup = AstLookup.new(config)
@counts = ConsoleCounts.new(@config)
@issues = ConsoleIssues.new(@config, @ast_lookup)
@start_time = Time.now
@config.on_event :test_case_started do |event|
print_feature event.test_case
print_test_case event.test_case
end
@config.on_event :test_case_finished do |event|
print_result event.result
end
@config.on_event :test_run_finished do |_event|
duration = Time.now - @start_time
@io.puts
print_statistics(duration, @config, @counts, @issues)
end
end
private
def gherkin_document(uri)
@ast_lookup.gherkin_document(uri)
end
def print_feature(test_case)
uri = test_case.location.file
return if @current_feature_uri == uri
feature_name = gherkin_document(uri).feature.name
@io.puts unless @current_feature_uri.nil?
@io.puts feature_name
@current_feature_uri = uri
end
def print_test_case(test_case)
@io.print " #{test_case.name} "
end
def print_result(result)
@io.puts format_string(result, result.to_sym)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/progress.rb | lib/cucumber/formatter/progress.rb | # frozen_string_literal: true
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/console'
require 'cucumber/formatter/console_counts'
require 'cucumber/formatter/console_issues'
require 'cucumber/formatter/io'
require 'cucumber/formatter/duration_extractor'
require 'cucumber/formatter/ast_lookup'
module Cucumber
module Formatter
# The formatter used for <tt>--format progress</tt>
class Progress
include Console
include Io
attr_reader :config, :current_feature_uri
private :config, :current_feature_uri
def initialize(config)
@config = config
@io = ensure_io(config.out_stream, config.error_stream)
@snippets_input = []
@undefined_parameter_types = []
@total_duration = 0
@matches = {}
@pending_step_matches = []
@failed_results = []
@passed_test_cases = []
@current_feature_uri = ''
@gherkin_documents = {}
@ast_lookup = AstLookup.new(config)
@counts = ConsoleCounts.new(config)
@issues = ConsoleIssues.new(config, @ast_lookup)
config.on_event :step_activated, &method(:on_step_activated)
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_step_finished, &method(:on_test_step_finished)
config.on_event :test_case_finished, &method(:on_test_case_finished)
config.on_event :test_run_finished, &method(:on_test_run_finished)
config.on_event :undefined_parameter_type, &method(:collect_undefined_parameter_type_names)
end
def on_step_activated(event)
@matches[event.test_step.to_s] = event.step_match
end
def on_test_case_started(event)
unless @profile_information_printed
do_print_profile_information(config.profiles) unless config.skip_profile_information? || config.profiles.nil? || config.profiles.empty?
@profile_information_printed = true
end
@current_feature_uri = event.test_case.location.file
end
def on_test_step_finished(event)
test_step = event.test_step
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
progress(result.to_sym) if !test_step.hook? || result.failed?
return if test_step.hook?
collect_snippet_data(test_step, @ast_lookup) if result.undefined?
@pending_step_matches << @matches[test_step.to_s] if result.pending?
@failed_results << result if result.failed?
end
def on_test_case_finished(event)
test_case = event.test_case
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
@passed_test_cases << test_case if result.passed?
@total_duration += DurationExtractor.new(result).result_duration
end
def on_test_run_finished(_event)
@io.puts
@io.puts
print_summary
end
private
def gherkin_document
@ast_lookup.gherkin_document(current_feature_uri)
end
def print_summary
print_elements(@pending_step_matches, :pending, 'steps')
print_elements(@failed_results, :failed, 'steps')
print_statistics(@total_duration, @config, @counts, @issues)
print_snippets(config.to_hash)
print_passing_wip(config, @passed_test_cases, @ast_lookup)
end
CHARS = {
passed: '.',
failed: 'F',
undefined: 'U',
pending: 'P',
skipped: '-'
}.freeze
def progress(status)
char = CHARS[status]
@io.print(format_string(char, status))
@io.flush
end
def table_header_cell?(status)
status == :skipped_param
end
TestCaseData = Struct.new(:name, :location)
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/html.rb | lib/cucumber/formatter/html.rb | # frozen_string_literal: true
require 'cucumber/formatter/io'
require 'cucumber/html_formatter'
require 'cucumber/formatter/message_builder'
module Cucumber
module Formatter
class HTML < MessageBuilder
include Io
def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
@html_formatter = Cucumber::HTMLFormatter::Formatter.new(@io)
@html_formatter.write_pre_message
super(config)
end
def output_envelope(envelope)
@html_formatter.write_message(envelope)
@html_formatter.write_post_message if envelope.test_run_finished
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/step_definitions_by_test_step.rb | lib/cucumber/formatter/query/step_definitions_by_test_step.rb | # frozen_string_literal: true
require 'cucumber/formatter/errors'
module Cucumber
module Formatter
module Query
class StepDefinitionsByTestStep
def initialize(config)
@step_definition_ids_by_test_step_id = {}
@step_match_arguments_by_test_step_id = {}
config.on_event :test_step_created, &method(:on_test_step_created)
config.on_event :step_activated, &method(:on_step_activated)
end
def step_definition_ids(test_step)
return @step_definition_ids_by_test_step_id[test_step.id] if @step_definition_ids_by_test_step_id.key?(test_step.id)
raise TestStepUnknownError, "No step definition found for #{test_step.id} }. Known: #{@step_definition_ids_by_test_step_id.keys}"
end
def step_match_arguments(test_step)
return @step_match_arguments_by_test_step_id[test_step.id] if @step_match_arguments_by_test_step_id.key?(test_step.id)
raise TestStepUnknownError, "No step match arguments found for #{test_step.id} }. Known: #{@step_match_arguments_by_test_step_id.keys}"
end
private
def on_test_step_created(event)
@step_definition_ids_by_test_step_id[event.test_step.id] = []
end
def on_step_activated(event)
@step_definition_ids_by_test_step_id[event.test_step.id] << event.step_match.step_definition.id
@step_match_arguments_by_test_step_id[event.test_step.id] = event.step_match.step_arguments
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/pickle_by_test.rb | lib/cucumber/formatter/query/pickle_by_test.rb | # frozen_string_literal: true
require 'cucumber/formatter/errors'
module Cucumber
module Formatter
module Query
class PickleByTest
def initialize(config)
@pickle_id_by_test_case_id = {}
config.on_event :test_case_created, &method(:on_test_case_created)
end
def pickle_id(test_case)
return @pickle_id_by_test_case_id[test_case.id] if @pickle_id_by_test_case_id.key?(test_case.id)
raise TestCaseUnknownError, "No pickle found for #{test_case.id} }. Known: #{@pickle_id_by_test_case_id.keys}"
end
private
def on_test_case_created(event)
@pickle_id_by_test_case_id[event.test_case.id] = event.pickle.id
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/test_run_started.rb | lib/cucumber/formatter/query/test_run_started.rb | # frozen_string_literal: true
module Cucumber
module Formatter
module Query
class TestRunStarted
def initialize(config)
@config = config
end
def id
@id ||= @config.id_generator.new_id
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/test_case_started_by_test_case.rb | lib/cucumber/formatter/query/test_case_started_by_test_case.rb | # frozen_string_literal: true
require 'cucumber/formatter/errors'
module Cucumber
module Formatter
module Query
class TestCaseStartedByTestCase
def initialize(config)
@config = config
config.on_event :test_case_created, &method(:on_test_case_created)
config.on_event :test_case_started, &method(:on_test_case_started)
@attempts_by_test_case_id = {}
@test_case_started_id_by_test_case_id = {}
end
def attempt_by_test_case(test_case)
raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@attempts_by_test_case_id.keys}" unless @attempts_by_test_case_id.key?(test_case.id)
@attempts_by_test_case_id[test_case.id]
end
def test_case_started_id_by_test_case(test_case)
raise TestCaseUnknownError, "No test case found for #{test_case.id} }. Known: #{@test_case_started_id_by_test_case_id.keys}" unless @test_case_started_id_by_test_case_id.key?(test_case.id)
@test_case_started_id_by_test_case_id[test_case.id]
end
private
def on_test_case_created(event)
@attempts_by_test_case_id[event.test_case.id] = 0
@test_case_started_id_by_test_case_id[event.test_case.id] = nil
end
def on_test_case_started(event)
@attempts_by_test_case_id[event.test_case.id] += 1
@test_case_started_id_by_test_case_id[event.test_case.id] = @config.id_generator.new_id
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/hook_by_test_step.rb | lib/cucumber/formatter/query/hook_by_test_step.rb | # frozen_string_literal: true
require 'cucumber/formatter/errors'
module Cucumber
module Formatter
module Query
class HookByTestStep
def initialize(config)
@hook_id_by_test_step_id = {}
config.on_event :test_step_created, &method(:on_test_step_created)
config.on_event :hook_test_step_created, &method(:on_hook_test_step_created)
end
def hook_id(test_step)
return @hook_id_by_test_step_id[test_step.id] if @hook_id_by_test_step_id.key?(test_step.id)
raise TestStepUnknownError, "No hook found for #{test_step.id} }. Known: #{@hook_id_by_test_step_id.keys}"
end
private
def on_test_step_created(event)
@hook_id_by_test_step_id[event.test_step.id] = nil
end
def on_hook_test_step_created(event)
@hook_id_by_test_step_id[event.test_step.id] = event.hook.id
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/formatter/query/pickle_step_by_test_step.rb | lib/cucumber/formatter/query/pickle_step_by_test_step.rb | # frozen_string_literal: true
require 'cucumber/formatter/errors'
module Cucumber
module Formatter
module Query
class PickleStepByTestStep
def initialize(config)
@pickle_id_step_by_test_step_id = {}
config.on_event :test_step_created, &method(:on_test_step_created)
end
def pickle_step_id(test_step)
return @pickle_id_step_by_test_step_id[test_step.id] if @pickle_id_step_by_test_step_id.key?(test_step.id)
raise TestStepUnknownError, "No pickle step found for #{test_step.id} }. Known: #{@pickle_id_step_by_test_step_id.keys}"
end
private
def on_test_step_created(event)
@pickle_id_step_by_test_step_id[event.test_step.id] = event.pickle_step.id
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/gherkin/data_table_parser.rb | lib/cucumber/gherkin/data_table_parser.rb | # frozen_string_literal: true
require 'gherkin'
require 'gherkin/dialect'
module Cucumber
module Gherkin
class DataTableParser
def initialize(builder)
@builder = builder
end
def parse(text)
gherkin_document = nil
messages = ::Gherkin.from_source('dummy', feature_header + text, gherkin_options)
messages.each do |message|
gherkin_document = message.gherkin_document.to_h unless message.gherkin_document.nil?
end
return if gherkin_document.nil?
gherkin_document[:feature][:children][0][:scenario][:steps][0][:data_table][:rows].each do |row|
@builder.row(row[:cells].map { |cell| cell[:value] })
end
end
def gherkin_options
{
include_source: false,
include_gherkin_document: true,
include_pickles: false
}
end
def feature_header
dialect = ::Gherkin::Dialect.for('en')
%(#{dialect.feature_keywords[0]}:
#{dialect.scenario_keywords[0]}:
#{dialect.given_keywords[0]} x
)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/gherkin/i18n.rb | lib/cucumber/gherkin/i18n.rb | # frozen_string_literal: true
module Cucumber
module Gherkin
module I18n
class << self
def code_keyword_for(gherkin_keyword)
gherkin_keyword.gsub(/[\s',!]/, '').strip
end
def code_keywords_for(gherkin_keywords)
gherkin_keywords.reject { |kw| kw == '* ' }.map { |kw| code_keyword_for(kw) }
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/gherkin/steps_parser.rb | lib/cucumber/gherkin/steps_parser.rb | # frozen_string_literal: true
require 'gherkin'
require 'gherkin/dialect'
module Cucumber
module Gherkin
class StepsParser
def initialize(builder, language)
@builder = builder
@language = language
end
def parse(text)
dialect = ::Gherkin::Dialect.for(@language)
gherkin_document = nil
messages = ::Gherkin.from_source('dummy', feature_header(dialect) + text, gherkin_options)
messages.each do |message|
gherkin_document = message.gherkin_document.to_h unless message.gherkin_document.nil?
end
@builder.steps(gherkin_document[:feature][:children][0][:scenario][:steps])
end
def gherkin_options
{
default_dialect: @language,
include_source: false,
include_gherkin_document: true,
include_pickles: false
}
end
def feature_header(dialect)
%(#{dialect.feature_keywords[0]}:
#{dialect.scenario_keywords[0]}:
)
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/gherkin/formatter/ansi_escapes.rb | lib/cucumber/gherkin/formatter/ansi_escapes.rb | # frozen_string_literal: true
module Cucumber
module Gherkin
module Formatter
# Defines aliases for ANSI coloured output. Default colours can be overridden by defining
# a <tt>GHERKIN_COLORS</tt> variable in your shell, very much like how you can
# tweak the familiar POSIX command <tt>ls</tt> with $LSCOLORS: http://linux-sxs.org/housekeeping/lscolors.html
#
# The colours that you can change are:
#
# <tt>undefined</tt>:: defaults to <tt>yellow</tt>
# <tt>pending</tt>:: defaults to <tt>yellow</tt>
# <tt>pending_arg</tt>:: defaults to <tt>yellow,bold</tt>
# <tt>executing</tt>:: defaults to <tt>grey</tt>
# <tt>executing_arg</tt>:: defaults to <tt>grey,bold</tt>
# <tt>failed</tt>:: defaults to <tt>red</tt>
# <tt>failed_arg</tt>:: defaults to <tt>red,bold</tt>
# <tt>passed</tt>:: defaults to <tt>green</tt>
# <tt>passed_arg</tt>:: defaults to <tt>green,bold</tt>
# <tt>outline</tt>:: defaults to <tt>cyan</tt>
# <tt>outline_arg</tt>:: defaults to <tt>cyan,bold</tt>
# <tt>skipped</tt>:: defaults to <tt>cyan</tt>
# <tt>skipped_arg</tt>:: defaults to <tt>cyan,bold</tt>
# <tt>comment</tt>:: defaults to <tt>grey</tt>
# <tt>tag</tt>:: defaults to <tt>cyan</tt>
#
# For instance, if your shell has a black background and a green font (like the
# "Homebrew" settings for OS X' Terminal.app), you may want to override passed
# steps to be white instead of green. Examples:
#
# export GHERKIN_COLORS="passed=white"
# export GHERKIN_COLORS="passed=white,bold:passed_arg=white,bold,underline"
#
# (If you're on Windows, use SET instead of export).
# To see what colours and effects are available, just run this in your shell:
#
# ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"
#
# Although not listed, you can also use <tt>grey</tt>
module AnsiEscapes
COLORS = {
'black' => "\e[30m",
'red' => "\e[31m",
'green' => "\e[32m",
'yellow' => "\e[33m",
'blue' => "\e[34m",
'magenta' => "\e[35m",
'cyan' => "\e[36m",
'white' => "\e[37m",
'grey' => "\e[90m",
'bold' => "\e[1m"
}.freeze
ALIASES = Hash.new do |h, k|
"#{h[Regexp.last_match(1)]},bold" if k.to_s =~ /(.*)_arg/
end.merge(
'undefined' => 'yellow',
'pending' => 'yellow',
'executing' => 'grey',
'failed' => 'red',
'passed' => 'green',
'outline' => 'cyan',
'skipped' => 'cyan',
'comments' => 'grey',
'tag' => 'cyan'
)
# Example: export GHERKIN_COLORS="passed=red:failed=yellow"
ENV.fetch('GHERKIN_COLORS', '').split(':').each do |pair|
rule, colour = pair.split('=')
ALIASES[colour] = rule
end
ALIASES.each_key do |key|
define_method(key) do
ALIASES[key].split(',').map { |color| COLORS[color] }.join('')
end
define_method("#{key}_arg") do
ALIASES["#{key}_arg"].split(',').map { |color| COLORS[color] }.join('')
end
end
def reset
"\e[0m"
end
def up(amount)
"\e[#{amount}A"
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/gherkin/formatter/escaping.rb | lib/cucumber/gherkin/formatter/escaping.rb | # frozen_string_literal: true
module Cucumber
module Gherkin
module Formatter
module Escaping
# Escapes a pipes and backslashes:
#
# * | becomes \|
# * \ becomes \\
#
# This is used in the pretty formatter.
def escape_cell(sym)
sym.gsub(/\\(?!\|)/, '\\\\\\\\').gsub(/\n/, '\\n').gsub(/\|/, '\\|')
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/meta_message_builder.rb | lib/cucumber/runtime/meta_message_builder.rb | # frozen_string_literal: true
require 'cucumber/messages'
require 'cucumber/ci_environment'
module Cucumber
class Runtime
# Builder to instantiate a Cucumber::Messages::Meta message filled-in with
# the runtime meta-data:
# - protocol version: the version of the Cucumber::Messages protocol
# - implementation: the name and version of the implementation (e.g. cucumber-ruby 8.0.0)
# - runtime: the name and version of the runtime (e.g. ruby 3.0.1)
# - os: the name and version of the operating system (e.g. linux 3.13.0-45-generic)
# - cpu: the name of the CPU (e.g. x86_64)
# - ci: information about the CI environment if any, including:
# - name: the name of the CI environment (e.g. Jenkins)
# - url: the URL of the CI environment (e.g. https://ci.example.com)
# - build_number: the build number of the CI environment (e.g. 123)
# - git: the git information of the CI environment if any
# - remote: the remote of the git repository (e.g. git@github.com:cucumber/cucumber-ruby.git)
# - revision: the revision of the git repository (e.g. abcdef)
# - branch: the name of the git branch (e.g. main)
# - tag: the name of the git tag (e.g. v1.0.0)
class MetaMessageBuilder
class << self
# Builds a Cucumber::Messages::Meta filled-in with the runtime meta-data
#
# @param [env] environment data from which the CI information will be
# retrieved (default ENV). Can be used to mock the environment for
# testing purpose.
#
# @return [Cucumber::Messages::Meta] the meta message
#
# @see Cucumber::Runtime::MetaMessageBuilder
#
# @example
# Cucumber::Runtime::MetaMessageBuilder.build_meta_message
#
def build_meta_message(env = ENV)
Cucumber::Messages::Meta.new(
protocol_version: protocol_version,
implementation: implementation,
runtime: runtime,
os: os,
cpu: cpu,
ci: ci(env)
)
end
private
def protocol_version
Cucumber::Messages::VERSION
end
def implementation
Cucumber::Messages::Product.new(
name: 'cucumber-ruby',
version: Cucumber::VERSION
)
end
def runtime
Cucumber::Messages::Product.new(
name: RUBY_ENGINE,
version: RUBY_VERSION
)
end
def os
Cucumber::Messages::Product.new(
name: RbConfig::CONFIG['target_os'],
version: Sys::Uname.uname.version
)
end
def cpu
Cucumber::Messages::Product.new(
name: RbConfig::CONFIG['target_cpu']
)
end
def ci(env)
ci_data = Cucumber::CiEnvironment.detect_ci_environment(env)
return nil unless ci_data
Cucumber::Messages::Ci.new(
name: ci_data[:name],
url: ci_data[:url],
build_number: ci_data[:buildNumber],
git: git_info(ci_data)
)
end
def git_info(ci_data)
return nil unless ci_data[:git]
Cucumber::Messages::Git.new(
remote: ci_data[:git][:remote],
revision: ci_data[:git][:revision],
branch: ci_data[:git][:branch],
tag: ci_data[:git][:tag]
)
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/step_hooks.rb | lib/cucumber/runtime/step_hooks.rb | # frozen_string_literal: true
module Cucumber
class Runtime
class StepHooks
def initialize(id_generator, hooks, event_bus)
@hooks = hooks
@id_generator = id_generator
@event_bus = event_bus
end
def apply(test_steps)
test_steps.flat_map do |test_step|
[test_step] + after_step_hooks(test_step)
end
end
private
def after_step_hooks(test_step)
@hooks.map do |hook|
action = ->(*args) { hook.invoke('AfterStep', [args, test_step]) }
hook_step = Hooks.after_step_hook(@id_generator.new_id, test_step, hook.location, &action)
@event_bus.hook_test_step_created(hook_step, hook)
hook_step
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/before_hooks.rb | lib/cucumber/runtime/before_hooks.rb | # frozen_string_literal: true
require 'cucumber/hooks'
module Cucumber
class Runtime
class BeforeHooks
def initialize(id_generator, hooks, scenario, event_bus)
@hooks = hooks
@scenario = scenario
@id_generator = id_generator
@event_bus = event_bus
end
def apply_to(test_case)
test_case.with_steps(
before_hooks + test_case.test_steps
)
end
private
def before_hooks
@hooks.map do |hook|
action_block = ->(result) { hook.invoke('Before', @scenario.with_result(result)) }
hook_step = Hooks.before_hook(@id_generator.new_id, hook.location, &action_block)
@event_bus.hook_test_step_created(hook_step, hook)
hook_step
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/user_interface.rb | lib/cucumber/runtime/user_interface.rb | # frozen_string_literal: true
require 'timeout'
module Cucumber
class Runtime
module UserInterface
attr_writer :visitor
# Suspends execution and prompts +question+ to the console (STDOUT).
# An operator (manual tester) can then enter a line of text and hit
# <ENTER>. The entered text is returned, and both +question+ and
# the result is added to the output using #puts.
#
# If you want a beep to happen (to grab the manual tester's attention),
# just prepend ASCII character 7 to the question:
#
# ask("#{7.chr}How many cukes are in the external system?")
#
# If that doesn't issue a beep, you can shell out to something else
# that makes a sound before invoking #ask.
#
def ask(question, timeout_seconds)
$stdout.puts(question)
$stdout.flush
puts(question)
answer = if Cucumber::JRUBY
jruby_gets(timeout_seconds)
else
mri_gets(timeout_seconds)
end
raise("Waited for input for #{timeout_seconds} seconds, then timed out.") unless answer
puts(answer)
answer
end
# Embed +src+ of MIME type +mime_type+ into the output. The +src+ argument may
# be a path to a file, or if it's an image it may also be a Base64 encoded image.
# The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
#
def attach(src, media_type, filename)
@visitor.attach(src, media_type, filename)
end
private
def mri_gets(timeout_seconds)
Timeout.timeout(timeout_seconds) do
$stdin.gets
end
rescue Timeout::Error
nil
end
def jruby_gets(timeout_seconds)
answer = nil
t = java.lang.Thread.new do
answer = $stdin.gets
end
t.start
t.join(timeout_seconds * 1000)
answer
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/support_code.rb | lib/cucumber/runtime/support_code.rb | # frozen_string_literal: true
require 'cucumber/constantize'
require 'cucumber/runtime/for_programming_languages'
require 'cucumber/runtime/step_hooks'
require 'cucumber/runtime/before_hooks'
require 'cucumber/runtime/after_hooks'
require 'cucumber/gherkin/steps_parser'
require 'cucumber/step_match_search'
module Cucumber
class Runtime
class SupportCode
require 'forwardable'
class StepInvoker
def initialize(support_code)
@support_code = support_code
end
def steps(steps)
steps.each { |step| step(step) }
end
def step(step)
location = Core::Test::Location.of_caller
@support_code.invoke_dynamic_step(step[:text], multiline_arg(step, location))
end
def multiline_arg(step, location)
if !step[:doc_string].nil?
MultilineArgument.from(step[:doc_string][:content], location, step[:doc_string][:content_type])
elsif !step[:data_table].nil?
MultilineArgument::DataTable.from(step[:data_table][:rows].map { |row| row[:cells].map { |cell| cell[:value] } })
else
MultilineArgument.from(nil)
end
end
end
include Constantize
attr_reader :registry
def initialize(user_interface, configuration = Configuration.default)
@configuration = configuration
# TODO: needs a better name, or inlining its methods
@runtime_facade = Runtime::ForProgrammingLanguages.new(self, user_interface)
@registry = Cucumber::Glue::RegistryAndMore.new(@runtime_facade, @configuration)
end
def configure(new_configuration)
@configuration = Configuration.new(new_configuration)
end
# Invokes a series of steps +steps_text+. Example:
#
# invoke(%Q{
# Given I have 8 cukes in my belly
# Then I should not be thirsty
# })
def invoke_dynamic_steps(steps_text, iso_code, _location)
parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self), iso_code)
parser.parse(steps_text)
end
# @api private
# This allows users to attempt to find, match and execute steps
# from code as the features are running, as opposed to regular
# steps which are compiled into test steps before execution.
#
# These are commonly called nested steps.
def invoke_dynamic_step(step_name, multiline_argument, _location = nil)
matches = step_matches(step_name)
raise UndefinedDynamicStep, step_name if matches.empty?
matches.first.invoke(multiline_argument)
end
def load_files!(files)
log.debug("Code:\n")
files.each do |file|
load_file(file)
end
log.debug("\n")
end
def load_files_from_paths(paths)
files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
load_files! files
end
def unmatched_step_definitions
registry.unmatched_step_definitions
end
def fire_hook(name, *args)
# TODO: kill with fire
registry.send(name, *args)
end
def step_definitions
registry.step_definitions
end
def find_after_step_hooks(test_case)
scenario = RunningTestCase.new(test_case)
hooks = registry.hooks_for(:after_step, scenario)
StepHooks.new(@configuration.id_generator, hooks, @configuration.event_bus)
end
def apply_before_hooks(test_case)
return test_case if test_case.test_steps.empty?
scenario = RunningTestCase.new(test_case)
hooks = registry.hooks_for(:before, scenario)
BeforeHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
end
def apply_after_hooks(test_case)
return test_case if test_case.test_steps.empty?
scenario = RunningTestCase.new(test_case)
hooks = registry.hooks_for(:after, scenario)
AfterHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
end
def find_around_hooks(test_case)
scenario = RunningTestCase.new(test_case)
registry.hooks_for(:around, scenario).map do |hook|
Hooks.around_hook do |run_scenario|
hook.invoke('Around', scenario, &run_scenario)
end
end
end
private
def step_matches(step_name)
StepMatchSearch.new(registry.method(:step_matches), @configuration).call(step_name)
end
def load_file(file)
log.debug(" * #{file}\n")
registry.load_code_file(file)
end
def log
Cucumber.logger
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/for_programming_languages.rb | lib/cucumber/runtime/for_programming_languages.rb | # frozen_string_literal: true
require 'forwardable'
require 'cucumber/core/test/doc_string'
module Cucumber
class Runtime
# This is what a programming language will consider to be a runtime.
#
# It's a thin class that directs the handful of methods needed by the programming languages to the right place
class ForProgrammingLanguages
extend Forwardable
attr_reader :support_code
def initialize(support_code, user_interface)
@support_code = support_code
@user_interface = user_interface
end
def_delegators :@user_interface,
:embed,
:attach,
:ask,
:puts,
:features_paths,
:step_match
def_delegators :@support_code,
:invoke_dynamic_steps,
:invoke_dynamic_step
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/runtime/after_hooks.rb | lib/cucumber/runtime/after_hooks.rb | # frozen_string_literal: true
module Cucumber
class Runtime
class AfterHooks
def initialize(id_generator, hooks, scenario, event_bus)
@hooks = hooks
@scenario = scenario
@id_generator = id_generator
@event_bus = event_bus
end
def apply_to(test_case)
test_case.with_steps(test_case.test_steps + after_hooks.reverse)
end
private
def after_hooks
@hooks.map do |hook|
action = ->(result) { hook.invoke('After', @scenario.with_result(result)) }
hook_step = Hooks.after_hook(@id_generator.new_id, hook.location, &action)
@event_bus.hook_test_step_created(hook_step, hook)
hook_step
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/term/banner.rb | lib/cucumber/term/banner.rb | # frozen_string_literal: true
require 'cucumber/term/ansicolor'
module Cucumber
module Term
module Banner
def display_banner(lines, io, border_modifiers = nil)
BannerMaker.new.display_banner(lines, io, border_modifiers || %i[green bold])
end
class BannerMaker
include Term::ANSIColor
def display_banner(lines, io, border_modifiers)
lines = lines.split("\n") if lines.is_a? String
longest_line_length = lines.map { |line| line_length(line) }.max
io.puts apply_modifiers("┌#{'─' * (longest_line_length + 2)}┐", border_modifiers)
lines.map do |line|
padding = ' ' * (longest_line_length - line_length(line))
io.puts "#{apply_modifiers('│', border_modifiers)} #{display_line(line)}#{padding} #{apply_modifiers('│', border_modifiers)}"
end
io.puts apply_modifiers("└#{'─' * (longest_line_length + 2)}┘", border_modifiers)
end
private
def display_line(line)
line.is_a?(Array) ? line.map { |span| display_span(span) }.join : line
end
def display_span(span)
return apply_modifiers(span.shift, span) if span.is_a?(Array)
span
end
def apply_modifiers(str, modifiers)
display = str
modifiers.each { |modifier| display = send(modifier, display) }
display
end
def line_length(line)
if line.is_a?(Array)
line.map { |span| span_length(span) }.sum
else
line.length
end
end
def span_length(span)
span.is_a?(Array) ? span[0].length : span.length
end
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/term/ansicolor.rb | lib/cucumber/term/ansicolor.rb | # frozen_string_literal: true
module Cucumber
module Term
# This module allows to colorize text using ANSI escape sequences.
#
# Include the module in your class and use its methods to colorize text.
#
# Example:
#
# require 'cucumber/term/ansicolor'
#
# class MyFormatter
# include Cucumber::Term::ANSIColor
#
# def initialize(config)
# $stdout.puts yellow("Initializing formatter")
# $stdout.puts green("Coloring is active \o/") if Cucumber::Term::ANSIColor.coloring?
# $stdout.puts grey("Feature path:") + blue(bold(config.feature_dirs))
# end
# end
#
# To see what colours and effects are available, just run this in your shell:
#
# ruby -e "require 'rubygems'; require 'cucumber/term/ansicolor'; puts Cucumber::Term::ANSIColor.attributes"
#
module ANSIColor
# :stopdoc:
ATTRIBUTES = [
[:clear, 0],
[:reset, 0], # synonym for :clear
[:bold, 1],
[:dark, 2],
[:italic, 3], # not widely implemented
[:underline, 4],
[:underscore, 4], # synonym for :underline
[:blink, 5],
[:rapid_blink, 6], # not widely implemented
[:negative, 7], # no reverse because of String#reverse
[:concealed, 8],
[:strikethrough, 9], # not widely implemented
[:black, 30],
[:red, 31],
[:green, 32],
[:yellow, 33],
[:blue, 34],
[:magenta, 35],
[:cyan, 36],
[:white, 37],
[:grey, 90],
[:on_black, 40],
[:on_red, 41],
[:on_green, 42],
[:on_yellow, 43],
[:on_blue, 44],
[:on_magenta, 45],
[:on_cyan, 46],
[:on_white, 47]
].freeze
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
# :startdoc:
# Regular expression that is used to scan for ANSI-sequences while
# uncoloring strings.
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/.freeze
@coloring = true
class << self
# Turns the coloring on or off globally, so you can easily do
# this for example:
# Cucumber::Term::ANSIColor::coloring = $stdout.isatty
attr_accessor :coloring
# Returns true, if the coloring function of this module
# is switched on, false otherwise.
alias coloring? :coloring
def included(klass)
return unless klass == String
ATTRIBUTES.delete(:clear)
ATTRIBUTE_NAMES.delete(:clear)
end
end
ATTRIBUTES.each do |color_name, color_code|
define_method(color_name) do |text = nil, &block|
if block
colorize(block.call, color_code)
elsif text
colorize(text, color_code)
elsif respond_to?(:to_str)
colorize(to_str, color_code)
else
colorize(nil, color_code) # switch coloration on
end
end
end
# Returns an uncolored version of the string
# ANSI-sequences are stripped from the string.
def uncolored(text = nil)
if block_given?
uncolorize(yield)
elsif text
uncolorize(text)
elsif respond_to?(:to_str)
uncolorize(to_str)
else
''
end
end
# Returns an array of all Cucumber::Term::ANSIColor attributes as symbols.
def attributes
ATTRIBUTE_NAMES
end
private
def colorize(text, color_code)
return String.new(text || '') unless Cucumber::Term::ANSIColor.coloring?
return "\e[#{color_code}m" unless text
"\e[#{color_code}m#{text}\e[0m"
end
def uncolorize(string)
string.gsub(COLORED_REGEXP, '')
end
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/step_activated.rb | lib/cucumber/events/step_activated.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired when a step is activated
class StepActivated < Core::Event.new(:test_step, :step_match)
# The test step that was matched.
#
# @return [Cucumber::Core::Test::Step]
attr_reader :test_step
# Information about the matching definition.
#
# @return [Cucumber::StepMatch]
attr_reader :step_match
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/envelope.rb | lib/cucumber/events/envelope.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
class Envelope < Core::Event.new(:envelope)
attr_reader :envelope
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_step_created.rb | lib/cucumber/events/test_step_created.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired when a TestStep is created from a PickleStep
class TestStepCreated < Core::Event.new(:test_step, :pickle_step)
attr_reader :test_step, :pickle_step
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_case_started.rb | lib/cucumber/events/test_case_started.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Signals that a {Cucumber::Core::Test::Case} is about to be executed
class TestCaseStarted < Core::Events::TestCaseStarted
# @return [Cucumber::Core::Test::Case] the test case to be executed
attr_reader :test_case
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_case_finished.rb | lib/cucumber/events/test_case_finished.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Signals that a {Cucumber::Core::Test::Case} has finished executing
class TestCaseFinished < Core::Events::TestCaseFinished
# @return [Cucumber::Core::Test::Case] that was executed
attr_reader :test_case
# @return [Cucumber::Core::Test::Result] the result of running the {Cucumber::Core::Test::Case}
attr_reader :result
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_run_started.rb | lib/cucumber/events/test_run_started.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired once all test cases have been filtered before
# the first one is executed.
class TestRunStarted < Core::Event.new(:test_cases)
# @return [Array<Cucumber::Core::Test::Case>] the test cases to be executed
attr_reader :test_cases
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_step_finished.rb | lib/cucumber/events/test_step_finished.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Signals that a {Cucumber::Core::Test::Step} has finished executing
class TestStepFinished < Core::Events::TestStepFinished
# @return [Cucumber::Core::Test::Step] the test step that was executed
attr_reader :test_step
# @return [Cucumber::Core::Test::Result] the result of running the {Cucumber::Core::Test::Step}
attr_reader :result
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/gherkin_source_read.rb | lib/cucumber/events/gherkin_source_read.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Fired after we've read in the contents of a feature file
class GherkinSourceRead < Core::Event.new(:path, :body)
# The path to the file
attr_reader :path
# The raw Gherkin source
attr_reader :body
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_run_finished.rb | lib/cucumber/events/test_run_finished.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired after all test cases have finished executing
class TestRunFinished < Core::Event.new(:success)
attr_reader :success
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/gherkin_source_parsed.rb | lib/cucumber/events/gherkin_source_parsed.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Fired after we've parsed the contents of a feature file
class GherkinSourceParsed < Core::Event.new(:gherkin_document)
# The Gherkin Ast
attr_reader :gherkin_document
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/hook_test_step_created.rb | lib/cucumber/events/hook_test_step_created.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired when a step is created from a hook
class HookTestStepCreated < Core::Event.new(:test_step, :hook)
attr_reader :test_step, :hook
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/step_definition_registered.rb | lib/cucumber/events/step_definition_registered.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired after each step definition has been registered
class StepDefinitionRegistered < Core::Event.new(:step_definition)
# The step definition that was just registered.
#
# @return [RbSupport::RbStepDefinition]
attr_reader :step_definition
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_case_ready.rb | lib/cucumber/events/test_case_ready.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired when a Test::Case is ready to be ran (matching has been done, hooks added etc)
class TestCaseReady < Core::Event.new(:test_case)
attr_reader :test_case
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/test_case_created.rb | lib/cucumber/events/test_case_created.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
# Event fired when a Test::Case is created from a Pickle
class TestCaseCreated < Core::Event.new(:test_case, :pickle)
attr_reader :test_case, :pickle
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
cucumber/cucumber-ruby | https://github.com/cucumber/cucumber-ruby/blob/50c37055b0e5e74de50a026756ca915f0f7b7820/lib/cucumber/events/undefined_parameter_type.rb | lib/cucumber/events/undefined_parameter_type.rb | # frozen_string_literal: true
require 'cucumber/core/events'
module Cucumber
module Events
class UndefinedParameterType < Core::Event.new(:type_name, :expression)
attr_reader :type_name, :expression
end
end
end
| ruby | MIT | 50c37055b0e5e74de50a026756ca915f0f7b7820 | 2026-01-04T15:43:43.142161Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.