Make pry_tester accept Pry ctor options

This commit is contained in:
Ryan Fitzgerald 2012-09-08 22:46:45 -07:00
parent 9b52d358ae
commit 1a1ea323ea
2 changed files with 12 additions and 11 deletions

View File

@ -242,8 +242,10 @@ ensure
File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
end end
def pry_tester(context = TOPLEVEL_BINDING, &block) def pry_tester(*args, &block)
PryTester.new(context).tap do |t| args << TOPLEVEL_BINDING if args.length == 0
PryTester.new(*args).tap do |t|
(class << t; self; end).class_eval(&block) if block (class << t; self; end).class_eval(&block) if block
end end
end end
@ -261,8 +263,8 @@ end
class PryTester class PryTester
attr_reader :pry, :out attr_reader :pry, :out
def initialize(context = TOPLEVEL_BINDING) def initialize(context = TOPLEVEL_BINDING, options = {})
@pry = Pry.new @pry = Pry.new(options)
if context if context
@pry.binding_stack << Pry.binding_for(context) @pry.binding_stack << Pry.binding_for(context)
@ -277,7 +279,7 @@ class PryTester
result = nil result = nil
strs.flatten.each do |str| strs.flatten.each do |str|
str = "#{str}\n" unless str.end_with?("\n") str = "#{str.strip}\n"
if @pry.process_command(str) if @pry.process_command(str)
result = last_command_result_or_output result = last_command_result_or_output
else else

View File

@ -352,12 +352,11 @@ describe "Pry::Command" do
end end
it 'should accept multiline blocks' do it 'should accept multiline blocks' do
redirect_pry_io(InputTester.new("walking-spanish | do", pry_tester(@context, :commands => @set).eval <<-EOS
" :jesus", walking-spanish | do
"end", :jesus
"exit-all"), out = StringIO.new) do end
Pry.start @context, :commands => @set EOS
end
@context.instance_variable_get(:@x).should == :jesus @context.instance_variable_get(:@x).should == :jesus
end end