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

move Pad to local helpers, and move more methods in PryTestHelpers

This commit is contained in:
John Mair 2012-12-08 23:56:57 +01:00
parent 9a279461c1
commit 4bf42ca006
3 changed files with 28 additions and 27 deletions

View file

@ -24,10 +24,6 @@ end
Pry.reset_defaults
# A global space for storing temporary state during tests.
Pad = OpenStruct.new
def Pad.clear
@table = {}
end
module PryTestHelpers
@ -70,34 +66,34 @@ module PryTestHelpers
def unindent(*args)
Pry::Helpers::CommandHelpers.unindent(*args)
end
end
def mock_pry(*args)
args.flatten!
binding = args.first.is_a?(Binding) ? args.shift : binding()
def mock_pry(*args)
args.flatten!
binding = args.first.is_a?(Binding) ? args.shift : binding()
input = InputTester.new(*args)
output = StringIO.new
input = InputTester.new(*args)
output = StringIO.new
redirect_pry_io(input, output) do
binding.pry
redirect_pry_io(input, output) do
binding.pry
end
output.string
end
output.string
end
def mock_command(cmd, args=[], opts={})
output = StringIO.new
ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
Struct.new(:output, :return).new(output.string, ret)
end
def mock_exception(*mock_backtrace)
e = StandardError.new("mock exception")
(class << e; self; end).class_eval do
define_method(:backtrace) { mock_backtrace }
def mock_command(cmd, args=[], opts={})
output = StringIO.new
ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
Struct.new(:output, :return).new(output.string, ret)
end
def mock_exception(*mock_backtrace)
e = StandardError.new("mock exception")
(class << e; self; end).class_eval do
define_method(:backtrace) { mock_backtrace }
end
e
end
e
end
def pry_tester(*args, &block)

View file

@ -31,6 +31,11 @@ def redirect_pry_io(new_in, new_out = StringIO.new)
end
end
Pad = OpenStruct.new
def Pad.clear
@table = {}
end
class InputTester
def initialize(*actions)
@orig_actions = actions.dup

View file

@ -41,7 +41,7 @@ describe Pry do
end
it "should not be phased by un-inspectable things" do
mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<NastyClass:0x.*?>/
mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<.*NastyClass:0x.*?>/
end
end