rubocop: fix offences of the Lint/InterpolationCheck cop

This commit is contained in:
Kyrylo Silin 2019-03-03 19:52:24 +02:00
parent f92e221bbc
commit 08fa0dcb5d
7 changed files with 29 additions and 17 deletions

View File

@ -22,16 +22,6 @@ Lint/HandleExceptions:
- 'lib/pry/pager.rb'
- 'lib/pry/terminal.rb'
# Offense count: 16
Lint/InterpolationCheck:
Exclude:
- 'spec/command_integration_spec.rb'
- 'spec/command_set_spec.rb'
- 'spec/command_spec.rb'
- 'spec/commands/amend_line_spec.rb'
- 'spec/commands/edit_spec.rb'
- 'spec/pry_spec.rb'
# Offense count: 1
Lint/Loop:
Exclude:

View File

@ -236,7 +236,9 @@ describe "commands" do
end
end
# rubocop:disable Lint/InterpolationCheck
expect(pry_tester(commands: set).eval('hello #{Pad.bong}')).to match(/bong/)
# rubocop:enable Lint/InterpolationCheck
end
# bug fix for https://github.com/pry/pry/issues/170
@ -245,7 +247,10 @@ describe "commands" do
"is a command"
) do
redirect_pry_io(
InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), @str_output
# rubocop:disable Lint/InterpolationCheck
InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'),
# rubocop:enable Lint/InterpolationCheck
@str_output
) do
pry
end
@ -260,16 +265,19 @@ describe "commands" do
end
end
# rubocop:disable Lint/InterpolationCheck
expect(pry_tester(commands: set).eval('hello #{Pad.bong}'))
.to match(/Pad\.bong/)
# rubocop:enable Lint/InterpolationCheck
end
it 'should NOT try to interpolate pure ruby code (no commands) ' do
# rubocop:disable Lint/InterpolationCheck
# These should raise RuntimeError instead of NameError
expect { pry_eval 'raise \'#{aggy}\'' }.to raise_error RuntimeError
expect { pry_eval 'raise #{aggy}' }.to raise_error RuntimeError
expect { pry_eval 'raise #{aggy}' }.to raise_error RuntimeError
expect(pry_eval('format \'#{my_var}\'')).to eq "\#{my_var}"
# rubocop:enable Lint/InterpolationCheck
end
it 'should create a command with a space in its name zzz' do
@ -326,7 +334,7 @@ describe "commands" do
end
bong = "bong"
expect(pry_tester(binding, commands: set).eval('hello #{bong}'))
expect(pry_tester(binding, commands: set).eval("hello #{bong}"))
.to match(/hello #{bong}/)
end
@ -342,7 +350,7 @@ describe "commands" do
bang = 'bang'
expect(pry_tester(binding, commands: set)
.eval('hellojohn #{bing} #{bong} #{bang}'))
.eval("hellojohn #{bing} #{bong} #{bang}"))
.to match(/hello john #{bing} #{bong} #{bang}/)
end

View File

@ -575,7 +575,9 @@ describe Pry::CommandSet do
it 'should not cause argument interpolation' do
@set.command('hello')
# rubocop:disable Lint/InterpolationCheck
expect { @set.valid_command?('hello #{raise "futz"}') }.to_not raise_error
# rubocop:enable Lint/InterpolationCheck
end
end

View File

@ -315,12 +315,14 @@ describe "Pry::Command" do
end
describe 'tokenize' do
it 'should interpolate string with #{} in them' do
it "should interpolate string with \#{} in them" do
expect do |probe|
cmd = @set.command('random-dent', &probe)
_foo = 5
cmd.new(target: binding).process_line 'random-dent #{1 + 2} #{3 + _foo}'
# rubocop:disable Lint/InterpolationCheck
cmd.new(target: binding).process_line('random-dent #{1 + 2} #{3 + _foo}')
# rubocop:enable Lint/InterpolationCheck
end.to yield_with_args('3', '8')
end
@ -333,11 +335,13 @@ describe "Pry::Command" do
end
it 'should not interpolate commands with :interpolate => false' do
# rubocop:disable Lint/InterpolationCheck
expect do |probe|
cmd = @set.command('thor', 'norse god', interpolate: false, &probe)
cmd.new.process_line 'thor %(#{foo})'
end.to yield_with_args('%(#{foo})')
# rubocop:enable Lint/InterpolationCheck
end
it 'should use shell-words to split strings' do

View File

@ -97,7 +97,9 @@ describe "amend-line" do
puts :bang
STR
# rubocop:disable Lint/InterpolationCheck
@t.process_command 'amend-line puts "#{goodbye}"'
# rubocop:enable Lint/InterpolationCheck
expect(@t.eval_string).to eq unindent(<<-'STR')
def hello

View File

@ -726,7 +726,11 @@ describe "edit" do
before do
Pry.config.editor = lambda do |file, _line|
lines = File.read(file).lines.to_a
# rubocop:disable Lint/InterpolationCheck
lines[1] = '"#{super}aa".to_sym' + "\n"
# rubocop:enable Lint/InterpolationCheck
File.open(file, 'w') do |f|
f.write(lines.join)
end

View File

@ -318,7 +318,9 @@ describe Pry do
a.to_i + 1
end
# rubocop:disable Lint/InterpolationCheck
expect(mock_pry('++ 86', '++ #{_}')).to match(/88/)
# rubocop:enable Lint/InterpolationCheck
end
it "should be preserved over an empty line" do