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

View File

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