2013-01-12 16:13:18 -05:00
|
|
|
# This command needs a TONNE more tests for it, but i can't figure out
|
|
|
|
# how to do them yet, and i really want to release. Sorry. Someone
|
|
|
|
# come along and do a better job.
|
2012-09-15 17:50:15 -04:00
|
|
|
describe "play" do
|
|
|
|
before do
|
2013-01-18 02:56:07 -05:00
|
|
|
@o = Object.new
|
|
|
|
@t = pry_tester(@o)
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2012-11-30 22:22:16 -05:00
|
|
|
describe "with an argument" do
|
2013-01-08 19:39:02 -05:00
|
|
|
# can't think of a f*cking way to test this!!
|
|
|
|
describe "implied file" do
|
|
|
|
# it 'should play from the file associated with the current binding' do
|
|
|
|
# # require 'fixtures/play_helper'
|
|
|
|
# end
|
2012-11-30 22:22:16 -05:00
|
|
|
|
2013-01-08 19:39:02 -05:00
|
|
|
# describe "integer" do
|
|
|
|
# it "should process one line from _pry_.last_file" do
|
|
|
|
# @t.process_command 'play --lines 1', @eval_str
|
|
|
|
# @eval_str.should =~ /bing = :bing\n/
|
|
|
|
# end
|
|
|
|
# end
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2013-01-08 19:39:02 -05:00
|
|
|
# describe "range" do
|
|
|
|
# it "should process multiple lines at once from _pry_.last_file" do
|
|
|
|
# @t.process_command 'play --lines 1..3', @eval_str
|
|
|
|
# [/bing = :bing\n/, /bang = :bang\n/, /bong = :bong\n/].each { |str|
|
|
|
|
# @eval_str.should =~ str
|
|
|
|
# }
|
|
|
|
# end
|
2012-11-30 22:22:16 -05:00
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-12-12 04:01:23 -05:00
|
|
|
describe "playing a file" do
|
|
|
|
it 'should play a file' do
|
|
|
|
@t.process_command 'play spec/fixtures/whereami_helper.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR)
|
2018-10-14 02:23:34 -04:00
|
|
|
# rubocop:disable Layout/EmptyLineBetweenDefs
|
2013-12-12 04:01:23 -05:00
|
|
|
class Cor
|
|
|
|
def a; end
|
|
|
|
def b; end
|
|
|
|
def c; end
|
|
|
|
def d; end
|
|
|
|
end
|
2018-10-14 02:23:34 -04:00
|
|
|
# rubocop:enable Layout/EmptyLineBetweenDefs
|
2013-12-12 04:01:23 -05:00
|
|
|
STR
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should output file contents with print option' do
|
|
|
|
@t.process_command 'play --print spec/fixtures/whereami_helper.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.last_output).to eq unindent(<<-STR)
|
2018-10-14 02:23:34 -04:00
|
|
|
1: # rubocop:disable Layout/EmptyLineBetweenDefs
|
|
|
|
2: class Cor
|
|
|
|
3: def a; end
|
|
|
|
4: def b; end
|
|
|
|
5: def c; end
|
|
|
|
6: def d; end
|
|
|
|
7: end
|
|
|
|
8: # rubocop:enable Layout/EmptyLineBetweenDefs
|
2013-12-12 04:01:23 -05:00
|
|
|
STR
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-12 16:13:18 -05:00
|
|
|
describe "whatever" do
|
2012-11-30 22:49:27 -05:00
|
|
|
before do
|
|
|
|
def @o.test_method
|
|
|
|
:test_method_content
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2012-11-30 22:49:27 -05:00
|
|
|
it 'should play documentation with the -d switch' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@o.singleton_class.send :remove_method, :test_method
|
|
|
|
|
2012-11-30 22:49:27 -05:00
|
|
|
# @v = 10
|
|
|
|
# @y = 20
|
|
|
|
def @o.test_method
|
|
|
|
:test_method_content
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:53:26 -05:00
|
|
|
@t.process_command 'play -d test_method'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR)
|
2012-11-30 22:49:27 -05:00
|
|
|
@v = 10
|
|
|
|
@y = 20
|
|
|
|
STR
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2012-11-30 22:49:27 -05:00
|
|
|
it 'should restrict -d switch with --lines' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@o.singleton_class.send :remove_method, :test_method
|
|
|
|
|
2012-11-30 22:49:27 -05:00
|
|
|
# @x = 0
|
|
|
|
# @v = 10
|
|
|
|
# @y = 20
|
|
|
|
# @z = 30
|
|
|
|
def @o.test_method
|
|
|
|
:test_method_content
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2012-12-18 03:53:26 -05:00
|
|
|
@t.process_command 'play -d test_method --lines 2..3'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR)
|
2012-11-30 22:49:27 -05:00
|
|
|
@v = 10
|
|
|
|
@y = 20
|
|
|
|
STR
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-01-12 16:13:18 -05:00
|
|
|
it 'has pretty error messages when -d cant find object' do
|
2019-03-03 10:37:58 -05:00
|
|
|
expect { @t.process_command "play -d sdfsdf" }
|
|
|
|
.to raise_error(Pry::CommandError, /Cannot locate/)
|
2013-01-12 16:13:18 -05:00
|
|
|
end
|
|
|
|
|
2013-01-07 17:12:10 -05:00
|
|
|
it 'should play a method (a single line)' do
|
2013-01-18 02:56:07 -05:00
|
|
|
@t.process_command 'play test_method --lines 2'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq ":test_method_content\n"
|
2013-01-12 16:15:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should properly reindent lines' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@o.singleton_class.send :remove_method, :test_method
|
|
|
|
|
2013-01-12 16:15:51 -05:00
|
|
|
def @o.test_method
|
|
|
|
'hello world'
|
|
|
|
end
|
|
|
|
|
2013-01-18 02:56:07 -05:00
|
|
|
@t.process_command 'play test_method --lines 2'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq "'hello world'\n"
|
2012-11-30 22:49:27 -05:00
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2013-01-07 17:12:10 -05:00
|
|
|
it 'should APPEND to the input buffer when playing a method line, not replace it' do
|
2013-01-18 02:56:07 -05:00
|
|
|
@t.eval_string = unindent(<<-STR)
|
2012-11-30 22:49:27 -05:00
|
|
|
def another_test_method
|
|
|
|
STR
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2013-01-18 02:56:07 -05:00
|
|
|
@t.process_command 'play test_method --lines 2'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR)
|
2012-11-30 22:49:27 -05:00
|
|
|
def another_test_method
|
|
|
|
:test_method_content
|
|
|
|
STR
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-01-12 16:15:51 -05:00
|
|
|
it 'should play a method (multiple lines)' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@o.singleton_class.send :remove_method, :test_method
|
|
|
|
|
2012-11-30 22:49:27 -05:00
|
|
|
def @o.test_method
|
|
|
|
@var0 = 10
|
|
|
|
@var1 = 20
|
|
|
|
@var2 = 30
|
|
|
|
@var3 = 40
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2013-01-18 02:56:07 -05:00
|
|
|
@t.process_command 'play test_method --lines 3..4'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR, 0)
|
2012-11-30 22:49:27 -05:00
|
|
|
@var1 = 20
|
|
|
|
@var2 = 30
|
|
|
|
STR
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
2013-01-12 16:13:18 -05:00
|
|
|
|
2013-01-14 11:06:08 -05:00
|
|
|
describe "play -i" do
|
|
|
|
it 'should play multi-ranged input expressions' do
|
|
|
|
a = b = c = d = e = 0
|
2019-03-03 10:48:57 -05:00
|
|
|
redirect_pry_io(
|
|
|
|
InputTester.new(
|
|
|
|
'a += 1', 'b += 1', 'c += 1', 'd += 1', 'e += 1', 'play -i 1..3'
|
|
|
|
),
|
|
|
|
StringIO.new
|
|
|
|
) do
|
|
|
|
binding.pry # rubocop:disable Lint/Debugger
|
2013-01-14 11:06:08 -05:00
|
|
|
end
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
[a, b, c].all? { |v| expect(v).to eq 2 }
|
|
|
|
expect(d).to eq 1
|
|
|
|
expect(e).to eq 1
|
2013-01-14 11:06:08 -05:00
|
|
|
end
|
|
|
|
end
|
2013-07-22 19:03:23 -04:00
|
|
|
|
|
|
|
describe "play -e" do
|
|
|
|
it 'should run an expression from given line number' do
|
2015-01-23 04:30:41 -05:00
|
|
|
@o.singleton_class.send :remove_method, :test_method
|
|
|
|
|
2013-07-22 19:03:23 -04:00
|
|
|
def @o.test_method
|
|
|
|
@s = [
|
2019-02-25 17:40:40 -05:00
|
|
|
1, 2, 3,
|
|
|
|
4, 5, 6
|
2013-07-22 19:03:23 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
@t.process_command 'play test_method -e 2'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq unindent(<<-STR, 0)
|
2013-07-22 19:03:23 -04:00
|
|
|
@s = [
|
2019-02-25 17:40:40 -05:00
|
|
|
1, 2, 3,
|
|
|
|
4, 5, 6
|
2013-07-22 19:03:23 -04:00
|
|
|
]
|
|
|
|
STR
|
|
|
|
end
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|