Skip to content

Commit fbe6108

Browse files
authored
Refactor/rubocop af part1 (#1736)
* AF: RSpec/ContextMethod * AF: RSpec/EmptyLineAfterExample * AF: 4*EmptyLine RSpec cops * AF: RSpec/ExampleWording * AF: RSpec/HooksBeforeExamples * AF: RSpec/NotToNot * AF: RSpec/ScatteredLet * AF: Lint/AmbigiousBlockAssociation * Partial AF: Layout/HeredocIndentation * Re-gen of config and update of state: ~11% improvement
1 parent 809d002 commit fbe6108

32 files changed

+242
-322
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-09-02 09:39:29 UTC using RuboCop version 1.56.2.
3+
# on 2023-09-06 13:00:58 UTC using RuboCop version 1.56.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# TODO - [LH] -> Aug '23 - 370 files inspected, 1110 offenses detected, 482 offenses autocorrectable
10+
# TODO - [LH] -> Sep 6 '23 - 370 files inspected, 983 offenses detected, 368 offenses autocorrectable
1011

1112
# Offense count: 38
1213
# This cop supports safe autocorrection (--autocorrect).
@@ -21,23 +22,12 @@ Layout/HashAlignment:
2122
- 'lib/cucumber/formatter/ansicolor.rb'
2223
- 'lib/cucumber/gherkin/formatter/ansi_escapes.rb'
2324

24-
# Offense count: 13
25+
# Offense count: 2
2526
# This cop supports safe autocorrection (--autocorrect).
2627
Layout/HeredocIndentation:
2728
Exclude:
28-
- 'features/lib/support/feature_factory.rb'
2929
- 'lib/cucumber/cli/options.rb'
3030
- 'lib/cucumber/cli/profile_loader.rb'
31-
- 'spec/cucumber/cli/configuration_spec.rb'
32-
- 'spec/cucumber/cli/profile_loader_spec.rb'
33-
- 'spec/cucumber/formatter/pretty_spec.rb'
34-
35-
# Offense count: 1
36-
# This cop supports safe autocorrection (--autocorrect).
37-
# Configuration parameters: AllowedMethods, AllowedPatterns.
38-
Lint/AmbiguousBlockAssociation:
39-
Exclude:
40-
- 'spec/cucumber/glue/step_definition_spec.rb'
4131

4232
# Offense count: 1
4333
# This cop supports safe autocorrection (--autocorrect).
@@ -89,22 +79,7 @@ RSpec/Capybara/FeatureMethods:
8979
Exclude:
9080
- 'spec/cucumber/filters/activate_steps_spec.rb'
9181

92-
# Offense count: 13
93-
# This cop supports safe autocorrection (--autocorrect).
94-
RSpec/ContextMethod:
95-
Exclude:
96-
- 'spec/cucumber/deprecate_spec.rb'
97-
- 'spec/cucumber/formatter/backtrace_filter_spec.rb'
98-
- 'spec/cucumber/formatter/http_io_spec.rb'
99-
- 'spec/cucumber/formatter/query/hook_by_test_step_spec.rb'
100-
- 'spec/cucumber/formatter/query/pickle_by_test_spec.rb'
101-
- 'spec/cucumber/formatter/query/pickle_step_by_test_step_spec.rb'
102-
- 'spec/cucumber/formatter/query/step_definitions_by_test_step_spec.rb'
103-
- 'spec/cucumber/formatter/query/test_case_started_by_test_case_spec.rb'
104-
- 'spec/cucumber/formatter/url_reporter_spec.rb'
105-
- 'spec/cucumber/term/banner_spec.rb'
106-
107-
# Offense count: 98
82+
# Offense count: 85
10883
# Configuration parameters: Prefixes, AllowedPatterns.
10984
# Prefixes: when, with, without
11085
RSpec/ContextWording:
@@ -135,63 +110,11 @@ RSpec/EmptyExampleGroup:
135110
- 'spec/cucumber/filters/activate_steps_spec.rb'
136111
- 'spec/cucumber/running_test_case_spec.rb'
137112

138-
# Offense count: 6
139-
# This cop supports safe autocorrection (--autocorrect).
140-
# Configuration parameters: AllowConsecutiveOneLiners.
141-
RSpec/EmptyLineAfterExample:
142-
Exclude:
143-
- 'spec/cucumber/cli/options_spec.rb'
144-
- 'spec/cucumber/formatter/pretty_spec.rb'
145-
- 'spec/cucumber/multiline_argument/data_table_spec.rb'
146-
147-
# Offense count: 1
148-
# This cop supports safe autocorrection (--autocorrect).
149-
RSpec/EmptyLineAfterExampleGroup:
150-
Exclude:
151-
- 'spec/cucumber/formatter/rerun_spec.rb'
152-
153-
# Offense count: 10
154-
# This cop supports safe autocorrection (--autocorrect).
155-
RSpec/EmptyLineAfterFinalLet:
156-
Exclude:
157-
- 'spec/cucumber/cli/main_spec.rb'
158-
- 'spec/cucumber/configuration_spec.rb'
159-
- 'spec/cucumber/formatter/fail_fast_spec.rb'
160-
- 'spec/cucumber/formatter/junit_spec.rb'
161-
- 'spec/cucumber/formatter/pretty_spec.rb'
162-
- 'spec/cucumber/hooks_spec.rb'
163-
- 'spec/cucumber/rake/task_spec.rb'
164-
165-
# Offense count: 3
166-
# This cop supports safe autocorrection (--autocorrect).
167-
# Configuration parameters: AllowConsecutiveOneLiners.
168-
RSpec/EmptyLineAfterHook:
169-
Exclude:
170-
- 'spec/cucumber/formatter/junit_spec.rb'
171-
172-
# Offense count: 2
173-
# This cop supports safe autocorrection (--autocorrect).
174-
RSpec/EmptyLineAfterSubject:
175-
Exclude:
176-
- 'spec/cucumber/filters/tag_limits/verifier_spec.rb'
177-
- 'spec/cucumber/runtime/meta_message_builder_spec.rb'
178-
179113
# Offense count: 150
180114
# Configuration parameters: CountAsOne.
181115
RSpec/ExampleLength:
182116
Max: 58
183117

184-
# Offense count: 51
185-
# This cop supports safe autocorrection (--autocorrect).
186-
# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples.
187-
# DisallowedExamples: works
188-
RSpec/ExampleWording:
189-
Exclude:
190-
- 'spec/cucumber/cli/configuration_spec.rb'
191-
- 'spec/cucumber/multiline_argument/data_table_spec.rb'
192-
- 'spec/cucumber/project_initializer_spec.rb'
193-
- 'spec/cucumber/rake/task_spec.rb'
194-
195118
# Offense count: 2
196119
# This cop supports safe autocorrection (--autocorrect).
197120
RSpec/ExpectActual:
@@ -218,13 +141,6 @@ RSpec/ExpectOutput:
218141
RSpec/HookArgument:
219142
Enabled: false
220143

221-
# Offense count: 4
222-
# This cop supports safe autocorrection (--autocorrect).
223-
RSpec/HooksBeforeExamples:
224-
Exclude:
225-
- 'spec/cucumber/cli/configuration_spec.rb'
226-
- 'spec/cucumber/formatter/interceptor_spec.rb'
227-
228144
# Offense count: 15
229145
# Configuration parameters: AssignmentOnly.
230146
RSpec/InstanceVariable:
@@ -291,17 +207,6 @@ RSpec/NamedSubject:
291207
RSpec/NestedGroups:
292208
Max: 6
293209

294-
# Offense count: 8
295-
# This cop supports safe autocorrection (--autocorrect).
296-
# Configuration parameters: EnforcedStyle.
297-
# SupportedStyles: not_to, to_not
298-
RSpec/NotToNot:
299-
Exclude:
300-
- 'spec/cucumber/filters/gated_receiver_spec.rb'
301-
- 'spec/cucumber/filters/tag_limits/verifier_spec.rb'
302-
- 'spec/cucumber/glue/step_definition_spec.rb'
303-
- 'spec/cucumber/multiline_argument/data_table_spec.rb'
304-
305210
# Offense count: 4
306211
# This cop supports unsafe autocorrection (--autocorrect-all).
307212
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
@@ -346,13 +251,6 @@ RSpec/ReturnFromStub:
346251
- 'spec/cucumber/formatter/junit_spec.rb'
347252
- 'spec/cucumber/glue/registry_and_more_spec.rb'
348253

349-
# Offense count: 4
350-
# This cop supports safe autocorrection (--autocorrect).
351-
RSpec/ScatteredLet:
352-
Exclude:
353-
- 'spec/cucumber/glue/snippet_spec.rb'
354-
- 'spec/cucumber/runtime/support_code_spec.rb'
355-
356254
# Offense count: 9
357255
RSpec/StubbedMock:
358256
Exclude:

features/lib/support/feature_factory.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
module FeatureFactory
44
def create_feature(name = generate_feature_name)
5-
gherkin = <<-GHERKIN
6-
Feature: #{name}
7-
#{yield}
5+
gherkin = <<~GHERKIN
6+
Feature: #{name}
7+
#{yield}
88
GHERKIN
99
write_file filename(name), gherkin
1010
end
1111

1212
def create_feature_ja(name = generate_feature_name)
13-
gherkin = <<-GHERKIN
14-
# language: ja
15-
機能: #{name}
16-
#{yield}
13+
gherkin = <<~GHERKIN
14+
# language: ja
15+
機能: #{name}
16+
#{yield}
1717
GHERKIN
1818
write_file filename(name), gherkin
1919
end

spec/cucumber/cli/configuration_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def reset_config
9696
end
9797

9898
it 'parses ERB in cucumber.yml that makes uses nested ERB sessions' do
99-
given_cucumber_yml_defined_as(<<ERB_YML)
100-
<%= ERB.new({'standard' => '--require some_file'}.to_yaml).result %>
101-
<%= ERB.new({'enhanced' => '--require other_file'}.to_yaml).result %>
102-
ERB_YML
99+
given_cucumber_yml_defined_as(<<~ERB_YML)
100+
<%= ERB.new({'standard' => '--require some_file'}.to_yaml).result %>
101+
<%= ERB.new({'enhanced' => '--require other_file'}.to_yaml).result %>
102+
ERB_YML
103103

104104
config.parse!(%w[-p standard])
105105

@@ -109,12 +109,12 @@ def reset_config
109109
it 'provides a helpful error message when a specified profile does not exists in cucumber.yml' do
110110
given_cucumber_yml_defined_as('default' => '--require from/yml', 'json_report' => '--format json')
111111

112-
expected_message = <<-END_OF_MESSAGE
113-
Could not find profile: 'i_do_not_exist'
112+
expected_message = <<~END_OF_MESSAGE
113+
Could not find profile: 'i_do_not_exist'
114114
115-
Defined profiles in cucumber.yml:
116-
* default
117-
* json_report
115+
Defined profiles in cucumber.yml:
116+
* default
117+
* json_report
118118
END_OF_MESSAGE
119119

120120
expect { config.parse!(%w[--profile i_do_not_exist]) }.to raise_error(ProfileNotFound, expected_message)
@@ -357,6 +357,10 @@ def reset_config
357357
Cucumber.use_full_backtrace = false
358358
end
359359

360+
after do
361+
Cucumber.use_full_backtrace = false
362+
end
363+
360364
it 'shows full backtrace when --backtrace is present' do
361365
Main.new(['--backtrace'])
362366
begin
@@ -365,10 +369,6 @@ def reset_config
365369
expect(e.backtrace[0]).not_to eq "#{__FILE__}:#{__LINE__ - 2}"
366370
end
367371
end
368-
369-
after do
370-
Cucumber.use_full_backtrace = false
371-
end
372372
end
373373

374374
it 'accepts multiple --name options' do
@@ -385,7 +385,7 @@ def reset_config
385385
expect(config.options[:name_regexps]).to include(/User signs up/)
386386
end
387387

388-
it 'should allow specifying environment variables on the command line' do
388+
it 'allows specifying environment variables on the command line' do
389389
config.parse!(['foo=bar'])
390390

391391
expect(ENV['foo']).to eq 'bar'

spec/cucumber/cli/main_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Cli
1515
let(:stdout) { StringIO.new }
1616
let(:stderr) { StringIO.new }
1717
let(:kernel) { double(:kernel) }
18+
1819
subject { Main.new(args, stdout, stderr, kernel) }
1920

2021
describe '#execute!' do

spec/cucumber/cli/options_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def with_env(name, value)
136136
it "defaults the formatter to 'pretty' when not specified earlier" do
137137
after_parsing('-o file.txt') { expect(options[:formats]).to eq [['pretty', {}, 'file.txt']] }
138138
end
139+
139140
it 'sets the output for the formatter defined immediately before it' do
140141
after_parsing('-f profile --out file.txt -f pretty -o file2.txt') do
141142
expect(options[:formats]).to eq [['profile', {}, 'file.txt'], ['pretty', {}, 'file2.txt']]

spec/cucumber/cli/profile_loader_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def loader
3535
end
3636

3737
it 'treats percent sign as ERB code block after YAML directive' do
38-
yml = <<-HERE
39-
---
40-
% x = '--format "pretty" features/sync_imap_mailbox.feature:16:22'
41-
default: <%= x %>
38+
yml = <<~HERE
39+
---
40+
% x = '--format "pretty" features/sync_imap_mailbox.feature:16:22'
41+
default: <%= x %>
4242
HERE
4343
given_cucumber_yml_defined_as yml
4444
expect(loader.args_from('default')).to eq ['--format', 'pretty', 'features/sync_imap_mailbox.feature:16:22']

spec/cucumber/configuration_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Cucumber
1515

1616
describe 'with custom user options' do
1717
let(:user_options) { { autoload_code_paths: ['foo/bar/baz'] } }
18+
1819
subject { Configuration.new(user_options) }
1920

2021
it 'allows you to override the defaults' do

spec/cucumber/deprecate_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Cucumber::Deprecate
3030
describe CliOption do
3131
let(:error_stream) { double }
3232

33-
context '.deprecate' do
33+
describe '.deprecate' do
3434
it 'outputs a warning to the provided channel' do
3535
allow(error_stream).to receive(:puts)
3636
described_class.deprecate(error_stream, '--some-option', 'Please use --another-option instead', '1.2.3')

spec/cucumber/filters/gated_receiver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
describe '#test_case' do
1212
it 'does not immediately describe the test case to the receiver' do
1313
test_cases.each do |test_case|
14-
expect(test_case).to_not receive(:describe_to).with(receiver)
14+
expect(test_case).not_to receive(:describe_to).with(receiver)
1515
gated_receiver.test_case(test_case)
1616
end
1717
end

spec/cucumber/filters/tag_limits/verifier_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
describe Cucumber::Filters::TagLimits::Verifier do
66
describe '#verify!' do
77
subject(:verifier) { Cucumber::Filters::TagLimits::Verifier.new(tag_limits) }
8+
89
let(:test_case_index) { double(:test_case_index) }
910

1011
context 'the tag counts exceed the tag limits' do
@@ -48,7 +49,7 @@
4849
end
4950

5051
it 'does not raise an error' do
51-
expect { verifier.verify!(test_case_index) }.to_not raise_error
52+
expect { verifier.verify!(test_case_index) }.not_to raise_error
5253
end
5354
end
5455
end

0 commit comments

Comments
 (0)