2014-03-14 00:31:24 -04:00
|
|
|
require_relative '../helper'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
|
|
|
describe "amend-line" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend the last line of input when no line number specified' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line puts :blah'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :blah
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend the specified line of input when line number given' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 1 def goodbye'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def goodbye
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend the first line of input when 0 given as line number' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 0 def goodbye'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def goodbye
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend a specified line when negative number given' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line -1 puts :bink'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bink
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line -2 puts :bink'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bink
|
|
|
|
puts :bink
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend a range of lines of input when negative numbers given' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boat
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line -3..-2 puts :bink'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bink
|
|
|
|
puts :boat
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly amend the specified line with interpolated text' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line puts "#{goodbye}"'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-'STR')
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts "#{goodbye}"
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display error if nothing to amend' do
|
|
|
|
error = nil
|
|
|
|
|
|
|
|
begin
|
|
|
|
@t.process_command 'amend-line'
|
|
|
|
rescue Pry::CommandError => e
|
|
|
|
error = e
|
|
|
|
end
|
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
error.should_not equal nil
|
2012-09-15 17:50:15 -04:00
|
|
|
error.message.should =~ /No input to amend/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly amend the specified range of lines' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 2..3 puts :bong'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bong
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly delete a specific line using the ! for content' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boast
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 3 !'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :boast
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly delete a range of lines using the ! for content' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boast
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 2..4 !'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly delete the previous line using the ! for content' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boast
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line !'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boast
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should amend the specified range of lines, with numbers < 0 in range' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
puts :boast
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 2..-2 puts :bong'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bong
|
|
|
|
puts :heart
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly insert a line before a specified line using >' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 2 > puts :inserted'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :inserted
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should ignore second value of range with > syntax' do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push *unindent(<<-STR).split("\n")
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.process_command 'amend-line 2..21 > puts :inserted'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:45:10 -05:00
|
|
|
@t.eval_string.should == unindent(<<-STR)
|
2012-09-15 17:50:15 -04:00
|
|
|
def hello
|
|
|
|
puts :inserted
|
|
|
|
puts :bing
|
|
|
|
puts :bang
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
end
|