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

Add print option to play command (resolves #864)

When print option in play is used, it prints the executed code.
This commit is contained in:
Uros Jurglic 2013-12-12 10:01:23 +01:00
parent 2a2db1a9d6
commit 0262e827ae
2 changed files with 36 additions and 1 deletions

View file

@ -32,13 +32,14 @@ class Pry
' modify the method.' ' modify the method.'
opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer
opt.on :p, :print, 'Prints executed code'
end end
def process def process
@cc = CodeCollector.new(args, opts, _pry_) @cc = CodeCollector.new(args, opts, _pry_)
perform_play perform_play
run "show-input" unless Pry::Code.complete_expression?(eval_string) show_input
end end
def perform_play def perform_play
@ -46,6 +47,13 @@ class Pry
run "fix-indent" run "fix-indent"
end end
def show_input
if opts.present?(:print) or !Pry::Code.complete_expression?(eval_string)
run "show-input"
end
end
def content_after_options def content_after_options
if opts.present?(:open) if opts.present?(:open)
restrict_to_lines(content, (0..-2)) restrict_to_lines(content, (0..-2))

View file

@ -36,6 +36,33 @@ describe "play" do
end end
end end
describe "playing a file" do
it 'should play a file' do
@t.process_command 'play spec/fixtures/whereami_helper.rb'
@t.eval_string.should == unindent(<<-STR)
class Cor
def a; end
def b; end
def c; end
def d; end
end
STR
end
it 'should output file contents with print option' do
@t.process_command 'play --print spec/fixtures/whereami_helper.rb'
@t.last_output.should == unindent(<<-STR)
1: class Cor
2: def a; end
3: def b; end
4: def c; end
5: def d; end
6: end
STR
end
end
describe "whatever" do describe "whatever" do
before do before do
def @o.test_method def @o.test_method