mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Directify tests for play
This commit is contained in:
parent
52448d557f
commit
f2b63d0cb2
2 changed files with 44 additions and 47 deletions
|
@ -193,7 +193,7 @@ class Pry
|
||||||
#
|
#
|
||||||
# @param [String] text The text from which to remove indentation
|
# @param [String] text The text from which to remove indentation
|
||||||
# @return [String] The text with indentation stripped.
|
# @return [String] The text with indentation stripped.
|
||||||
def unindent(text)
|
def unindent(text, left_padding = 0)
|
||||||
# Empty blank lines
|
# Empty blank lines
|
||||||
text = text.sub(/^[ \t]+$/, '')
|
text = text.sub(/^[ \t]+$/, '')
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
text.gsub(/^#{margin}/, '')
|
text.gsub(/^#{margin}/, ' ' * left_padding)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Restrict a string to the given range of lines (1-indexed)
|
# Restrict a string to the given range of lines (1-indexed)
|
||||||
|
|
|
@ -276,27 +276,25 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
|
|
||||||
describe "play" do
|
describe "play" do
|
||||||
it 'should play a string variable (with no args)' do
|
it 'should play a string variable (with no args)' do
|
||||||
x = "\"hello\""
|
eval_str = ''
|
||||||
redirect_pry_io(InputTester.new("play x", "exit-all"), @str_output) do
|
|
||||||
Pry.start binding, :hooks => Pry::Hooks.new
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /"hello"/
|
@t.eval 'x = "\"hello\""'
|
||||||
|
@t.process_command 'play x', eval_str
|
||||||
|
|
||||||
|
eval_str.should == '"hello"'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should play a string variable (with no args) using --lines to select what to play' do
|
it 'should play a string variable (with no args) using --lines to select what to play' do
|
||||||
b = binding
|
eval_str = ''
|
||||||
b.eval('x = "\"hello\"\n\"goodbye\"\n\"love\""')
|
|
||||||
redirect_pry_io(InputTester.new("play x --lines 1", "exit-all"), @str_output) do
|
|
||||||
Pry.start b, :hooks => Pry::Hooks.new
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /hello/
|
@t.eval 'x = "\"hello\"\n\"goodbye\"\n\"love\""'
|
||||||
@str_output.string.should.not =~ /love/
|
@t.process_command 'play x --lines 1', eval_str
|
||||||
@str_output.string.should.not =~ /goodbye/
|
|
||||||
|
eval_str.should == "\"hello\"\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should play documentation with the -d switch' do
|
it 'should play documentation with the -d switch' do
|
||||||
|
eval_str = ''
|
||||||
o = Object.new
|
o = Object.new
|
||||||
|
|
||||||
# @v = 10
|
# @v = 10
|
||||||
|
@ -305,15 +303,16 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
:test_method_content
|
:test_method_content
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('play -d test_method', "exit-all")) do
|
pry_tester(o).process_command 'play -d test_method', eval_str
|
||||||
o.pry
|
|
||||||
end
|
|
||||||
|
|
||||||
o.instance_variable_get(:@v).should == 10
|
eval_str.should == unindent(<<-STR)
|
||||||
o.instance_variable_get(:@y).should == 20
|
@v = 10
|
||||||
|
@y = 20
|
||||||
|
STR
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should play documentation with the -d switch (restricted by --lines)' do
|
it 'should restrict -d switch with --lines' do
|
||||||
|
eval_str = ''
|
||||||
o = Object.new
|
o = Object.new
|
||||||
|
|
||||||
# @x = 0
|
# @x = 0
|
||||||
|
@ -324,45 +323,47 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
:test_method_content
|
:test_method_content
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('play -d test_method --lines 2..3', "exit-all")) do
|
pry_tester(o).process_command 'play -d test_method --lines 2..3', eval_str
|
||||||
o.pry
|
|
||||||
end
|
|
||||||
|
|
||||||
o.instance_variable_get(:@x).should == nil
|
eval_str.should == unindent(<<-STR)
|
||||||
o.instance_variable_get(:@z).should == nil
|
@v = 10
|
||||||
o.instance_variable_get(:@v).should == 10
|
@y = 20
|
||||||
o.instance_variable_get(:@y).should == 20
|
STR
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'should play a method with the -m switch (a single line)' do
|
it 'should play a method with the -m switch (a single line)' do
|
||||||
|
eval_str = ''
|
||||||
o = Object.new
|
o = Object.new
|
||||||
|
|
||||||
def o.test_method
|
def o.test_method
|
||||||
:test_method_content
|
:test_method_content
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('play -m test_method --lines 2', "exit-all"), @str_output) do
|
pry_tester(o).process_command 'play -m test_method --lines 2', eval_str
|
||||||
o.pry
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /:test_method_content/
|
eval_str.should == " :test_method_content\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
|
it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
|
||||||
|
eval_str = unindent(<<-STR)
|
||||||
|
def another_test_method
|
||||||
|
STR
|
||||||
|
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.test_method
|
def o.test_method
|
||||||
:test_method_content
|
:test_method_content
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('def another_test_method', 'play -m test_method --lines 2', 'show-input', 'exit-all'), @str_output) do
|
pry_tester(o).process_command 'play -m test_method --lines 2', eval_str
|
||||||
o.pry
|
|
||||||
end
|
|
||||||
|
|
||||||
@str_output.string.should =~ /def another_test_method/
|
eval_str.should == unindent(<<-STR)
|
||||||
@str_output.string.should =~ /:test_method_content/
|
def another_test_method
|
||||||
|
:test_method_content
|
||||||
|
STR
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should play a method with the -m switch (multiple line)' do
|
it 'should play a method with the -m switch (multiple line)' do
|
||||||
|
eval_str = ''
|
||||||
o = Object.new
|
o = Object.new
|
||||||
|
|
||||||
def o.test_method
|
def o.test_method
|
||||||
|
@ -372,16 +373,12 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
@var3 = 40
|
@var3 = 40
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('play -m test_method --lines 3..4', "exit-all"), @str_output) do
|
pry_tester(o).process_command 'play -m test_method --lines 3..4', eval_str
|
||||||
o.pry
|
|
||||||
end
|
|
||||||
|
|
||||||
o.instance_variable_get(:@var0).should == nil
|
eval_str.should == unindent(<<-STR, 2)
|
||||||
o.instance_variable_get(:@var1).should == 20
|
@var1 = 20
|
||||||
o.instance_variable_get(:@var2).should == 30
|
@var2 = 30
|
||||||
o.instance_variable_get(:@var3).should == nil
|
STR
|
||||||
@str_output.string.should =~ /30/
|
|
||||||
@str_output.string.should.not =~ /20/
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue