Skip to content

Commit 8fa3468

Browse files
authored
Refactor/minor tidies (#1800)
* Minor doc tidies * Simplify a little bit of code regarding error messages * Remove redundant logic for processing profile logic * Minor fix to test * Reorder readers and priv methods * Remove deprecation notice from usage formatter which uses step key class
1 parent 3d1191d commit 8fa3468

File tree

8 files changed

+49
-39
lines changed

8 files changed

+49
-39
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ Later in this document, bundler is considered being used so all commands are usi
4949
- Ruby 3.3
5050
- Ruby 3.2
5151
- Ruby 3.1
52-
- Ruby 3.0
5352
- TruffleRuby 24.0.0+
5453
- JRuby 9.4+ (with [some limitations](https://github.com/cucumber/cucumber-ruby/blob/main/docs/jruby-limitations.md))
5554

cucumber.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Gem::Specification.new do |s|
44
s.name = 'cucumber'
55
s.version = File.read(File.expand_path('VERSION', __dir__)).strip
6-
s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke']
6+
s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke', 'Luke Hill']
77
s.description = 'Behaviour Driven Development with elegance and joy'
88
s.summary = "cucumber-#{s.version}"
99
s.email = '[email protected]'

lib/cucumber/cli/configuration.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
module Cucumber
1010
module Cli
11-
class YmlLoadError < StandardError; end
12-
13-
class ProfilesNotDefinedError < YmlLoadError; end
14-
15-
class ProfileNotFound < StandardError; end
11+
YmlLoadError = Class.new(StandardError)
12+
ProfilesNotDefinedError = Class.new(YmlLoadError)
13+
ProfileNotFound = Class.new(StandardError)
1614

1715
class Configuration
1816
include Constantize

lib/cucumber/cli/profile_loader.rb

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'yaml'
4+
require 'erb'
45

56
module Cucumber
67
module Cli
@@ -11,12 +12,12 @@ def initialize
1112

1213
def args_from(profile)
1314
unless cucumber_yml.key?(profile)
14-
raise(ProfileNotFound, <<~END_OF_ERROR)
15+
raise(ProfileNotFound, <<~ERROR_MESSAGE)
1516
Could not find profile: '#{profile}'
1617
1718
Defined profiles in cucumber.yml:
1819
* #{cucumber_yml.keys.sort.join("\n * ")}
19-
END_OF_ERROR
20+
ERROR_MESSAGE
2021
end
2122

2223
args_from_yml = cucumber_yml[profile] || ''
@@ -56,9 +57,12 @@ def cucumber_yml
5657
process_configuration_file_with_erb
5758
load_configuration
5859

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

6468
@cucumber_yml
@@ -67,32 +71,26 @@ def cucumber_yml
6771
def ensure_configuration_file_exists
6872
return if cucumber_yml_defined?
6973

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

7582
def process_configuration_file_with_erb
76-
require 'erb'
77-
begin
78-
@cucumber_erb = ERB.new(IO.read(cucumber_file), trim_mode: '%').result(binding)
79-
rescue StandardError
80-
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}")
81-
end
83+
@cucumber_erb = ERB.new(IO.read(cucumber_file), trim_mode: '%').result(binding)
84+
rescue StandardError
85+
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}")
8286
end
8387

8488
def load_configuration
85-
require 'yaml'
86-
begin
87-
@cucumber_yml = YAML.load(@cucumber_erb)
88-
rescue StandardError
89-
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.\n")
90-
end
89+
@cucumber_yml = YAML.load(@cucumber_erb)
90+
rescue StandardError
91+
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.")
9192
end
9293

93-
# Locates cucumber.yml file. The file can end in .yml or .yaml,
94-
# and be located in the current directory (eg. project root) or
95-
# in a .config/ or config/ subdirectory of the current directory.
9694
def cucumber_file
9795
@cucumber_file ||= Dir.glob('{,.config/,config/}cucumber{.yml,.yaml}').first
9896
end

lib/cucumber/filters/activate_steps.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def find_match(test_step)
3838
end
3939

4040
class FindMatch
41+
attr_reader :step_match_search, :configuration, :test_step
42+
private :step_match_search, :configuration, :test_step
43+
4144
def initialize(step_match_search, configuration, test_step)
4245
@step_match_search = step_match_search
4346
@configuration = configuration
@@ -58,9 +61,6 @@ def result
5861

5962
private
6063

61-
attr_reader :step_match_search, :configuration, :test_step
62-
private :step_match_search, :configuration, :test_step
63-
6464
def match
6565
matches.first
6666
end

lib/cucumber/formatter/usage.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ module Cucumber
88
module Formatter
99
class Usage < Progress
1010
include Console
11-
class StepDefKey < StepDefinitionLight
11+
class StepDefKey
1212
attr_accessor :mean_duration, :status
13+
attr_reader :regexp_source, :location
14+
15+
def initialize(regexp_source, location)
16+
@regexp_source = regexp_source
17+
@location = location
18+
end
19+
20+
def eql?(other)
21+
regexp_source == other.regexp_source && location == other.location
22+
end
23+
24+
def hash
25+
regexp_source.hash + 31 * location.to_s.hash
26+
end
1327
end
1428

1529
def initialize(config)

lib/cucumber/platform.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

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

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

1312
class << self
14-
attr_accessor :use_full_backtrace
13+
attr_writer :use_full_backtrace
14+
15+
def use_full_backtrace
16+
@use_full_backtrace ||= false
17+
end
1518

16-
# @private
1719
def file_mode(mode, encoding = 'UTF-8')
1820
"#{mode}:#{encoding}"
1921
end
2022
end
21-
self.use_full_backtrace = false
2223
end

spec/cucumber/cli/configuration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def reset_config
158158
end
159159

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

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

0 commit comments

Comments
 (0)