Skip to content

Commit

Permalink
Fix cli_autocorrect_spec failures now that rubocop#9187 and rubocop#9190
Browse files Browse the repository at this point in the history
 are merged.
  • Loading branch information
dvandersluis committed Dec 8, 2020
1 parent 24765a0 commit 08f612c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions spec/rubocop/cli/cli_autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ def primes limit
RUBY
end

it 'does not say [Corrected] if correction was avoided' do
it 'does not say [Corrected] if correction is not possible' do
src = <<~RUBY
func a do b end
Signal.trap('TERM') { system(cmd); exit }
Expand Down Expand Up @@ -1406,14 +1406,44 @@ def self.some_method(foo, bar: 1)
expect(IO.read('example.rb')).to eq(corrected)
expect($stdout.string).to eq(<<~RESULT)
== example.rb ==
C: 1: 8: [Correctable] Style/BlockDelimiters: Prefer {...} over do...end for single-line blocks.
C: 2: 34: [Correctable] Style/Semicolon: Do not use semicolons to terminate expressions.
W: 3: 27: [Correctable] Lint/UnusedMethodArgument: Unused method argument - bar.
C: 1: 8: Style/BlockDelimiters: Prefer {...} over do...end for single-line blocks.
C: 2: 34: Style/Semicolon: Do not use semicolons to terminate expressions.
W: 3: 27: Lint/UnusedMethodArgument: Unused method argument - bar.
1 file inspected, 3 offenses detected
RESULT
end

it 'says [Correctable] if correction is unsafe' do
src = <<~RUBY
var = :false
%w('foo', "bar")
RUBY
corrected = <<~RUBY
var = :false
%w('foo', "bar")
RUBY
create_file('.rubocop.yml', <<~YAML)
AllCops:
TargetRubyVersion: 2.4
YAML
create_file('example.rb', src)
exit_status = cli.run(
%w[-a -f simple
--only Lint/BooleanSymbol,Lint/PercentStringArray]
)
expect(exit_status).to eq(1)
expect($stderr.string).to eq('')
expect(IO.read('example.rb')).to eq(corrected)
expect($stdout.string).to eq(<<~RESULT)
== example.rb ==
W: 1: 7: [Correctable] Lint/BooleanSymbol: Symbol with a boolean name - you probably meant to use false.
W: 2: 1: [Correctable] Lint/PercentStringArray: Within %w/%W, quotes and ',' are unnecessary and may be unwanted in the resulting strings.
1 file inspected, 2 offenses detected, 2 more offenses can be corrected with `rubocop -A`
RESULT
end

it 'does not hang SpaceAfterPunctuation and SpaceInsideParens' do
create_file('example.rb', 'some_method(a, )')
Timeout.timeout(10) do
Expand Down

0 comments on commit 08f612c

Please sign in to comment.