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

Use accept_line in amend_line_spec instead of passing eval_string

This commit is contained in:
Ryan Fitzgerald 2012-12-18 00:45:10 -08:00
parent 94bf5d63d0
commit d80e0494af
3 changed files with 52 additions and 43 deletions

View file

@ -35,6 +35,7 @@ class Pry
attr_accessor :custom_completions attr_accessor :custom_completions
attr_accessor :binding_stack attr_accessor :binding_stack
attr_accessor :eval_string
attr_accessor :last_result attr_accessor :last_result
attr_accessor :last_file attr_accessor :last_file

View file

@ -101,8 +101,12 @@ def pry_eval(*eval_strs)
end end
class PryTester class PryTester
extend Forwardable
attr_reader :pry, :out attr_reader :pry, :out
def_delegators :@pry, :eval_string, :eval_string=, :accept_line
def initialize(target = TOPLEVEL_BINDING, options = {}) def initialize(target = TOPLEVEL_BINDING, options = {})
@pry = Pry.new(options.merge(:target => target)) @pry = Pry.new(options.merge(:target => target))
@history = options[:history] @history = options[:history]
@ -130,6 +134,10 @@ class PryTester
result result
end end
def accept_lines(*lines)
lines.each(&method(:accept_line))
end
def push_binding(context) def push_binding(context)
@pry.push_binding context @pry.push_binding context
end end
@ -155,8 +163,8 @@ class PryTester
@out.string if @out @out.string if @out
end end
def process_command(command_str, eval_str = '') def process_command(command_str)
@pry.process_command(command_str, eval_str) or raise "Not a valid command" @pry.process_command(command_str) or raise "Not a valid command"
last_command_result_or_output last_command_result_or_output
end end

View file

@ -6,29 +6,29 @@ describe "amend-line" do
end end
it 'should amend the last line of input when no line number specified' do it 'should amend the last line of input when no line number specified' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
STR STR
@t.process_command 'amend-line puts :blah', eval_str @t.process_command 'amend-line puts :blah'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :blah puts :blah
STR STR
end end
it 'should amend the specified line of input when line number given' do it 'should amend the specified line of input when line number given' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line 1 def goodbye', eval_str @t.process_command 'amend-line 1 def goodbye'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def goodbye def goodbye
puts :bing puts :bing
puts :bang puts :bang
@ -36,15 +36,15 @@ describe "amend-line" do
end end
it 'should amend the first line of input when 0 given as line number' do it 'should amend the first line of input when 0 given as line number' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line 0 def goodbye', eval_str @t.process_command 'amend-line 0 def goodbye'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def goodbye def goodbye
puts :bing puts :bing
puts :bang puts :bang
@ -52,23 +52,23 @@ describe "amend-line" do
end end
it 'should amend a specified line when negative number given' do it 'should amend a specified line when negative number given' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line -1 puts :bink', eval_str @t.process_command 'amend-line -1 puts :bink'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bink puts :bink
STR STR
@t.process_command 'amend-line -2 puts :bink', eval_str @t.process_command 'amend-line -2 puts :bink'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bink puts :bink
puts :bink puts :bink
@ -76,16 +76,16 @@ describe "amend-line" do
end end
it 'should amend a range of lines of input when negative numbers given' do it 'should amend a range of lines of input when negative numbers given' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
puts :boat puts :boat
STR STR
@t.process_command 'amend-line -3..-2 puts :bink', eval_str @t.process_command 'amend-line -3..-2 puts :bink'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bink puts :bink
puts :boat puts :boat
@ -93,15 +93,15 @@ describe "amend-line" do
end end
it 'should correctly amend the specified line with interpolated text' do it 'should correctly amend the specified line with interpolated text' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line puts "#{goodbye}"', eval_str @t.process_command 'amend-line puts "#{goodbye}"'
eval_str.should == unindent(<<-'STR') @t.eval_string.should == unindent(<<-'STR')
def hello def hello
puts :bing puts :bing
puts "#{goodbye}" puts "#{goodbye}"
@ -122,16 +122,16 @@ describe "amend-line" do
end end
it 'should correctly amend the specified range of lines' do it 'should correctly amend the specified range of lines' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
puts :heart puts :heart
STR STR
@t.process_command 'amend-line 2..3 puts :bong', eval_str @t.process_command 'amend-line 2..3 puts :bong'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bong puts :bong
puts :heart puts :heart
@ -139,7 +139,7 @@ describe "amend-line" do
end end
it 'should correctly delete a specific line using the ! for content' do it 'should correctly delete a specific line using the ! for content' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -147,9 +147,9 @@ describe "amend-line" do
puts :heart puts :heart
STR STR
@t.process_command 'amend-line 3 !', eval_str @t.process_command 'amend-line 3 !'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :boast puts :boast
@ -158,7 +158,7 @@ describe "amend-line" do
end end
it 'should correctly delete a range of lines using the ! for content' do it 'should correctly delete a range of lines using the ! for content' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -166,16 +166,16 @@ describe "amend-line" do
puts :heart puts :heart
STR STR
@t.process_command 'amend-line 2..4 !', eval_str @t.process_command 'amend-line 2..4 !'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :heart puts :heart
STR STR
end end
it 'should correctly delete the previous line using the ! for content' do it 'should correctly delete the previous line using the ! for content' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -183,9 +183,9 @@ describe "amend-line" do
puts :heart puts :heart
STR STR
@t.process_command 'amend-line !', eval_str @t.process_command 'amend-line !'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -194,7 +194,7 @@ describe "amend-line" do
end end
it 'should amend the specified range of lines, with numbers < 0 in range' do it 'should amend the specified range of lines, with numbers < 0 in range' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -202,9 +202,9 @@ describe "amend-line" do
puts :heart puts :heart
STR STR
@t.process_command 'amend-line 2..-2 puts :bong', eval_str @t.process_command 'amend-line 2..-2 puts :bong'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :bong puts :bong
puts :heart puts :heart
@ -212,15 +212,15 @@ describe "amend-line" do
end end
it 'should correctly insert a line before a specified line using >' do it 'should correctly insert a line before a specified line using >' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line 2 > puts :inserted', eval_str @t.process_command 'amend-line 2 > puts :inserted'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :inserted puts :inserted
puts :bing puts :bing
@ -229,15 +229,15 @@ describe "amend-line" do
end end
it 'should ignore second value of range with > syntax' do it 'should ignore second value of range with > syntax' do
eval_str = unindent(<<-STR) @t.accept_lines *unindent(<<-STR).split("\n")
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
STR STR
@t.process_command 'amend-line 2..21 > puts :inserted', eval_str @t.process_command 'amend-line 2..21 > puts :inserted'
eval_str.should == unindent(<<-STR) @t.eval_string.should == unindent(<<-STR)
def hello def hello
puts :inserted puts :inserted
puts :bing puts :bing