1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

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/pager.rb'
- 'lib/pry/terminal.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 # Offense count: 1
Lint/Loop: Lint/Loop:
Exclude: Exclude:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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