diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb index e9fc5bfa..5498d38d 100644 --- a/lib/pry/commands/play.rb +++ b/lib/pry/commands/play.rb @@ -32,13 +32,14 @@ class Pry ' modify the method.' opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer + opt.on :p, :print, 'Prints executed code' end def process @cc = CodeCollector.new(args, opts, _pry_) perform_play - run "show-input" unless Pry::Code.complete_expression?(eval_string) + show_input end def perform_play @@ -46,6 +47,13 @@ class Pry run "fix-indent" end + def show_input + if opts.present?(:print) or !Pry::Code.complete_expression?(eval_string) + run "show-input" + end + end + + def content_after_options if opts.present?(:open) restrict_to_lines(content, (0..-2)) diff --git a/spec/commands/play_spec.rb b/spec/commands/play_spec.rb index 68192bac..c766b09c 100644 --- a/spec/commands/play_spec.rb +++ b/spec/commands/play_spec.rb @@ -36,6 +36,33 @@ describe "play" do 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 before do def @o.test_method