Skip to content

Commit

Permalink
Refactor/rubocop autofixes (#286)
Browse files Browse the repository at this point in the history
* AF: RSpec/ClassCheck

* AF: RSpec/ExampleWording

* Begin to tidy up multiple expectations in compiler

* Fix up some multiple expectation tests by unpicking them

* AF: RSpec/RedundantPredicateMatcher

* AF: HashEachMethod and tidy up some newlines

* Regenerate TODO file

* WIP investigate duration matcher composition and tidy up defined spec

* Validate change to duration matcher

* Simplify api spy used in core spec

* Update rubocop to avoid the erroneous private errors

* Autofix newly discovered cop offenses around layout
  • Loading branch information
luke-hill authored Dec 23, 2024
1 parent 4f53171 commit fc0bcaa
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 148 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ AllCops:
DisplayStyleGuide: true
NewCops: enable

# Stylistic preference to keep dev dependencies in gemspec
Gemspec/DevelopmentDependencies:
Enabled: false

# We do not support MFA at the moment with the new automated release process
Gemspec/RequireMFA:
Enabled: false
Expand Down
71 changes: 15 additions & 56 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-07-26 08:56:07 UTC using RuboCop version 1.61.0.
# on 2024-11-01 10:28:22 UTC using RuboCop version 1.61.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -12,33 +12,23 @@
# TODO: [LH] v14 Pre-release iteration -> 58 files inspected, 392 offenses detected, 100 offenses auto-correctable
# TODO: [LH] v14 Pre-release iteration 2 (Rubocop upgrade) -> 60 files inspected, 324 offenses detected, 86 offenses autocorrectable
# TODO: [LH] v14 Pre-release iteration 3 (Rubocop additional upgrade) -> 60 files inspected, 267 offenses detected, 26 offenses autocorrectable
# TODO: [LH] v15 Release incoming (Minimum ruby bump) -> 60 files inspected, 234 offenses detected, 12 offenses autocorrectable

# Offense count: 6
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
# Offense count: 1
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'cucumber-core.gemspec'
- 'spec/cucumber/core/compiler_spec.rb'

# Offense count: 1
Lint/RescueException:
Exclude:
- 'lib/cucumber/core/test/action/defined.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, consistent
Lint/SymbolConversion:
Exclude:
- 'lib/cucumber/core/event.rb'
- 'lib/cucumber/core/filter.rb'

# Offense count: 2
# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 23
Max: 21

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Expand All @@ -48,33 +38,17 @@ Metrics/MethodLength:
# Offense count: 3
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 413
Max: 423

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 8

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: be_a, be_kind_of
RSpec/ClassCheck:
Exclude:
- 'spec/cucumber/core/event_spec.rb'

# Offense count: 42
# Offense count: 38
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 18

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples.
# DisallowedExamples: works
RSpec/ExampleWording:
Exclude:
- 'spec/cucumber/core/event_bus_spec.rb'
Max: 11

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -84,7 +58,7 @@ RSpec/MetadataStyle:
Exclude:
- 'spec/cucumber/core/test/locations_filter_spec.rb'

# Offense count: 24
# Offense count: 23
RSpec/MissingExampleGroupArgument:
Exclude:
- 'spec/cucumber/core/compiler_spec.rb'
Expand All @@ -95,11 +69,11 @@ RSpec/MissingExampleGroupArgument:
- 'spec/cucumber/core/test/locations_filter_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 82
# Offense count: 75
RSpec/MultipleExpectations:
Max: 6

# Offense count: 43
# Offense count: 42
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 11
Expand All @@ -122,13 +96,6 @@ RSpec/NoExpectationExample:
- 'spec/cucumber/core/test/locations_filter_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
RSpec/RedundantPredicateMatcher:
Exclude:
- 'spec/cucumber/core/test/case_spec.rb'
- 'spec/cucumber/core/test/location_spec.rb'

# Offense count: 4
RSpec/RepeatedExample:
Exclude:
Expand All @@ -149,14 +116,6 @@ Style/ExpandPathArguments:
Exclude:
- 'Rakefile'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: Thread.current
Style/HashEachMethods:
Exclude:
- 'lib/cucumber/core/test/result.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -194,7 +153,7 @@ Style/SuperWithArgsParentheses:
- 'lib/cucumber/core/test/doc_string.rb'
- 'lib/cucumber/core/test/location.rb'

# Offense count: 2
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
# AllowedMethods: define_method
Expand Down
2 changes: 1 addition & 1 deletion cucumber-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rake', '~> 13.2'
s.add_development_dependency 'rspec', '~> 3.13'
s.add_development_dependency 'rubocop', '~> 1.61.0'
s.add_development_dependency 'rubocop', '~> 1.69.0'
s.add_development_dependency 'rubocop-packaging', '~> 0.5.2'
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
s.add_development_dependency 'rubocop-rspec', '~> 3.0.5'
Expand Down
8 changes: 4 additions & 4 deletions lib/cucumber/core/test/action/defined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def initialize(location = nil, &block)
@timer = Timer.new
end

def skip(*)
skipped
end

def execute(*args)
@timer.start
@block.call(*args)
Expand All @@ -37,6 +33,10 @@ def inspect
"#<#{self.class}: #{location}>"
end

def skip(*)
skipped
end

private

def passed
Expand Down
12 changes: 4 additions & 8 deletions lib/cucumber/core/test/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def self.ok?(type, strict: StrictConfiguration.new)

# Defines to_sym on a result class for the given result type
#
# Defines predicate methods on a result class with only the given one
# returning true
# Defines predicate methods on a result class with only the given one returning true
def self.query_methods(result_type)
Module.new do
define_method :to_sym do
Expand Down Expand Up @@ -166,8 +165,7 @@ def self.ok?(strict: false)
end
end

# Base class for exceptions that can be raised in a step definition causing
# the step to have that result.
# Base class for exceptions that can be raised in a step definition causing the step to have that result.
class Raisable < StandardError
attr_reader :message, :duration

Expand Down Expand Up @@ -295,7 +293,7 @@ def initialize(strict_types = [])

def strict?(type = nil)
if type.nil?
settings.each do |_key, value|
settings.each_value do |value|
return true if value == true
end
false
Expand All @@ -309,9 +307,7 @@ def strict?(type = nil)

def set_strict(setting, type = nil)
if type.nil?
STRICT_AFFECTED_TYPES.each do |t|
set_strict(setting, t)
end
STRICT_AFFECTED_TYPES.each { |type| set_strict(setting, type) }
else
settings[type] = setting
end
Expand Down
59 changes: 32 additions & 27 deletions spec/cucumber/core/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,31 @@ def envelope(*); end
end

context 'when compiling scenario outlines' do
it 'compiles a scenario outline to test cases' do
gherkin_documents = [
let(:gherkin_documents) do
[
gherkin do
feature do
background do
step 'passing'
end

scenario_outline do
step 'passing <arg>'
step 'passing'

examples 'examples 1' do
row 'arg'
row '1'
row '2'
end

examples 'examples 2' do
row 'arg'
row 'a'
end
end
end
end
]
end

it 'produces test cases' do
compile(gherkin_documents) do |visitor|
expect(visitor).to receive(:test_case).exactly(3).times.and_yield(visitor)
expect(visitor).to receive(:test_step).exactly(9).times
allow(visitor).to receive(:test_step)
allow(visitor).to receive(:done)
end
end

it 'produces test steps' do
compile(gherkin_documents) do |visitor|
allow(visitor).to receive(:done)
expect(visitor).to receive(:test_step).exactly(6).times
end
end

it 'finishes the compilation once' do
compile(gherkin_documents) do |visitor|
allow(visitor).to receive(:test_step)
expect(visitor).to receive(:done).once
end
end
Expand All @@ -174,7 +170,7 @@ def envelope(*); end

compile(gherkin_documents) do |visitor|
expect(visitor).to receive(:test_step) do |test_step|
expect(test_step.text).to eq 'passing 1 with 2'
expect(test_step.text).to eq 'passing 1'
end.once.ordered

expect(visitor).to receive(:test_step) do |test_step|
Expand All @@ -186,10 +182,19 @@ def envelope(*); end
end
end

context 'with empty scenarios' do
it 'creates test cases' do
context 'with no scenarios' do
it 'creates a single test case' do
compile([empty_gherkin_document]) do |visitor|
allow(visitor).to receive(:done)

expect(visitor).to receive(:test_case).once.ordered
end
end

it 'finishes the compilation once' do
compile([empty_gherkin_document]) do |visitor|
allow(visitor).to receive(:test_case)

expect(visitor).to receive(:done).once.ordered
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/core/event_bus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def on_test_event(event)
end
end

it 'will let you inspect the registry' do
it 'lets you inspect the registry' do
expect(event_bus.event_types[:test_event]).to eq(Events::TestEvent)
end

it "won't let you modify the registry" do
it 'does not let you modify the registry' do
expect { event_bus.event_types[:foo] = :bar }.to raise_error(RuntimeError)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/core/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
it 'generates new types of events' do
my_event_type = described_class.new
my_event = my_event_type.new
expect(my_event).to be_kind_of(described_class)
expect(my_event).to be_a(described_class)
end

it 'generates events with attributes' do
Expand Down
Loading

0 comments on commit fc0bcaa

Please sign in to comment.