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

cleaned up lib/pry/test/helper.rb

* removed most historicla junk from lib/pry/test/helper.rb
* relocated recalcitrant junk to the local spec/helper.rb (this isn't exposed to 3rd parties)
This commit is contained in:
John Mair 2012-12-07 01:52:37 +01:00
parent d65e5c8901
commit 31a9578228
18 changed files with 274 additions and 313 deletions

View file

@ -49,7 +49,7 @@ task :test do
check_dependencies unless ENV['SKIP_DEP_CHECK'] check_dependencies unless ENV['SKIP_DEP_CHECK']
all_specs = Dir['spec/**/*_spec.rb'] all_specs = Dir['spec/**/*_spec.rb']
all_specs.shuffle! if all_specs.respond_to? :shuffle! all_specs.shuffle! if all_specs.respond_to? :shuffle!
system "bacon -Ilib/pry/test -Ispec -rubygems -a -q #{all_specs.join ' '}" system "bacon -Ispec -rubygems -a -q #{all_specs.join ' '}"
end end
task :spec => :test task :spec => :test

View file

@ -1,60 +1,9 @@
unless Object.const_defined? 'Pry' require 'pry'
$:.unshift File.expand_path '../../../../lib', __FILE__
require 'pry'
end
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}" puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
require File.join(File.expand_path(File.dirname(__FILE__)), 'bacon_helper') if defined?(Bacon) if defined?(Bacon)
require File.join(File.expand_path(File.dirname(__FILE__)), 'bacon_helper')
# A global space for storing temporary state during tests.
Pad = OpenStruct.new
def Pad.clear
@table = {}
end
# turn warnings off (esp for Pry::Hooks which will generate warnings
# in tests)
$VERBOSE = nil
# inject a variable into a binding
def inject_var(name, value, b)
Thread.current[:__pry_local__] = value
b.eval("#{name} = Thread.current[:__pry_local__]")
ensure
Thread.current[:__pry_local__] = nil
end
def constant_scope(*names)
names.each do |name|
Object.remove_const name if Object.const_defined?(name)
end
yield
ensure
names.each do |name|
Object.remove_const name if Object.const_defined?(name)
end
end
def mri18_and_no_real_source_location?
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
end
# used by test_show_source.rb and test_documentation.rb
class TestClassForShowSource
def alpha
end
end
class TestClassForShowSourceClassEval
def alpha
end
end
class TestClassForShowSourceInstanceEval
def alpha
end
end end
# in case the tests call reset_defaults, ensure we reset them to # in case the tests call reset_defaults, ensure we reset them to
@ -76,42 +25,51 @@ class << Pry
Pry.config.collision_warning = false Pry.config.collision_warning = false
end end
end 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
Pry.reset_defaults Pry.reset_defaults
# this is to test exception code (cat --ex) # A global space for storing temporary state during tests.
def broken_method Pad = OpenStruct.new
this method is broken def Pad.clear
@table = {}
end end
# sample doc module PryTestHelpers
def sample_method # inject a variable into a binding
:sample def self.inject_var(name, value, b)
end Thread.current[:__pry_local__] = value
b.eval("#{name} = Thread.current[:__pry_local__]")
ensure
Thread.current[:__pry_local__] = nil
end
# Set I/O streams. def self.constant_scope(*names)
# names.each do |name|
# Out defaults to an anonymous StringIO. Object.remove_const name if Object.const_defined?(name)
# end
def redirect_pry_io(new_in, new_out = StringIO.new)
old_in = Pry.input
old_out = Pry.output
Pry.input = new_in
Pry.output = new_out
begin
yield yield
ensure ensure
Pry.input = old_in names.each do |name|
Pry.output = old_out Object.remove_const name if Object.const_defined?(name)
end
end
def self.mri18_and_no_real_source_location?
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
end
# Open a temp file and yield it to the block, closing it after
# @return [String] The path of the temp file
def self.temp_file(ext='.rb')
file = Tempfile.new(['pry', ext])
yield file
ensure
file.close(true) if file
File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
end
def self.unindent(*args)
Pry::Helpers::CommandHelpers.unindent(*args)
end end
end end
@ -135,64 +93,12 @@ def mock_command(cmd, args=[], opts={})
Struct.new(:output, :return).new(output.string, ret) Struct.new(:output, :return).new(output.string, ret)
end end
def redirect_global_pry_input(new_io) def mock_exception(*mock_backtrace)
old_io = Pry.input e = StandardError.new("mock exception")
Pry.input = new_io (class << e; self; end).class_eval do
begin define_method(:backtrace) { mock_backtrace }
yield
ensure
Pry.input = old_io
end
end
def redirect_global_pry_output(new_io)
old_io = Pry.output
Pry.output = new_io
begin
yield
ensure
Pry.output = old_io
end
end
class Module
public :remove_const
public :remove_method
end
class InputTester
def initialize(*actions)
@orig_actions = actions.dup
@actions = actions
end end
e
def readline(*)
@actions.shift
end
def rewind
@actions = @orig_actions.dup
end
end
class Pry
# null output class - doesn't write anywwhere.
class NullOutput
def self.puts(*) end
def self.string(*) end
end
end
# Open a temp file and yield it to the block, closing it after
# @return [String] The path of the temp file
def temp_file(ext='.rb')
file = Tempfile.new(['pry', ext])
yield file
ensure
file.close(true) if file
File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
end end
def pry_tester(*args, &block) def pry_tester(*args, &block)
@ -298,25 +204,3 @@ class PryTester
@pry.output = @out @pry.output = @out
end end
end end
CommandTester = Pry::CommandSet.new do
command "command1", "command 1 test" do
output.puts "command1"
end
command "command2", "command 2 test" do |arg|
output.puts arg
end
end
def unindent(*args)
Pry::Helpers::CommandHelpers.unindent(*args)
end
# to help with tracking down bugs that cause an infinite loop in the test suite
if ENV["SET_TRACE_FUNC"]
require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
set_trace_func proc { |event, file, line, id, binding, classname|
STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
end

View file

@ -12,19 +12,19 @@ describe Pry::Code do
end end
should 'default to Ruby' do should 'default to Ruby' do
temp_file('') do |f| PryTestHelpers.temp_file('') do |f|
Pry::Code.from_file(f.path).code_type.should == :ruby Pry::Code.from_file(f.path).code_type.should == :ruby
end end
end end
should 'check the extension' do should 'check the extension' do
temp_file('.c') do |f| PryTestHelpers.temp_file('.c') do |f|
Pry::Code.from_file(f.path).code_type.should == :c Pry::Code.from_file(f.path).code_type.should == :c
end end
end end
should 'use the provided extension' do should 'use the provided extension' do
temp_file('.c') do |f| PryTestHelpers.temp_file('.c') do |f|
Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby
end end
end end

View file

@ -1,5 +1,6 @@
require 'helper' require 'helper'
describe "commands" do describe "commands" do
before do before do
@str_output = StringIO.new @str_output = StringIO.new
@ -12,6 +13,16 @@ describe "commands" do
@self = "Pad.self = self" @self = "Pad.self = self"
@command_tester = Pry::CommandSet.new do
command "command1", "command 1 test" do
output.puts "command1"
end
command "command2", "command 2 test" do |arg|
output.puts arg
end
end
Pad.bong = "bong" Pad.bong = "bong"
end end
@ -46,17 +57,10 @@ describe "commands" do
alias_command "test-alias", "test-command" alias_command "test-alias", "test-command"
end end
redirect_pry_io(InputTester.new("test-command hello baby duck"), out1 = StringIO.new) do t = pry_tester(:commands => set)
Pry.start self, :commands => set
end
out1.string.should =~ /hello baby duck/ t.process_command "test-alias hello baby duck"
t.last_output.should =~ /testing hello baby duck/
redirect_pry_io(InputTester.new("test-alias hello baby duck"), out2 = StringIO.new) do
Pry.start self, :commands => set
end
out2.string.should == out1.string
end end
it 'should pass option arguments to original' do it 'should pass option arguments to original' do
@ -66,17 +70,10 @@ describe "commands" do
end end
obj = Class.new { @x = 10 } obj = Class.new { @x = 10 }
redirect_pry_io(InputTester.new("ls -i"), out1 = StringIO.new) do t = pry_tester(obj, :commands => set)
Pry.start obj, :commands => set
end
out1.string.should =~ /@x/ t.process_command "test-alias -i"
t.last_output.should =~ /@x/
redirect_pry_io(InputTester.new("test-alias -i"), out2 = StringIO.new) do
Pry.start obj, :commands => set
end
out2.string.should == out1.string
end end
it 'should pass option arguments to original with additional parameters' do it 'should pass option arguments to original with additional parameters' do
@ -86,17 +83,9 @@ describe "commands" do
end end
obj = Class.new { @x = Class.new { define_method(:plymouth) {} } } obj = Class.new { @x = Class.new { define_method(:plymouth) {} } }
redirect_pry_io(InputTester.new("ls -M @x"), out1 = StringIO.new) do t = pry_tester(obj, :commands => set)
Pry.start obj, :commands => set t.process_command "test-alias @x"
end t.last_output.should =~ /plymouth/
out1.string.should =~ /plymouth/
redirect_pry_io(InputTester.new("test-alias @x"), out2 = StringIO.new) do
Pry.start obj, :commands => set
end
out2.string.should == out1.string
end end
it 'should be able to alias a regex command' do it 'should be able to alias a regex command' do
@ -107,11 +96,9 @@ describe "commands" do
alias_command "test-alias", "duck" alias_command "test-alias", "duck"
end end
redirect_pry_io(InputTester.new("test-alias"), out1 = StringIO.new) do t = pry_tester(:commands => set)
Pry.start self, :commands => set t.process_command "test-alias"
end t.last_output.should =~ /ducky/
out1.string.should =~ /ducky/
end end
it 'should be able to make the alias a regex' do it 'should be able to make the alias a regex' do
@ -138,6 +125,7 @@ describe "commands" do
run "cd / " run "cd / "
end end
end end
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run", redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
@self, @bs2, "exit-all")) do @self, @bs2, "exit-all")) do
Pry.start(@o, :commands => set) Pry.start(@o, :commands => set)
@ -630,9 +618,9 @@ describe "commands" do
it 'should run a command with no parameter' do it 'should run a command with no parameter' do
pry_tester = Pry.new pry_tester = Pry.new
pry_tester.commands = CommandTester pry_tester.commands = @command_tester
pry_tester.input = InputTester.new("command1", "exit-all") pry_tester.input = InputTester.new("command1", "exit-all")
pry_tester.commands = CommandTester pry_tester.commands = @command_tester
pry_tester.output = @str_output pry_tester.output = @str_output
@ -643,9 +631,9 @@ describe "commands" do
it 'should run a command with one parameter' do it 'should run a command with one parameter' do
pry_tester = Pry.new pry_tester = Pry.new
pry_tester.commands = CommandTester pry_tester.commands = @command_tester
pry_tester.input = InputTester.new("command2 horsey", "exit-all") pry_tester.input = InputTester.new("command2 horsey", "exit-all")
pry_tester.commands = CommandTester pry_tester.commands = @command_tester
pry_tester.output = @str_output pry_tester.output = @str_output

View file

@ -469,7 +469,7 @@ describe "Pry::Command" do
before do before do
@context = Object.new @context = Object.new
@set.command "walking-spanish", "down the hall", :takes_block => true do @set.command "walking-spanish", "down the hall", :takes_block => true do
inject_var(:@x, command_block.call, target) PryTestHelpers.inject_var(:@x, command_block.call, target)
end end
@set.import Pry::Commands @set.import Pry::Commands
@ -490,9 +490,9 @@ describe "Pry::Command" do
@set.block_command "walking-spanish", @set.block_command "walking-spanish",
"litella's been screeching for a blind pig.", "litella's been screeching for a blind pig.",
:takes_block => true do |x, y| :takes_block => true do |x, y|
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
inject_var(:@y, y, target) PryTestHelpers.inject_var(:@y, y, target)
inject_var(:@block_var, command_block.call, target) PryTestHelpers.inject_var(:@block_var, command_block.call, target)
end end
@t.eval 'walking-spanish john carl| { :jesus }' @t.eval 'walking-spanish john carl| { :jesus }'
@ -524,8 +524,8 @@ describe "Pry::Command" do
describe "arg_string" do describe "arg_string" do
it 'should remove block-related content from arg_string (with one normal arg)' do it 'should remove block-related content from arg_string (with one normal arg)' do
@set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y| @set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
inject_var(:@arg_string, arg_string, target) PryTestHelpers.inject_var(:@arg_string, arg_string, target)
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
end end
@t.eval 'walking-spanish john| { :jesus }' @t.eval 'walking-spanish john| { :jesus }'
@ -535,7 +535,7 @@ describe "Pry::Command" do
it 'should remove block-related content from arg_string (with no normal args)' do it 'should remove block-related content from arg_string (with no normal args)' do
@set.block_command "walking-spanish", "down the hall", :takes_block => true do @set.block_command "walking-spanish", "down the hall", :takes_block => true do
inject_var(:@arg_string, arg_string, target) PryTestHelpers.inject_var(:@arg_string, arg_string, target)
end end
@t.eval 'walking-spanish | { :jesus }' @t.eval 'walking-spanish | { :jesus }'
@ -546,7 +546,7 @@ describe "Pry::Command" do
it 'should NOT remove block-related content from arg_string when :takes_block => false' do it 'should NOT remove block-related content from arg_string when :takes_block => false' do
block_string = "| { :jesus }" block_string = "| { :jesus }"
@set.block_command "walking-spanish", "homemade special", :takes_block => false do @set.block_command "walking-spanish", "homemade special", :takes_block => false do
inject_var(:@arg_string, arg_string, target) PryTestHelpers.inject_var(:@arg_string, arg_string, target)
end end
@t.eval "walking-spanish #{block_string}" @t.eval "walking-spanish #{block_string}"
@ -559,8 +559,8 @@ describe "Pry::Command" do
describe "block_command" do describe "block_command" do
it "should remove block-related content from arguments" do it "should remove block-related content from arguments" do
@set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y| @set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
inject_var(:@y, y, target) PryTestHelpers.inject_var(:@y, y, target)
end end
@t.eval 'walking-spanish | { :jesus }' @t.eval 'walking-spanish | { :jesus }'
@ -571,8 +571,8 @@ describe "Pry::Command" do
it "should NOT remove block-related content from arguments if :takes_block => false" do it "should NOT remove block-related content from arguments if :takes_block => false" do
@set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y| @set.block_command "walking-spanish", "litella screeching for a blind pig", :takes_block => false do |x, y|
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
inject_var(:@y, y, target) PryTestHelpers.inject_var(:@y, y, target)
end end
@t.eval 'walking-spanish | { :jesus }' @t.eval 'walking-spanish | { :jesus }'
@ -586,8 +586,8 @@ describe "Pry::Command" do
it "should remove block-related content from arguments" do it "should remove block-related content from arguments" do
@set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do @set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
def process(x, y) def process(x, y)
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
inject_var(:@y, y, target) PryTestHelpers.inject_var(:@y, y, target)
end end
end end
@ -600,8 +600,8 @@ describe "Pry::Command" do
it "should NOT remove block-related content from arguments if :takes_block => false" do it "should NOT remove block-related content from arguments if :takes_block => false" do
@set.create_command "walking-spanish", "down the hall", :takes_block => false do @set.create_command "walking-spanish", "down the hall", :takes_block => false do
def process(x, y) def process(x, y)
inject_var(:@x, x, target) PryTestHelpers.inject_var(:@x, x, target)
inject_var(:@y, y, target) PryTestHelpers.inject_var(:@y, y, target)
end end
end end
@ -618,7 +618,7 @@ describe "Pry::Command" do
describe "{} style blocks" do describe "{} style blocks" do
it 'should accept multiple parameters' do it 'should accept multiple parameters' do
@set.block_command "walking-spanish", "down the hall", :takes_block => true do @set.block_command "walking-spanish", "down the hall", :takes_block => true do
inject_var(:@x, command_block.call(1, 2), target) PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
end end
@t.eval 'walking-spanish | { |x, y| [x, y] }' @t.eval 'walking-spanish | { |x, y| [x, y] }'
@ -631,7 +631,7 @@ describe "Pry::Command" do
it 'should accept multiple parameters' do it 'should accept multiple parameters' do
@set.create_command "walking-spanish", "litella", :takes_block => true do @set.create_command "walking-spanish", "litella", :takes_block => true do
def process def process
inject_var(:@x, command_block.call(1, 2), target) PryTestHelpers.inject_var(:@x, command_block.call(1, 2), target)
end end
end end
@ -657,7 +657,7 @@ describe "Pry::Command" do
describe "block_command" do describe "block_command" do
it "should expose block in command_block method" do it "should expose block in command_block method" do
@set.block_command "walking-spanish", "glass full of sand", :takes_block => true do @set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
inject_var(:@x, command_block.call, target) PryTestHelpers.inject_var(:@x, command_block.call, target)
end end
@t.eval 'walking-spanish | { :jesus }' @t.eval 'walking-spanish | { :jesus }'
@ -683,7 +683,7 @@ describe "Pry::Command" do
it "should expose block in command_block method" do it "should expose block in command_block method" do
@set.create_command "walking-spanish", "homemade special", :takes_block => true do @set.create_command "walking-spanish", "homemade special", :takes_block => true do
def process def process
inject_var(:@x, command_block.call, target) PryTestHelpers.inject_var(:@x, command_block.call, target)
end end
end end
@ -719,7 +719,7 @@ describe "Pry::Command" do
pry_eval("my---test").should =~ /my-testmy-test/ pry_eval("my---test").should =~ /my-testmy-test/
end end
if !mri18_and_no_real_source_location? if !PryTestHelpers.mri18_and_no_real_source_location?
it "should show the source of the process method" do it "should show the source of the process method" do
pry_eval("show-source my-test").should =~ /output.puts command_name/ pry_eval("show-source my-test").should =~ /output.puts command_name/
end end

View file

@ -6,21 +6,21 @@ describe "amend-line" do
end end
it 'should amend the last line of input when no line number specified' do it 'should amend the last line of input when no line number specified' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
STR STR
@t.process_command 'amend-line puts :blah', eval_str @t.process_command 'amend-line puts :blah', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :blah puts :blah
STR STR
end end
it 'should amend the specified line of input when line number given' do it 'should amend the specified line of input when line number given' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -28,7 +28,7 @@ describe "amend-line" do
@t.process_command 'amend-line 1 def goodbye', eval_str @t.process_command 'amend-line 1 def goodbye', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def goodbye def goodbye
puts :bing puts :bing
puts :bang puts :bang
@ -36,7 +36,7 @@ describe "amend-line" do
end end
it 'should amend the first line of input when 0 given as line number' do it 'should amend the first line of input when 0 given as line number' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -44,7 +44,7 @@ describe "amend-line" do
@t.process_command 'amend-line 0 def goodbye', eval_str @t.process_command 'amend-line 0 def goodbye', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def goodbye def goodbye
puts :bing puts :bing
puts :bang puts :bang
@ -52,7 +52,7 @@ describe "amend-line" do
end end
it 'should amend a specified line when negative number given' do it 'should amend a specified line when negative number given' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -60,7 +60,7 @@ describe "amend-line" do
@t.process_command 'amend-line -1 puts :bink', eval_str @t.process_command 'amend-line -1 puts :bink', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bink puts :bink
@ -68,7 +68,7 @@ describe "amend-line" do
@t.process_command 'amend-line -2 puts :bink', eval_str @t.process_command 'amend-line -2 puts :bink', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bink puts :bink
puts :bink puts :bink
@ -76,7 +76,7 @@ describe "amend-line" do
end end
it 'should amend a range of lines of input when negative numbers given' do it 'should amend a range of lines of input when negative numbers given' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -85,7 +85,7 @@ describe "amend-line" do
@t.process_command 'amend-line -3..-2 puts :bink', eval_str @t.process_command 'amend-line -3..-2 puts :bink', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bink puts :bink
puts :boat puts :boat
@ -93,7 +93,7 @@ describe "amend-line" do
end end
it 'should correctly amend the specified line with interpolated text' do it 'should correctly amend the specified line with interpolated text' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -101,7 +101,7 @@ describe "amend-line" do
@t.process_command 'amend-line puts "#{goodbye}"', eval_str @t.process_command 'amend-line puts "#{goodbye}"', eval_str
eval_str.should == unindent(<<-'STR') eval_str.should == PryTestHelpers.unindent(<<-'STR')
def hello def hello
puts :bing puts :bing
puts "#{goodbye}" puts "#{goodbye}"
@ -122,7 +122,7 @@ describe "amend-line" do
end end
it 'should correctly amend the specified range of lines' do it 'should correctly amend the specified range of lines' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -131,7 +131,7 @@ describe "amend-line" do
@t.process_command 'amend-line 2..3 puts :bong', eval_str @t.process_command 'amend-line 2..3 puts :bong', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bong puts :bong
puts :heart puts :heart
@ -139,7 +139,7 @@ describe "amend-line" do
end end
it 'should correctly delete a specific line using the ! for content' do it 'should correctly delete a specific line using the ! for content' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -149,7 +149,7 @@ describe "amend-line" do
@t.process_command 'amend-line 3 !', eval_str @t.process_command 'amend-line 3 !', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :boast puts :boast
@ -158,7 +158,7 @@ describe "amend-line" do
end end
it 'should correctly delete a range of lines using the ! for content' do it 'should correctly delete a range of lines using the ! for content' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -168,14 +168,14 @@ describe "amend-line" do
@t.process_command 'amend-line 2..4 !', eval_str @t.process_command 'amend-line 2..4 !', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :heart puts :heart
STR STR
end end
it 'should correctly delete the previous line using the ! for content' do it 'should correctly delete the previous line using the ! for content' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -185,7 +185,7 @@ describe "amend-line" do
@t.process_command 'amend-line !', eval_str @t.process_command 'amend-line !', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -194,7 +194,7 @@ describe "amend-line" do
end end
it 'should amend the specified range of lines, with numbers < 0 in range' do it 'should amend the specified range of lines, with numbers < 0 in range' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -204,7 +204,7 @@ describe "amend-line" do
@t.process_command 'amend-line 2..-2 puts :bong', eval_str @t.process_command 'amend-line 2..-2 puts :bong', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bong puts :bong
puts :heart puts :heart
@ -212,7 +212,7 @@ describe "amend-line" do
end end
it 'should correctly insert a line before a specified line using >' do it 'should correctly insert a line before a specified line using >' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -220,7 +220,7 @@ describe "amend-line" do
@t.process_command 'amend-line 2 > puts :inserted', eval_str @t.process_command 'amend-line 2 > puts :inserted', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :inserted puts :inserted
puts :bing puts :bing
@ -229,7 +229,7 @@ describe "amend-line" do
end end
it 'should ignore second value of range with > syntax' do it 'should ignore second value of range with > syntax' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
puts :bang puts :bang
@ -237,7 +237,7 @@ describe "amend-line" do
@t.process_command 'amend-line 2..21 > puts :inserted', eval_str @t.process_command 'amend-line 2..21 > puts :inserted', eval_str
eval_str.should == unindent(<<-STR) eval_str.should == PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :inserted puts :inserted
puts :bing puts :bing
@ -245,4 +245,3 @@ describe "amend-line" do
STR STR
end end
end end

View file

@ -6,7 +6,7 @@ describe "!" do
end end
it 'should correctly clear the input buffer ' do it 'should correctly clear the input buffer ' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
STR STR

View file

@ -25,7 +25,7 @@ describe "cat" do
describe "with --in" do describe "with --in" do
it 'should display the last few expressions with indices' do it 'should display the last few expressions with indices' do
@t.eval('10', '20', 'cat --in').should == unindent(<<-STR) @t.eval('10', '20', 'cat --in').should == PryTestHelpers.unindent(<<-STR)
1: 1:
10 10
2: 2:
@ -52,7 +52,7 @@ describe "cat" do
@t.insert_nil_input # normally happens when a command is executed @t.insert_nil_input # normally happens when a command is executed
@t.eval ':hello' @t.eval ':hello'
@t.eval('cat --in 1..3').should == unindent(<<-EOS) @t.eval('cat --in 1..3').should == PryTestHelpers.unindent(<<-EOS)
1: 1:
10 10
3: 3:
@ -64,9 +64,18 @@ describe "cat" do
# this doesnt work so well on rbx due to differences in backtrace # this doesnt work so well on rbx due to differences in backtrace
# so we currently skip rbx until we figure out a workaround # so we currently skip rbx until we figure out a workaround
describe "with --ex" do describe "with --ex" do
before do
@o = Object.new
# this is to test exception code (cat --ex)
def @o.broken_method
this method is broken
end
end
if !Pry::Helpers::BaseHelpers.rbx? if !Pry::Helpers::BaseHelpers.rbx?
it 'cat --ex should display repl code that generated exception' do it 'cat --ex should display repl code that generated exception' do
@t.eval unindent(<<-EOS) @t.eval PryTestHelpers.unindent(<<-EOS)
begin begin
this raises error this raises error
rescue => e rescue => e
@ -78,7 +87,7 @@ describe "cat" do
it 'cat --ex should correctly display code that generated exception' do it 'cat --ex should correctly display code that generated exception' do
begin begin
broken_method @o.broken_method
rescue => e rescue => e
@t.last_exception = e @t.last_exception = e
end end
@ -89,7 +98,7 @@ describe "cat" do
describe "with --ex N" do describe "with --ex N" do
it 'should cat first level of backtrace when --ex used with no argument ' do it 'should cat first level of backtrace when --ex used with no argument ' do
temp_file do |f| PryTestHelpers.temp_file do |f|
f << "bt number 1" f << "bt number 1"
f.flush f.flush
@t.last_exception = mock_exception("#{f.path}:1", 'x', 'x') @t.last_exception = mock_exception("#{f.path}:1", 'x', 'x')
@ -98,7 +107,7 @@ describe "cat" do
end end
it 'should cat first level of backtrace when --ex 0 used ' do it 'should cat first level of backtrace when --ex 0 used ' do
temp_file do |f| PryTestHelpers.temp_file do |f|
f << "bt number 1" f << "bt number 1"
f.flush f.flush
@t.last_exception = mock_exception("#{f.path}:1", 'x', 'x') @t.last_exception = mock_exception("#{f.path}:1", 'x', 'x')
@ -107,7 +116,7 @@ describe "cat" do
end end
it 'should cat second level of backtrace when --ex 1 used ' do it 'should cat second level of backtrace when --ex 1 used ' do
temp_file do |f| PryTestHelpers.temp_file do |f|
f << "bt number 2" f << "bt number 2"
f.flush f.flush
@t.last_exception = mock_exception('x', "#{f.path}:1", 'x') @t.last_exception = mock_exception('x', "#{f.path}:1", 'x')
@ -116,7 +125,7 @@ describe "cat" do
end end
it 'should cat third level of backtrace when --ex 2 used' do it 'should cat third level of backtrace when --ex 2 used' do
temp_file do |f| PryTestHelpers.temp_file do |f|
f << "bt number 3" f << "bt number 3"
f.flush f.flush
@t.last_exception = mock_exception('x', 'x', "#{f.path}:1") @t.last_exception = mock_exception('x', 'x', "#{f.path}:1")

View file

@ -49,7 +49,7 @@ describe "edit" do
end end
it "should reload the file if it is a ruby file" do it "should reload the file if it is a ruby file" do
temp_file do |tf| PryTestHelpers.temp_file do |tf|
counter = Pad.counter counter = Pad.counter
path = tf.path path = tf.path
@ -60,7 +60,7 @@ describe "edit" do
end end
it "should not reload the file if it is not a ruby file" do it "should not reload the file if it is not a ruby file" do
temp_file('.py') do |tf| PryTestHelpers.temp_file('.py') do |tf|
counter = Pad.counter counter = Pad.counter
path = tf.path path = tf.path
@ -71,7 +71,7 @@ describe "edit" do
end end
it "should not reload a ruby file if -n is given" do it "should not reload a ruby file if -n is given" do
temp_file do |tf| PryTestHelpers.temp_file do |tf|
counter = Pad.counter counter = Pad.counter
path = tf.path path = tf.path
@ -80,7 +80,7 @@ describe "edit" do
end end
it "should reload a non-ruby file if -r is given" do it "should reload a non-ruby file if -r is given" do
temp_file('.pryrc') do |tf| PryTestHelpers.temp_file('.pryrc') do |tf|
counter = Pad.counter counter = Pad.counter
path = tf.path path = tf.path

View file

@ -81,7 +81,7 @@ describe "play" do
pry_tester(@o).process_command 'play -d test_method', @eval_str pry_tester(@o).process_command 'play -d test_method', @eval_str
@eval_str.should == unindent(<<-STR) @eval_str.should == PryTestHelpers.unindent(<<-STR)
@v = 10 @v = 10
@y = 20 @y = 20
STR STR
@ -98,7 +98,7 @@ describe "play" do
pry_tester(@o).process_command 'play -d test_method --lines 2..3', @eval_str pry_tester(@o).process_command 'play -d test_method --lines 2..3', @eval_str
@eval_str.should == unindent(<<-STR) @eval_str.should == PryTestHelpers.unindent(<<-STR)
@v = 10 @v = 10
@y = 20 @y = 20
STR STR
@ -110,13 +110,13 @@ describe "play" do
end end
it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
@eval_str = unindent(<<-STR) @eval_str = PryTestHelpers.unindent(<<-STR)
def another_test_method def another_test_method
STR STR
pry_tester(@o).process_command 'play -m test_method --lines 2', @eval_str pry_tester(@o).process_command 'play -m test_method --lines 2', @eval_str
@eval_str.should == unindent(<<-STR) @eval_str.should == PryTestHelpers.unindent(<<-STR)
def another_test_method def another_test_method
:test_method_content :test_method_content
STR STR
@ -132,7 +132,7 @@ describe "play" do
pry_tester(@o).process_command 'play -m test_method --lines 3..4', @eval_str pry_tester(@o).process_command 'play -m test_method --lines 3..4', @eval_str
@eval_str.should == unindent(<<-STR, 2) @eval_str.should == PryTestHelpers.unindent(<<-STR, 2)
@var1 = 20 @var1 = 20
@var2 = 30 @var2 = 30
STR STR

View file

@ -13,7 +13,7 @@ describe "save-file" do
describe "-f" do describe "-f" do
it 'should save a file to a file' do it 'should save a file to a file' do
temp_file do |f| PryTestHelpers.temp_file do |f|
path = f.path path = f.path
f.puts ":cute_horse" f.puts ":cute_horse"
f.flush f.flush
@ -163,4 +163,3 @@ describe "save-file" do
end end
end end
end end

View file

@ -1,21 +1,27 @@
require 'helper' require 'helper'
require "fixtures/show_source_doc_examples"
if !mri18_and_no_real_source_location? if !PryTestHelpers.mri18_and_no_real_source_location?
describe "show-doc" do describe "show-doc" do
before do before do
@o = Object.new @o = Object.new
# sample doc
def @o.sample_method
:sample
end
end end
it 'should output a method\'s documentation' do it 'should output a method\'s documentation' do
pry_eval("show-doc sample_method").should =~ /sample doc/ pry_eval(binding, "show-doc @o.sample_method").should =~ /sample doc/
end end
it 'should output a method\'s documentation with line numbers' do it 'should output a method\'s documentation with line numbers' do
pry_eval("show-doc sample_method -l").should =~ /\d: sample doc/ pry_eval(binding, "show-doc @o.sample_method -l").should =~ /\d: sample doc/
end end
it 'should output a method\'s documentation with line numbers (base one)' do it 'should output a method\'s documentation with line numbers (base one)' do
pry_eval("show-doc sample_method -b").should =~ /1: sample doc/ pry_eval(binding, "show-doc @o.sample_method -b").should =~ /1: sample doc/
end end
it 'should output a method\'s documentation if inside method without needing to use method name' do it 'should output a method\'s documentation if inside method without needing to use method name' do
@ -203,7 +209,7 @@ if !mri18_and_no_real_source_location?
end end
it 'should lookup module name with respect to current context' do it 'should lookup module name with respect to current context' do
constant_scope(:AlphaClass, :BetaClass) do PryTestHelpers.constant_scope(:AlphaClass, :BetaClass) do
# top-level beta # top-level beta
class BetaClass class BetaClass
def alpha def alpha
@ -223,7 +229,7 @@ if !mri18_and_no_real_source_location?
end end
it 'should look up nested modules' do it 'should look up nested modules' do
constant_scope(:AlphaClass) do PryTestHelpers.constant_scope(:AlphaClass) do
class AlphaClass class AlphaClass
# nested beta # nested beta
class BetaClass class BetaClass

View file

@ -6,7 +6,7 @@ describe "show-input" do
end end
it 'should correctly show the current lines in the input buffer' do it 'should correctly show the current lines in the input buffer' do
eval_str = unindent(<<-STR) eval_str = PryTestHelpers.unindent(<<-STR)
def hello def hello
puts :bing puts :bing
STR STR

View file

@ -1,10 +1,15 @@
require 'helper' require 'helper'
require "fixtures/show_source_doc_examples"
if !mri18_and_no_real_source_location? if !PryTestHelpers.mri18_and_no_real_source_location?
describe "show-source" do describe "show-source" do
before do before do
@str_output = StringIO.new @str_output = StringIO.new
@o = Object.new @o = Object.new
def @o.sample_method
:sample
end
Object.const_set(:Test, Module.new) Object.const_set(:Test, Module.new)
end end
@ -13,7 +18,7 @@ if !mri18_and_no_real_source_location?
end end
it "should output a method's source" do it "should output a method's source" do
pry_eval('show-source sample_method').should =~ /def sample/ pry_eval(binding, 'show-source @o.sample_method').should =~ /def @o.sample/
end end
it "should output help" do it "should output help" do
@ -21,11 +26,11 @@ if !mri18_and_no_real_source_location?
end end
it "should output a method's source with line numbers" do it "should output a method's source with line numbers" do
pry_eval('show-source -l sample_method').should =~ /\d+: def sample/ pry_eval(binding, 'show-source -l @o.sample_method').should =~ /\d+: def @o.sample/
end end
it "should output a method's source with line numbers starting at 1" do it "should output a method's source with line numbers starting at 1" do
pry_eval('show-source -b sample_method').should =~ /1: def sample/ pry_eval(binding, 'show-source -b @o.sample_method').should =~ /1: def @o.sample/
end end
it "should output a method's source if inside method and no name given" do it "should output a method's source if inside method and no name given" do
@ -196,7 +201,7 @@ if !mri18_and_no_real_source_location?
describe "on variables that shadow methods" do describe "on variables that shadow methods" do
before do before do
@t = pry_tester.eval unindent(<<-EOS) @t = pry_tester.eval PryTestHelpers.unindent(<<-EOS)
class ::TestHost class ::TestHost
def hello def hello
hello = proc { ' smile ' } hello = proc { ' smile ' }
@ -334,7 +339,7 @@ if !mri18_and_no_real_source_location?
if !Pry::Helpers::BaseHelpers.mri_18? if !Pry::Helpers::BaseHelpers.mri_18?
before do before do
pry_eval unindent(<<-EOS) pry_eval PryTestHelpers.unindent(<<-EOS)
class Dog class Dog
def woof def woof
end end
@ -362,8 +367,9 @@ if !mri18_and_no_real_source_location?
end end
end end
it 'should lookup module name with respect to current context' do it 'should lookup module name with respect to current context' do
constant_scope(:AlphaClass, :BetaClass) do
PryTestHelpers.constant_scope(:AlphaClass, :BetaClass) do
class BetaClass class BetaClass
def alpha def alpha
end end
@ -381,7 +387,7 @@ if !mri18_and_no_real_source_location?
end end
it 'should lookup nested modules' do it 'should lookup nested modules' do
constant_scope(:AlphaClass) do PryTestHelpers.constant_scope(:AlphaClass) do
class AlphaClass class AlphaClass
class BetaClass class BetaClass
def beta def beta

View file

@ -0,0 +1,15 @@
# used by test_show_source.rb and test_documentation.rb
class TestClassForShowSource
def alpha
end
end
class TestClassForShowSourceClassEval
def alpha
end
end
class TestClassForShowSourceInstanceEval
def alpha
end
end

55
spec/helper.rb Normal file
View file

@ -0,0 +1,55 @@
unless Object.const_defined? 'Pry'
$:.unshift File.expand_path '../../lib', __FILE__
require 'pry'
end
require File.join(File.expand_path(File.dirname(__FILE__)), '../lib/pry/test/helper')
class Module
public :remove_const
public :remove_method
end
# turn warnings off (esp for Pry::Hooks which will generate warnings
# in tests)
$VERBOSE = nil
# Set I/O streams.
#
# Out defaults to an anonymous StringIO.
def redirect_pry_io(new_in, new_out = StringIO.new)
old_in = Pry.input
old_out = Pry.output
Pry.input = new_in
Pry.output = new_out
begin
yield
ensure
Pry.input = old_in
Pry.output = old_out
end
end
class InputTester
def initialize(*actions)
@orig_actions = actions.dup
@actions = actions
end
def readline(*)
@actions.shift
end
def rewind
@actions = @orig_actions.dup
end
end
# to help with tracking down bugs that cause an infinite loop in the test suite
if ENV["SET_TRACE_FUNC"]
require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
set_trace_func proc { |event, file, line, id, binding, classname|
STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
end

View file

@ -40,7 +40,7 @@ describe "test Pry defaults" do
end end
end.new end.new
Pry.start(self, :input => arity_one_input, :output => Pry::NullOutput) Pry.start(self, :input => arity_one_input, :output => StringIO.new)
arity_one_input.prompt.should == Pry.prompt.call arity_one_input.prompt.should == Pry.prompt.call
end end
@ -53,7 +53,7 @@ describe "test Pry defaults" do
end end
end.new end.new
lambda { Pry.start(self, :input => arity_zero_input, :output => Pry::NullOutput) }.should.not.raise Exception lambda { Pry.start(self, :input => arity_zero_input, :output => StringIO.new) }.should.not.raise Exception
end end
it 'should not pass in the prompt if the arity is -1' do it 'should not pass in the prompt if the arity is -1' do
@ -68,7 +68,7 @@ describe "test Pry defaults" do
end end
end.new end.new
Pry.start(self, :input => arity_multi_input, :output => Pry::NullOutput) Pry.start(self, :input => arity_multi_input, :output => StringIO.new)
arity_multi_input.prompt.should == nil arity_multi_input.prompt.should == nil
end end
@ -112,23 +112,23 @@ describe "test Pry defaults" do
describe "pry return values" do describe "pry return values" do
it 'should return nil' do it 'should return nil' do
Pry.start(self, :input => StringIO.new("exit-all"), :output => Pry::NullOutput).should == nil Pry.start(self, :input => StringIO.new("exit-all"), :output => StringIO.new).should == nil
end end
it 'should return the parameter given to exit-all' do it 'should return the parameter given to exit-all' do
Pry.start(self, :input => StringIO.new("exit-all 10"), :output => Pry::NullOutput).should == 10 Pry.start(self, :input => StringIO.new("exit-all 10"), :output => StringIO.new).should == 10
end end
it 'should return the parameter (multi word string) given to exit-all' do it 'should return the parameter (multi word string) given to exit-all' do
Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => Pry::NullOutput).should == "john mair" Pry.start(self, :input => StringIO.new("exit-all \"john mair\""), :output => StringIO.new).should == "john mair"
end end
it 'should return the parameter (function call) given to exit-all' do it 'should return the parameter (function call) given to exit-all' do
Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => Pry::NullOutput).should == 'cba' Pry.start(self, :input => StringIO.new("exit-all 'abc'.reverse"), :output => StringIO.new).should == 'cba'
end end
it 'should return the parameter (self) given to exit-all' do it 'should return the parameter (self) given to exit-all' do
Pry.start("carl", :input => StringIO.new("exit-all self"), :output => Pry::NullOutput).should == "carl" Pry.start("carl", :input => StringIO.new("exit-all self"), :output => StringIO.new).should == "carl"
end end
end end

View file

@ -107,7 +107,7 @@ describe Pry do
input = InputTester.new(input_string) input = InputTester.new(input_string)
o = Object.new o = Object.new
pry_tester = Pry.new(:input => input, :output => Pry::NullOutput) pry_tester = Pry.new(:input => input, :output => StringIO.new)
pry_tester.rep(o) pry_tester.rep(o)
o.instance_variable_get(:@x).should == 10 o.instance_variable_get(:@x).should == 10
end end
@ -136,7 +136,7 @@ describe Pry do
end end
it 'should define a nested class under Hello and not on top-level or Pry' do it 'should define a nested class under Hello and not on top-level or Pry' do
pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => Pry::NullOutput) pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => StringIO.new)
pry_tester.rep(Hello) pry_tester.rep(Hello)
Hello.const_defined?(:Nested).should == true Hello.const_defined?(:Nested).should == true
end end
@ -204,7 +204,7 @@ describe Pry do
o = Object.new o = Object.new
pry_tester = Pry.start(o, :input => input, :output => Pry::NullOutput) pry_tester = Pry.start(o, :input => input, :output => StringIO.new)
o.instance_variable_get(:@x).should == 10 o.instance_variable_get(:@x).should == 10
end end
@ -223,7 +223,7 @@ describe Pry do
it 'sets _ to the last result' do it 'sets _ to the last result' do
res = [] res = []
input = InputTester.new *[":foo", "self << _", "42", "self << _"] input = InputTester.new *[":foo", "self << _", "42", "self << _"]
pry = Pry.new(:input => input, :output => Pry::NullOutput) pry = Pry.new(:input => input, :output => StringIO.new)
pry.repl(res) pry.repl(res)
res.should == [:foo, 42] res.should == [:foo, 42]
@ -232,7 +232,7 @@ describe Pry do
it 'sets out to an array with the result' do it 'sets out to an array with the result' do
res = {} res = {}
input = InputTester.new *[":foo", "42", "self[:res] = _out_"] input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
pry = Pry.new(:input => input, :output => Pry::NullOutput) pry = Pry.new(:input => input, :output => StringIO.new)
pry.repl(res) pry.repl(res)
res[:res].should.be.kind_of Pry::HistoryArray res[:res].should.be.kind_of Pry::HistoryArray
@ -242,7 +242,7 @@ describe Pry do
it 'sets _in_ to an array with the entered lines' do it 'sets _in_ to an array with the entered lines' do
res = {} res = {}
input = InputTester.new *[":foo", "42", "self[:res] = _in_"] input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
pry = Pry.new(:input => input, :output => Pry::NullOutput) pry = Pry.new(:input => input, :output => StringIO.new)
pry.repl(res) pry.repl(res)
res[:res].should.be.kind_of Pry::HistoryArray res[:res].should.be.kind_of Pry::HistoryArray
@ -252,7 +252,7 @@ describe Pry do
it 'uses 100 as the size of _in_ and _out_' do it 'uses 100 as the size of _in_ and _out_' do
res = [] res = []
input = InputTester.new *["self << _out_.max_size << _in_.max_size"] input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
pry = Pry.new(:input => input, :output => Pry::NullOutput) pry = Pry.new(:input => input, :output => StringIO.new)
pry.repl(res) pry.repl(res)
res.should == [100, 100] res.should == [100, 100]
@ -261,7 +261,7 @@ describe Pry do
it 'can change the size of the history arrays' do it 'can change the size of the history arrays' do
res = [] res = []
input = InputTester.new *["self << _out_.max_size << _in_.max_size"] input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
pry = Pry.new(:input => input, :output => Pry::NullOutput, pry = Pry.new(:input => input, :output => StringIO.new,
:memory_size => 1000) :memory_size => 1000)
pry.repl(res) pry.repl(res)
@ -271,7 +271,7 @@ describe Pry do
it 'store exceptions' do it 'store exceptions' do
res = [] res = []
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"] input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
pry = Pry.new(:input => input, :output => Pry::NullOutput, pry = Pry.new(:input => input, :output => StringIO.new,
:memory_size => 1000) :memory_size => 1000)
pry.repl(res) pry.repl(res)
@ -322,10 +322,10 @@ describe Pry do
it "should never run the rc file twice" do it "should never run the rc file twice" do
Pry.config.should_load_rc = true Pry.config.should_load_rc = true
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
TEST_RC.should == [0] TEST_RC.should == [0]
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
TEST_RC.should == [0] TEST_RC.should == [0]
end end
@ -334,7 +334,7 @@ describe Pry do
old_rc = Pry.config.should_load_rc old_rc = Pry.config.should_load_rc
ENV['HOME'] = nil ENV['HOME'] = nil
Pry.config.should_load_rc = true Pry.config.should_load_rc = true
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new) }.should.not.raise
ENV['HOME'] = old_home ENV['HOME'] = old_home
Pry.config.should_load_rc = old_rc Pry.config.should_load_rc = old_rc
@ -342,13 +342,13 @@ describe Pry do
it "should not run the rc file at all if Pry.config.should_load_rc is false" do it "should not run the rc file at all if Pry.config.should_load_rc is false" do
Pry.config.should_load_rc = false Pry.config.should_load_rc = false
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) Pry.start(self, :input => StringIO.new("exit-all\n"), :output => StringIO.new)
Object.const_defined?(:TEST_RC).should == false Object.const_defined?(:TEST_RC).should == false
end end
it "should not load the rc file if #repl method invoked" do it "should not load the rc file if #repl method invoked" do
Pry.config.should_load_rc = true Pry.config.should_load_rc = true
Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self) Pry.new(:input => StringIO.new("exit-all\n"), :output => StringIO.new).repl(self)
Object.const_defined?(:TEST_RC).should == false Object.const_defined?(:TEST_RC).should == false
Pry.config.should_load_rc = false Pry.config.should_load_rc = false
end end
@ -368,7 +368,7 @@ describe Pry do
} }
@doing_it = lambda{ @doing_it = lambda{
Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => Pry::NullOutput) Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => StringIO.new)
putsed putsed
} }
end end