diff --git a/README.md b/README.md index d565a8633..3e228e2fa 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/cucumber.gemspec b/cucumber.gemspec index f62ed3881..fd2d22c53 100644 --- a/cucumber.gemspec +++ b/cucumber.gemspec @@ -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' diff --git a/lib/cucumber/cli/configuration.rb b/lib/cucumber/cli/configuration.rb index 8567cdee5..8afbca789 100644 --- a/lib/cucumber/cli/configuration.rb +++ b/lib/cucumber/cli/configuration.rb @@ -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 diff --git a/lib/cucumber/cli/profile_loader.rb b/lib/cucumber/cli/profile_loader.rb index 27886aa42..dc8a1a6ea 100644 --- a/lib/cucumber/cli/profile_loader.rb +++ b/lib/cucumber/cli/profile_loader.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'yaml' +require 'erb' module Cucumber module Cli @@ -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] || '' @@ -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 @@ -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 diff --git a/lib/cucumber/filters/activate_steps.rb b/lib/cucumber/filters/activate_steps.rb index 16010e039..937057832 100644 --- a/lib/cucumber/filters/activate_steps.rb +++ b/lib/cucumber/filters/activate_steps.rb @@ -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 @@ -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 diff --git a/lib/cucumber/formatter/usage.rb b/lib/cucumber/formatter/usage.rb index 8ea45618a..846b46562 100644 --- a/lib/cucumber/formatter/usage.rb +++ b/lib/cucumber/formatter/usage.rb @@ -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) diff --git a/lib/cucumber/platform.rb b/lib/cucumber/platform.rb index 112025a9d..8d5c52bf2 100644 --- a/lib/cucumber/platform.rb +++ b/lib/cucumber/platform.rb @@ -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' @@ -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 diff --git a/spec/cucumber/cli/configuration_spec.rb b/spec/cucumber/cli/configuration_spec.rb index c73126260..6c92248ff 100644 --- a/spec/cucumber/cli/configuration_spec.rb +++ b/spec/cucumber/cli/configuration_spec.rb @@ -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)