Skip to content
Permalink
Browse files

Address some pending RSpec style fixes (#4989)

* address RSpec/ScatteredSetup
* address RSpec/ReturnFromStub
* address RSpec/RepeatedExample
* address RSpec/DescribeClass
* address RSpec/BeforeAfterAll
* address RSpec/ExpectInHook
* address RSpec/IteratedExpectation
  • Loading branch information...
walf443 authored and bbatsov committed Nov 4, 2017
1 parent 09dcfc1 commit c8729c8ecd6c312d5ca8bb6b660d5380038b1ed6
@@ -32,30 +32,11 @@ RSpec/AnyInstance:
- 'spec/rubocop/cop/lint/duplicate_methods_spec.rb'
- 'spec/rubocop/target_finder_spec.rb'

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- 'spec/spec_helper.rb'
- 'spec/rails_helper.rb'
- 'spec/support/**/*.rb'
- 'spec/rubocop/ast/node_spec.rb'

# Offense count: 2
RSpec/DescribeClass:
Exclude:
- 'spec/isolated_environment_spec.rb'
- 'spec/project_spec.rb'

# Offense count: 2538
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false

# Offense count: 4
RSpec/ExpectInHook:
Exclude:
- 'spec/rubocop/cli/cli_options_spec.rb'

# Offense count: 39
RSpec/ExpectOutput:
Exclude:
@@ -73,13 +54,6 @@ RSpec/ExpectOutput:
- 'spec/rubocop/target_finder_spec.rb'
- 'spec/support/cli_spec_behavior.rb'

# Offense count: 6
RSpec/IteratedExpectation:
Exclude:
- 'spec/project_spec.rb'
- 'spec/rubocop/cop/force_spec.rb'
- 'spec/rubocop/formatter/formatter_set_spec.rb'

# Offense count: 36
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: have_received, receive
@@ -107,24 +81,6 @@ RSpec/MultipleExpectations:
RSpec/NestedGroups:
Enabled: false

# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/rubocop/cop/style/trailing_underscore_variable_spec.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: and_return, block
RSpec/ReturnFromStub:
Exclude:
- 'spec/rubocop/config_store_spec.rb'

# Offense count: 4
RSpec/ScatteredSetup:
Exclude:
- 'spec/rubocop/cli/cli_autocorrect_spec.rb'
- 'spec/rubocop/formatter/disabled_config_formatter_spec.rb'

# Offense count: 21
RSpec/SubjectStub:
Exclude:
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'isolated environment', :isolated_environment do
describe 'isolated environment', :isolated_environment, type: :feature do
include_context 'cli spec behavior'

let(:cli) { RuboCop::CLI.new }
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'RuboCop Project' do
describe 'RuboCop Project', type: :feature do
let(:cop_names) do
RuboCop::Cop::Cop
.registry
@@ -101,9 +101,7 @@
let(:lines) { changelog.each_line }

it 'has a whitespace between the * and the body' do
entries.each do |entry|
expect(entry).to match(/^\* \S/)
end
expect(entries).to all(match(/^\* \S/))
end

context 'after version 0.14.0' do
@@ -114,9 +112,7 @@
end

it 'has a link to the contributors at the end' do
entries.each do |entry|
expect(entry).to match(/\(\[@\S+\]\[\](?:, \[@\S+\]\[\])*\)$/)
end
expect(entries).to all(match(/\(\[@\S+\]\[\](?:, \[@\S+\]\[\])*\)$/))
end
end

@@ -146,9 +142,7 @@
entry.match(/^\*\s*\[/)
end

entries_including_issue_link.each do |entry|
expect(entry).to include('): ')
end
expect(entries_including_issue_link).to all(include('): '))
end
end

@@ -169,9 +163,7 @@
end

it 'ends with a punctuation' do
bodies.each do |body|
expect(body).to match(/[\.\!]$/)
end
expect(bodies).to all(match(/[\.\!]$/))
end
end
end
@@ -36,7 +36,7 @@
describe '#value_used?' do
let(:node) { RuboCop::ProcessedSource.new(src, ruby_version).ast }

before(:all) do
before do
module RuboCop
module AST
class Node
@@ -109,9 +109,6 @@

before do
create_file('example.rb', source)
end

before do
create_file('.rubocop.yml', YAML.dump(config))
end

@@ -1005,68 +1005,71 @@ def f
RUBY
end

after do
def expect_offense_detected(num)
expect($stderr.string).to eq('')
expect($stdout.string)
.to include('1 file inspected, 1 offense detected')
.to include("1 file inspected, #{num} offense detected")
end

it 'fails when option is less than the severity level' do
expect(cli.run(['--fail-level', 'refactor', target_file])).to eq(1)
expect(cli.run(['--fail-level', 'autocorrect', target_file])).to eq(1)
expect_offense_detected(1)
end

it 'fails when option is equal to the severity level' do
expect(cli.run(['--fail-level', 'convention', target_file])).to eq(1)
expect_offense_detected(1)
end

it 'succeeds when option is greater than the severity level' do
expect(cli.run(['--fail-level', 'warning', target_file])).to eq(0)
expect_offense_detected(1)
end

context 'with --auto-correct' do
after do
def expect_auto_corrected(num)
expect_offense_detected(num)
expect($stdout.string.lines.to_a.last)
.to eq('1 file inspected, 1 offense detected, 1 offense corrected' \
"\n")
.to eq("1 file inspected, #{num} offense detected, " \
"#{num} offense corrected\n")
end

it 'fails when option is autocorrect and all offenses are ' \
'autocorrected' do
expect(cli.run(['--auto-correct', '--format', 'simple',
'--fail-level', 'autocorrect',
target_file])).to eq(1)
expect_auto_corrected(1)
end

it 'fails when option is A and all offenses are autocorrected' do
expect(cli.run(['--auto-correct', '--format', 'simple',
'--fail-level', 'A',
target_file])).to eq(1)
expect_auto_corrected(1)
end

it 'succeeds when option is not given and all offenses are ' \
'autocorrected' do
expect(cli.run(['--auto-correct', '--format', 'simple',
target_file])).to eq(0)
expect_auto_corrected(1)
end

it 'succeeds when option is refactor and all offenses are ' \
'autocorrected' do
expect(cli.run(['--auto-correct', '--format', 'simple',
'--fail-level', 'refactor',
target_file])).to eq(0)
expect_auto_corrected(1)
end
end
end

describe 'with --auto-correct and disabled offense' do
let(:target_file) { 'example.rb' }

after do
expect($stdout.string.lines.to_a.last)
.to eq('1 file inspected, no offenses detected' \
"\n")
end
it 'succeeds when there is only a disabled offense' do
create_file(target_file, <<-RUBY.strip_indent)
def f
@@ -1077,6 +1080,10 @@ def f
expect(cli.run(['--auto-correct', '--format', 'simple',
'--fail-level', 'autocorrect',
target_file])).to eq(0)

expect($stdout.string.lines.to_a.last)
.to eq('1 file inspected, no offenses detected' \
"\n")
end
end

@@ -19,7 +19,7 @@
allow(RuboCop::ConfigLoader)
.to receive(:merge_with_default) { |config| "merged #{config.to_h}" }
allow(RuboCop::ConfigLoader)
.to receive(:default_configuration) { 'default config' }
.to receive(:default_configuration).and_return('default config')
end

describe '.for' do
@@ -13,9 +13,7 @@

describe '#run_hook' do
it 'invokes a hook in all cops' do
cops.each do |cop|
expect(cop).to receive(:some_hook).with(:foo, :bar)
end
expect(cops).to all(receive(:some_hook).with(:foo, :bar))

force.run_hook(:some_hook, :foo, :bar)
end
@@ -224,11 +224,6 @@

include_examples 'common functionality'

it 'does not register an offense for an underscore variable preceded ' \
'by a named splat underscore variable' do
expect_no_offenses('a, *_b, _ = foo()')
end

it 'does not register an offense for named variables ' \
'that start with an underscore' do
expect_no_offenses('a, b, _c = foo()')
@@ -239,8 +234,8 @@
expect_no_offenses('a, *_b = foo()')
end

it 'does not register an offense for an underscore preceded by ' \
'a named splat underscore' do
it 'does not register an offense for an underscore variable preceded ' \
'by a named splat underscore variable' do
expect_no_offenses('a, *_b, _ = foo()')
end

@@ -91,9 +91,7 @@ def io.path
Exclude:
- "**/*.blah"
YAML
end

before do
formatter.started(['test_a.rb', 'test_b.rb'])
formatter.file_started('test_a.rb', {})
formatter.file_finished('test_a.rb', offenses)
@@ -20,9 +20,9 @@ module Formatter
let(:files) { ['/path/to/file1', '/path/to/file2'] }

it 'invokes same method of all containing formatters' do
formatter_set.each do |formatter|
expect(formatter).to receive(:started).with(files)
end
# rubocop:disable RSpec/SubjectStub SEE ALSO: https://github.com/backus/rubocop-rspec/issues/488
expect(formatter_set).to all(receive(:started).with(files))
# rubocop:enable RSpec/SubjectStub
formatter_set.started(files)
end
end

0 comments on commit c8729c8

Please sign in to comment.
You can’t perform that action at this time.