Skip to content

Commit

Permalink
Refactor/v13 manual cop fixes (#279)
Browse files Browse the repository at this point in the history
* Attempted fix for AccessModifierDeclaration (Partially broken cop)

* Attempt to start unpicking the unverified doubles in compiler_spec

* Partial fix for RSpec/NestedGroups

* Attempt to fix up RSpec/MultipleMemoizedHelpers

* Fix workflow for ruby 2.6 failing to update

* Remove rubocop from being re-ran in default rake

* Fix up verifying doubles issue by adding in random legit value for text

* Don't update rubygems after 2.7 as it's new enough

* Add changelog for other fix I did for a 13.0.1

* Add changelog for test fixes

* Re-generate TODO file - Fix RSpec/FilePath single offense

* Tidy up timer spec

* Tidy up indentation level logic

* Simplify dummy code in filters

* Fix up remaining RSpec context wording offenses

* Fix issue where rubocop was using 1.60 by mistake

* Fix up a couple of very long-wordy specs

* Re-add in missing rubygems from poor rebase
  • Loading branch information
luke-hill committed Jan 31, 2024
1 parent 62b5057 commit 0259540
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 276 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2']
ruby: ['2.7', '3.0', '3.1', '3.2']
bundler: ['2.4.19']
rubygems: ['latest']
include:
- os: ubuntu-latest
ruby: '2.5'
bundler: '2.3.17'
rubygems: '3.0.8'
- os: ubuntu-latest
ruby: '2.6'
bundler: '2.4.19'
rubygems: '3.2.3'
- os: ubuntu-latest
ruby: jruby
Expand Down
59 changes: 13 additions & 46 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-11-29 11:28:59 UTC using RuboCop version 1.28.2.
# on 2024-01-31 16:02:10 UTC using RuboCop version 1.28.2.
# 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
# versions of RuboCop, may require this file to be generated again.

# TODO: [LH] Initial state -> 53 files inspected, 2221 offenses detected, 1663 offenses auto-correctable
# TODO: [LH] Part 1 iteration -> 53 files inspected, 1990 offenses detected, 1442 offenses auto-correctable
# TODO: [LH] Part 2 iteration -> 53 files inspected, 506 offenses detected, 163 offenses auto-correctable
# TODO: [LH] v12 -> 53 files inspected, 450 offenses detected, 150 offenses auto-correctable
# TODO: [LH] v12 -> 53 files inspected, 453 offenses detected, 148 offenses auto-correctable
# TODO: [LH] v13 -> 53 files inspected, 450 offenses detected, 173 offenses auto-correctable

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Expand All @@ -28,12 +27,11 @@ Layout/DotPosition:
Exclude:
- 'lib/cucumber/core/event.rb'

# Offense count: 12
# Offense count: 11
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/cucumber/core/event_bus.rb'
- 'lib/cucumber/core/gherkin/writer/helpers.rb'
- 'lib/cucumber/core/test/action.rb'
- 'lib/cucumber/core/test/case.rb'
- 'lib/cucumber/core/test/doc_string.rb'
Expand Down Expand Up @@ -62,21 +60,12 @@ Layout/HeredocIndentation:
Exclude:
- 'spec/cucumber/core/test/doc_string_spec.rb'

# Offense count: 2
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
Layout/LeadingCommentSpace:
Exclude:
- 'lib/cucumber/core/events.rb'
- 'spec/cucumber/core/test/timer_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Exclude:
- 'spec/cucumber/core/test/timer_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Expand Down Expand Up @@ -122,10 +111,10 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 409

# Offense count: 5
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 30
Max: 28

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Expand Down Expand Up @@ -161,16 +150,9 @@ RSpec/Capybara/FeatureMethods:
- 'spec/cucumber/core/gherkin/parser_spec.rb'
- 'spec/cucumber/core/gherkin/writer_spec.rb'
- 'spec/cucumber/core/test/case_spec.rb'
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'
- 'spec/cucumber/core/test/locations_filter_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 3
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: SkipBlocks, EnforcedStyle.
Expand Down Expand Up @@ -198,13 +180,6 @@ RSpec/ExpectActual:
- 'spec/routing/**/*'
- 'spec/cucumber/core/test/doc_string_spec.rb'

# Offense count: 1
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Exclude:
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
Expand All @@ -227,7 +202,7 @@ RSpec/MissingExampleGroupArgument:
- 'spec/cucumber/core/gherkin/parser_spec.rb'
- 'spec/cucumber/core/gherkin/writer_spec.rb'
- 'spec/cucumber/core/test/case_spec.rb'
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'
- 'spec/cucumber/core/test/locations_filter_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 1
Expand All @@ -239,12 +214,12 @@ RSpec/MultipleDescribes:
RSpec/MultipleExpectations:
Max: 6

# Offense count: 57
# Offense count: 55
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 14

# Offense count: 11
# Offense count: 5
RSpec/NestedGroups:
Max: 4

Expand All @@ -259,13 +234,7 @@ RSpec/RepeatedExample:
# This cop supports safe auto-correction (--auto-correct).
RSpec/ScatteredLet:
Exclude:
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/cucumber/core/compiler_spec.rb'
- 'spec/cucumber/core/test/locations_filter_spec.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
Expand All @@ -274,7 +243,7 @@ Style/AccessModifierDeclarations:
Exclude:
- 'lib/cucumber/core/filter.rb'

# Offense count: 3
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
Expand All @@ -283,7 +252,6 @@ Style/AccessModifierDeclarations:
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'lib/cucumber/core/filter.rb'
- 'lib/cucumber/core/test/filters/locations_filter.rb'

# Offense count: 1
Expand All @@ -301,11 +269,10 @@ Style/EmptyMethod:
Exclude:
- 'lib/cucumber/core/gherkin/writer.rb'

# Offense count: 3
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Style/Encoding:
Exclude:
- 'Rakefile'
- 'lib/cucumber/core/events.rb'
- 'lib/cucumber/core/test/result.rb'

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.

## [Unreleased]
### Fixed
- The `Passed` `Result` class was missing the strict keyword argument handling

### Changed
- Fixed up a few styling / layout cops in the tests

## [13.0.0] - 2023-12-05
### Changed
Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rubygems'
Expand All @@ -20,4 +19,4 @@ namespace :spec do
end
end

task default: ['spec', 'spec:slow', 'rubocop']
task default: ['spec', 'spec:slow']
4 changes: 1 addition & 3 deletions lib/cucumber/core/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def done
end

define_method(:with_receiver) do |new_receiver|
args = attributes.map { |name|
instance_variable_get("@#{name}".to_sym)
}
args = attributes.map { |name| instance_variable_get("@#{name}".to_sym) }
args[-1] = new_receiver
self.class.new(*args)
end
Expand Down
13 changes: 7 additions & 6 deletions lib/cucumber/core/gherkin/writer/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def elements(*names)
private

def element(name)
define_method name do |*args, &source|
define_method(name) do |*args, &source|
factory_name = String(name).split('_').map(&:capitalize).join
factory = Writer.const_get(factory_name)
factory.new(slurp_comments, *args).tap do |builder|
Expand All @@ -108,17 +108,18 @@ def element(name)
module Indentation
def self.level(number)
Module.new do
define_method :indent do |string, amount = nil|
amount ||= number
define_method(:indent) do |string, amount = nil|
return string if string.nil? || string.empty?
(' ' * amount) + string

amount ||= number
"#{' ' * amount}#{string}"
end

define_method :indent_level do
define_method(:indent_level) do
number
end

define_method :prepare_statements do |*statements|
define_method(:prepare_statements) do |*statements|
statements.flatten.compact.map { |s| indent(s) }
end
end
Expand Down
22 changes: 11 additions & 11 deletions lib/cucumber/core/test/filters/activate_steps_for_self_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ class ActivateStepsForSelfTest < Core::Filter.new
Failure = Class.new(StandardError)

def test_case(test_case)
test_steps = test_case.test_steps.map do |step|
test_case.with_steps(test_steps(test_case)).describe_to(receiver)
end

private

def test_steps(test_case)
test_case.test_steps.map do |step|
case step.text
when /fail/
step.with_action { raise Failure }
when /pending/
step.with_action { raise Test::Result::Pending }
when /pass/
step.with_action { :no_op }
else
step
when /fail/ then step.with_action { raise Failure }
when /pending/ then step.with_action { raise Test::Result::Pending }
when /pass/ then step.with_action { :no_op }
else; step
end
end

test_case.with_steps(test_steps).describe_to(receiver)
end
end
end
Expand Down
23 changes: 9 additions & 14 deletions spec/cucumber/core/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
include Cucumber::Core::Gherkin::Writer
include Cucumber::Core

def self.stubs(*names)
names.each do |name|
let(name) { double(name.to_s) }
end
end

let(:empty_gherkin_document) do
gherkin do
feature do
Expand Down Expand Up @@ -63,21 +57,22 @@ def self.stubs(*names)
end

context 'when the event_bus is provided' do
let(:event_bus) { double }

before do
allow(event_bus).to receive(:envelope)
allow(event_bus).to receive(:gherkin_source_parsed).and_return(nil)
allow(event_bus).to receive(:test_case_created).and_return(nil)
allow(event_bus).to receive(:test_step_created).and_return(nil)
let(:event_bus_class) do
Class.new(Cucumber::Core::EventBus) do
def gherkin_source_parsed(*); end
def test_case_created(*); end
def test_step_created(*); end
def envelope(*); end
end
end

let(:event_bus) { event_bus_class.new }

it 'emits a TestCaseCreated event with the created Test::Case and Pickle' do
compile([single_step_gherkin_document], event_bus) do |visitor|
allow(visitor).to receive(:test_case)
allow(visitor).to receive(:test_step)
allow(visitor).to receive(:done)
allow(event_bus).to receive(:envelope)

expect(event_bus).to receive(:test_case_created).once
end
Expand Down
10 changes: 5 additions & 5 deletions spec/cucumber/core/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
it 'creates a filter class that can pass-through by default' do
my_filter_class = described_class.new
my_filter = my_filter_class.new
expect(receiver).to receive(:test_case) { |test_case|
expect(test_case.test_steps.length).to eq 1
expect(test_case.test_steps.first.text).to eq 'a step'
}.twice
compile [doc], receiver, [my_filter]
expect(receiver).to receive(:test_case) do |test_case|
expect(test_case.test_steps.length).to eq(1)
expect(test_case.test_steps.first.text).to eq('a step')
end.twice
compile([doc], receiver, [my_filter])
end

context 'when customizing using a subclass' do
Expand Down
9 changes: 5 additions & 4 deletions spec/cucumber/core/gherkin/writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,8 @@
| 20 | 5 | 15 |
FEATURE
end

it 'can generate a complex feature' do
source = gherkin do
let(:gherkin_document) do
gherkin do
comment 'wow'
feature 'Fully featured', language: 'en', tags: '@always' do
comment 'cool'
Expand Down Expand Up @@ -333,8 +332,10 @@
end
end
end
end

expect(source.to_s).to eq(expected)
it 'can generate a complex feature' do
expect(gherkin_document.to_s).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_cases
result
end

context 'for a scenario' do
context 'with a scenario' do
let(:doc) do
Cucumber::Core::Gherkin::Document.new(file, <<-FEATURE)
Feature:
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_case_named(name)
end
end

context 'for a scenario outline' do
context 'with a scenario outline' do
let(:doc) do
Cucumber::Core::Gherkin::Document.new(file, <<-FEATURE)
Feature:
Expand Down Expand Up @@ -396,7 +396,7 @@ def test_case_named(name)
end
end

context 'under load', slow: true do
context 'when under extreme load', slow: true do
num_features = 50
num_scenarios_per_feature = 50

Expand Down
Loading

0 comments on commit 0259540

Please sign in to comment.