Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Later in this document, bundler is considered being used so all commands are usi
- Ruby 3.3
- Ruby 3.2
- Ruby 3.1
- Ruby 3.0
- TruffleRuby 24.0.0+
- JRuby 9.4+ (with [some limitations](https://github.com/cucumber/cucumber-ruby/blob/main/docs/jruby-limitations.md))

Expand Down
2 changes: 1 addition & 1 deletion cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Gem::Specification.new do |s|
s.name = 'cucumber'
s.version = File.read(File.expand_path('VERSION', __dir__)).strip
s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke']
s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke', 'Luke Hill']
s.description = 'Behaviour Driven Development with elegance and joy'
s.summary = "cucumber-#{s.version}"
s.email = 'cukes@googlegroups.com'
Expand Down
8 changes: 3 additions & 5 deletions lib/cucumber/cli/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

module Cucumber
module Cli
class YmlLoadError < StandardError; end

class ProfilesNotDefinedError < YmlLoadError; end

class ProfileNotFound < StandardError; end
YmlLoadError = Class.new(StandardError)
ProfilesNotDefinedError = Class.new(YmlLoadError)
ProfileNotFound = Class.new(StandardError)

class Configuration
include Constantize
Expand Down
44 changes: 21 additions & 23 deletions lib/cucumber/cli/profile_loader.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'yaml'
require 'erb'

module Cucumber
module Cli
Expand All @@ -11,12 +12,12 @@ def initialize

def args_from(profile)
unless cucumber_yml.key?(profile)
raise(ProfileNotFound, <<~END_OF_ERROR)
raise(ProfileNotFound, <<~ERROR_MESSAGE)
Could not find profile: '#{profile}'

Defined profiles in cucumber.yml:
* #{cucumber_yml.keys.sort.join("\n * ")}
END_OF_ERROR
ERROR_MESSAGE
end

args_from_yml = cucumber_yml[profile] || ''
Expand Down Expand Up @@ -56,9 +57,12 @@ def cucumber_yml
process_configuration_file_with_erb
load_configuration

if @cucumber_yml.nil? || !@cucumber_yml.is_a?(Hash)
raise(YmlLoadError, 'cucumber.yml was found, but was blank or malformed. ' \
"Please refer to cucumber's documentation on correct profile usage.\n")
unless @cucumber_yml.is_a?(Hash)
raise(YmlLoadError, <<~ERROR_MESSAGE)
cucumber.yml was found, but was blank or malformed.
Please refer to cucumber's documentation on correct profile usage.
Type 'cucumber --help' for usage.
ERROR_MESSAGE
end

@cucumber_yml
Expand All @@ -67,32 +71,26 @@ def cucumber_yml
def ensure_configuration_file_exists
return if cucumber_yml_defined?

raise(ProfilesNotDefinedError, "cucumber.yml was not found. Current directory is #{Dir.pwd}." \
"Please refer to cucumber's documentation on defining profiles in cucumber.yml. You must define" \
"a 'default' profile to use the cucumber command without any arguments.\nType 'cucumber --help' for usage.\n")
raise(ProfilesNotDefinedError, <<~ERROR_MESSAGE)
cucumber.yml was not found. Current directory is #{Dir.pwd}.
Please refer to cucumber's documentation on defining profiles in cucumber.yml.
You must define a 'default' profile to use the cucumber command without any arguments.
Type 'cucumber --help' for usage.
ERROR_MESSAGE
end

def process_configuration_file_with_erb
require 'erb'
begin
@cucumber_erb = ERB.new(IO.read(cucumber_file), trim_mode: '%').result(binding)
rescue StandardError
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed with ERB. Please refer to cucumber's documentation on correct profile usage.\n#{$ERROR_INFO.inspect}")
end
@cucumber_erb = ERB.new(IO.read(cucumber_file), trim_mode: '%').result(binding)
rescue StandardError
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed with ERB. Please refer to cucumber's documentation on correct profile usage.\n#{$ERROR_INFO.inspect}")
end

def load_configuration
require 'yaml'
begin
@cucumber_yml = YAML.load(@cucumber_erb)
rescue StandardError
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.\n")
end
@cucumber_yml = YAML.load(@cucumber_erb)
rescue StandardError
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.")
end

# Locates cucumber.yml file. The file can end in .yml or .yaml,
# and be located in the current directory (eg. project root) or
# in a .config/ or config/ subdirectory of the current directory.
def cucumber_file
@cucumber_file ||= Dir.glob('{,.config/,config/}cucumber{.yml,.yaml}').first
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/filters/activate_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def find_match(test_step)
end

class FindMatch
attr_reader :step_match_search, :configuration, :test_step
private :step_match_search, :configuration, :test_step

def initialize(step_match_search, configuration, test_step)
@step_match_search = step_match_search
@configuration = configuration
Expand All @@ -58,9 +61,6 @@ def result

private

attr_reader :step_match_search, :configuration, :test_step
private :step_match_search, :configuration, :test_step

def match
matches.first
end
Expand Down
16 changes: 15 additions & 1 deletion lib/cucumber/formatter/usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ module Cucumber
module Formatter
class Usage < Progress
include Console
class StepDefKey < StepDefinitionLight
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)
Expand Down
9 changes: 5 additions & 4 deletions lib/cucumber/platform.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# Detect the platform we're running on so we can tweak behaviour in various places.
require 'rbconfig'
require 'cucumber/core/platform'

Expand All @@ -11,12 +10,14 @@ module Cucumber
RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])

class << self
attr_accessor :use_full_backtrace
attr_writer :use_full_backtrace

def use_full_backtrace
@use_full_backtrace ||= false
end

# @private
def file_mode(mode, encoding = 'UTF-8')
"#{mode}:#{encoding}"
end
end
self.use_full_backtrace = false
end
2 changes: 1 addition & 1 deletion spec/cucumber/cli/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def reset_config
end

it 'issues a helpful error message when cucumber.yml is blank or malformed' do
expected_error_message = /cucumber\.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
expected_error_message = /cucumber\.yml was found, but was blank or malformed.\nPlease refer to cucumber's documentation on correct profile usage./

['', 'sfsadfs', "--- \n- an\n- array\n", '---dddfd'].each do |bad_input|
given_cucumber_yml_defined_as(bad_input)
Expand Down
Loading