2011-06-09 08:27:04 -04:00
|
|
|
require 'helper'
|
2010-12-21 09:03:52 -05:00
|
|
|
|
|
|
|
describe Pry do
|
2012-06-11 09:36:16 -04:00
|
|
|
before do
|
|
|
|
@str_output = StringIO.new
|
|
|
|
end
|
2011-06-05 18:41:59 -04:00
|
|
|
|
2011-07-25 09:07:10 -04:00
|
|
|
if RUBY_VERSION =~ /1.9/
|
|
|
|
describe "Exotic object support" do
|
|
|
|
# regression test for exotic object support
|
|
|
|
it "Should not error when return value is a BasicObject instance" do
|
|
|
|
|
|
|
|
lambda do
|
|
|
|
redirect_pry_io(InputTester.new("BasicObject.new", "exit-all"), StringIO.new) do
|
|
|
|
Pry.start
|
|
|
|
end
|
|
|
|
end.should.not.raise NoMethodError
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-24 09:11:40 -04:00
|
|
|
describe "Pry.binding_for" do
|
|
|
|
|
|
|
|
# regression test for burg's bug (see git history)
|
|
|
|
it "Should not error when object doesn't have a valid == method" do
|
|
|
|
o = Object.new
|
|
|
|
def o.==(other)
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
lambda { Pry.binding_for(o) }.should.not.raise Exception
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-21 09:03:52 -05:00
|
|
|
describe "open a Pry session on an object" do
|
|
|
|
describe "rep" do
|
2010-12-24 08:22:08 -05:00
|
|
|
before do
|
|
|
|
class Hello
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.send(:remove_const, :Hello)
|
|
|
|
end
|
|
|
|
|
2011-04-30 06:01:26 -04:00
|
|
|
# bug fix for https://github.com/banister/pry/issues/93
|
|
|
|
it 'should not leak pry constants into Object namespace' do
|
2011-12-31 06:50:04 -05:00
|
|
|
input_string = "Command"
|
2011-04-30 06:01:26 -04:00
|
|
|
o = Object.new
|
|
|
|
pry_tester = Pry.new(:input => StringIO.new(input_string),
|
2012-06-11 09:36:16 -04:00
|
|
|
:output => @str_output,
|
2011-09-10 12:41:05 -04:00
|
|
|
:exception_handler => proc { |_, exception, _pry_| @excep = exception },
|
2011-04-30 06:01:26 -04:00
|
|
|
:print => proc {}
|
|
|
|
).rep(o)
|
|
|
|
|
|
|
|
@excep.is_a?(NameError).should == true
|
|
|
|
end
|
|
|
|
|
2011-06-11 07:37:53 -04:00
|
|
|
if defined?(BasicObject)
|
|
|
|
it 'should be able to operate inside the BasicObject class' do
|
2012-07-11 14:34:44 -04:00
|
|
|
redirect_pry_io(InputTester.new(":foo", "Pad.obj = _", "exit-all")) do
|
2011-06-11 07:37:53 -04:00
|
|
|
BasicObject.pry
|
|
|
|
end
|
2012-07-11 14:34:44 -04:00
|
|
|
|
|
|
|
Pad.obj.should == :foo
|
2011-06-11 07:37:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-21 09:03:52 -05:00
|
|
|
it 'should set an ivar on an object' do
|
|
|
|
input_string = "@x = 10"
|
|
|
|
input = InputTester.new(input_string)
|
|
|
|
o = Object.new
|
|
|
|
|
2011-01-10 01:29:26 -05:00
|
|
|
pry_tester = Pry.new(:input => input, :output => Pry::NullOutput)
|
2010-12-21 09:03:52 -05:00
|
|
|
pry_tester.rep(o)
|
|
|
|
o.instance_variable_get(:@x).should == 10
|
|
|
|
end
|
|
|
|
|
2011-09-15 11:17:24 -04:00
|
|
|
it 'should display error and throw(:breakout) if Pry instance runs out of input' do
|
|
|
|
catch(:breakout) do
|
2012-06-11 09:36:16 -04:00
|
|
|
redirect_pry_io(StringIO.new(":nothing\n"), @str_output) do
|
2011-09-15 11:17:24 -04:00
|
|
|
Pry.new.repl
|
|
|
|
end
|
2011-09-04 09:50:27 -04:00
|
|
|
end
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should =~ /Error: Pry ran out of things to read/
|
2011-09-04 09:50:27 -04:00
|
|
|
end
|
|
|
|
|
2010-12-21 09:03:52 -05:00
|
|
|
it 'should make self evaluate to the receiver of the rep session' do
|
2011-06-16 11:01:04 -04:00
|
|
|
o = :john
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("self"), :output => @str_output)
|
2010-12-21 09:03:52 -05:00
|
|
|
pry_tester.rep(o)
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should =~ /:john/
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
2010-12-24 08:22:08 -05:00
|
|
|
|
|
|
|
it 'should work with multi-line input' do
|
2011-01-04 22:23:11 -05:00
|
|
|
o = Object.new
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("x = ", "1 + 4"), :output => @str_output)
|
2011-01-04 22:23:11 -05:00
|
|
|
pry_tester.rep(o)
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should =~ /5/
|
2010-12-24 08:22:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define a nested class under Hello and not on top-level or Pry' do
|
2011-01-10 01:29:26 -05:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("class Nested", "end"), :output => Pry::NullOutput)
|
2010-12-24 08:22:08 -05:00
|
|
|
pry_tester.rep(Hello)
|
2010-12-24 22:21:16 -05:00
|
|
|
Hello.const_defined?(:Nested).should == true
|
2010-12-24 08:22:08 -05:00
|
|
|
end
|
2011-04-16 00:47:48 -04:00
|
|
|
|
2011-04-17 03:26:05 -04:00
|
|
|
it 'should suppress output if input ends in a ";" and is an Exception object (single line)' do
|
|
|
|
o = Object.new
|
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("Exception.new;"), :output => @str_output)
|
2011-04-17 03:26:05 -04:00
|
|
|
pry_tester.rep(o)
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should == ""
|
2011-04-17 03:26:05 -04:00
|
|
|
end
|
|
|
|
|
2011-04-16 00:47:48 -04:00
|
|
|
it 'should suppress output if input ends in a ";" (single line)' do
|
|
|
|
o = Object.new
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("x = 5;"), :output => @str_output)
|
2011-04-16 00:47:48 -04:00
|
|
|
pry_tester.rep(o)
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should == ""
|
2011-04-16 00:47:48 -04:00
|
|
|
end
|
2011-04-24 10:25:07 -04:00
|
|
|
|
2011-04-16 00:47:48 -04:00
|
|
|
it 'should suppress output if input ends in a ";" (multi-line)' do
|
|
|
|
o = Object.new
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("def self.blah", ":test", "end;"), :output => @str_output)
|
2011-04-16 00:47:48 -04:00
|
|
|
pry_tester.rep(o)
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should == ""
|
2011-04-16 00:47:48 -04:00
|
|
|
end
|
2011-04-16 17:17:30 -04:00
|
|
|
|
|
|
|
it 'should be able to evaluate exceptions normally' do
|
|
|
|
o = Exception.new
|
|
|
|
|
|
|
|
was_called = false
|
2011-04-18 00:48:35 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("self"),
|
2012-06-11 09:36:16 -04:00
|
|
|
:output => @str_output,
|
2011-04-18 00:48:35 -04:00
|
|
|
:exception_handler => proc { was_called = true })
|
2011-04-16 17:17:30 -04:00
|
|
|
|
|
|
|
pry_tester.rep(o)
|
|
|
|
was_called.should == false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should notice when exceptions are raised' do
|
|
|
|
o = Exception.new
|
|
|
|
|
|
|
|
was_called = false
|
2011-04-18 00:48:35 -04:00
|
|
|
pry_tester = Pry.new(:input => InputTester.new("raise self"),
|
2012-06-11 09:36:16 -04:00
|
|
|
:output => @str_output,
|
2011-04-18 00:48:35 -04:00
|
|
|
:exception_handler => proc { was_called = true })
|
2011-04-16 17:17:30 -04:00
|
|
|
|
|
|
|
pry_tester.rep(o)
|
|
|
|
was_called.should == true
|
|
|
|
end
|
2011-08-26 20:44:13 -04:00
|
|
|
|
|
|
|
it 'should not try to catch intended exceptions' do
|
|
|
|
lambda { mock_pry("raise SystemExit") }.should.raise SystemExit
|
|
|
|
# SIGTERM
|
|
|
|
lambda { mock_pry("raise SignalException.new(15)") }.should.raise SignalException
|
|
|
|
end
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "repl" do
|
2010-12-24 03:30:51 -05:00
|
|
|
describe "basic functionality" do
|
|
|
|
it 'should set an ivar on an object and exit the repl' do
|
2011-08-25 05:41:43 -04:00
|
|
|
input_strings = ["@x = 10", "exit-all"]
|
2010-12-24 03:30:51 -05:00
|
|
|
input = InputTester.new(*input_strings)
|
|
|
|
|
|
|
|
o = Object.new
|
|
|
|
|
2011-01-10 01:29:26 -05:00
|
|
|
pry_tester = Pry.start(o, :input => input, :output => Pry::NullOutput)
|
2010-12-24 03:30:51 -05:00
|
|
|
|
|
|
|
o.instance_variable_get(:@x).should == 10
|
2011-01-04 22:23:11 -05:00
|
|
|
end
|
2010-12-24 03:30:51 -05:00
|
|
|
end
|
|
|
|
|
2011-12-03 23:47:26 -05:00
|
|
|
describe "complete_expression?" do
|
2011-10-12 02:19:37 -04:00
|
|
|
it "should not mutate the input!" do
|
|
|
|
clean = "puts <<-FOO\nhi\nFOO\n"
|
|
|
|
a = clean.dup
|
2012-04-10 09:39:29 -04:00
|
|
|
Pry::Code.complete_expression?(a)
|
2011-10-12 02:19:37 -04:00
|
|
|
a.should == clean
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-06 11:14:29 -04:00
|
|
|
describe "history arrays" do
|
|
|
|
it 'sets _ to the last result' do
|
|
|
|
res = []
|
|
|
|
input = InputTester.new *[":foo", "self << _", "42", "self << _"]
|
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res.should == [:foo, 42]
|
|
|
|
end
|
|
|
|
|
2011-06-07 08:57:01 -04:00
|
|
|
it 'sets out to an array with the result' do
|
2011-06-06 11:14:29 -04:00
|
|
|
res = {}
|
2011-09-01 00:58:38 -04:00
|
|
|
input = InputTester.new *[":foo", "42", "self[:res] = _out_"]
|
2011-06-06 11:14:29 -04:00
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res[:res].should.be.kind_of Pry::HistoryArray
|
|
|
|
res[:res][1..2].should == [:foo, 42]
|
|
|
|
end
|
|
|
|
|
2011-09-01 00:58:38 -04:00
|
|
|
it 'sets _in_ to an array with the entered lines' do
|
2011-06-06 11:14:29 -04:00
|
|
|
res = {}
|
2011-09-01 00:58:38 -04:00
|
|
|
input = InputTester.new *[":foo", "42", "self[:res] = _in_"]
|
2011-06-06 11:14:29 -04:00
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res[:res].should.be.kind_of Pry::HistoryArray
|
|
|
|
res[:res][1..2].should == [":foo\n", "42\n"]
|
|
|
|
end
|
|
|
|
|
2011-09-01 00:58:38 -04:00
|
|
|
it 'uses 100 as the size of _in_ and _out_' do
|
2011-06-06 11:14:29 -04:00
|
|
|
res = []
|
2011-09-01 00:58:38 -04:00
|
|
|
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
2011-06-06 11:14:29 -04:00
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res.should == [100, 100]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can change the size of the history arrays' do
|
|
|
|
res = []
|
2011-09-01 00:58:38 -04:00
|
|
|
input = InputTester.new *["self << _out_.max_size << _in_.max_size"]
|
2011-06-06 11:14:29 -04:00
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
|
|
|
:memory_size => 1000)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res.should == [1000, 1000]
|
|
|
|
end
|
2011-06-08 05:36:49 -04:00
|
|
|
|
|
|
|
it 'store exceptions' do
|
|
|
|
res = []
|
2011-09-01 00:58:38 -04:00
|
|
|
input = InputTester.new *["foo!","self << _in_[-1] << _out_[-1]"]
|
2011-06-08 05:36:49 -04:00
|
|
|
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
|
|
|
:memory_size => 1000)
|
|
|
|
pry.repl(res)
|
|
|
|
|
|
|
|
res.first.should == "foo!\n"
|
|
|
|
res.last.should.be.kind_of NoMethodError
|
|
|
|
end
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
|
|
|
|
2012-01-13 02:43:06 -05:00
|
|
|
describe "last_result" do
|
|
|
|
it "should be set to the most recent value" do
|
|
|
|
mock_pry("2", "_ + 82").should =~ /84/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be set to the result of a command with :keep_retval" do
|
|
|
|
mock_pry("Pry::Commands.block_command '++', '', {:keep_retval => true} do |a| a.to_i + 1; end", '++ 86', '++ #{_}').should =~ /88/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be preserved over an empty line" do
|
|
|
|
mock_pry("2 + 2", " ", "\t", " ", "_ + 92").should =~ /96/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be preserved when evalling a command without :keep_retval" do
|
|
|
|
mock_pry("2 + 2", "ls -l", "_ + 96").should =~ /100/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-05 09:17:54 -05:00
|
|
|
describe "test loading rc files" do
|
2011-05-28 09:38:00 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
Pry.instance_variable_set(:@initial_session, true)
|
|
|
|
end
|
|
|
|
|
2011-03-05 09:17:54 -05:00
|
|
|
after do
|
|
|
|
Pry::RC_FILES.clear
|
2011-05-28 09:38:00 -04:00
|
|
|
Pry.config.should_load_rc = false
|
2011-03-05 09:17:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should run the rc file only once" do
|
2011-05-28 09:38:00 -04:00
|
|
|
Pry.config.should_load_rc = true
|
2011-10-18 13:35:09 -04:00
|
|
|
2.times { Pry::RC_FILES << File.expand_path("../testrc", __FILE__) }
|
2011-03-05 09:17:54 -05:00
|
|
|
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
2011-03-05 09:17:54 -05:00
|
|
|
TEST_RC.should == [0]
|
|
|
|
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
2011-03-05 09:17:54 -05:00
|
|
|
TEST_RC.should == [0]
|
|
|
|
|
|
|
|
Object.remove_const(:TEST_RC)
|
|
|
|
end
|
|
|
|
|
2012-02-15 06:24:03 -05:00
|
|
|
it "should not load the pryrc if it cannot expand ENV[HOME]" do
|
|
|
|
old_home = ENV['HOME']
|
|
|
|
old_rc = Pry.config.should_load_rc
|
|
|
|
ENV['HOME'] = nil
|
|
|
|
Pry.config.should_load_rc = true
|
|
|
|
lambda { Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput) }.should.not.raise
|
|
|
|
|
|
|
|
ENV['HOME'] = old_home
|
|
|
|
Pry.config.should_load_rc = old_rc
|
|
|
|
end
|
|
|
|
|
2011-05-28 09:38:00 -04:00
|
|
|
it "should not run the rc file at all if Pry.config.should_load_rc is false" do
|
|
|
|
Pry.config.should_load_rc = false
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.start(self, :input => StringIO.new("exit-all\n"), :output => Pry::NullOutput)
|
2011-03-05 09:17:54 -05:00
|
|
|
Object.const_defined?(:TEST_RC).should == false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not load the rc file if #repl method invoked" do
|
2011-05-28 09:38:00 -04:00
|
|
|
Pry.config.should_load_rc = true
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.new(:input => StringIO.new("exit-all\n"), :output => Pry::NullOutput).repl(self)
|
2011-03-05 09:17:54 -05:00
|
|
|
Object.const_defined?(:TEST_RC).should == false
|
2011-05-28 09:38:00 -04:00
|
|
|
Pry.config.should_load_rc = false
|
2011-03-05 09:17:54 -05:00
|
|
|
end
|
2011-11-02 03:45:54 -04:00
|
|
|
|
|
|
|
describe "that raise exceptions" do
|
|
|
|
before do
|
|
|
|
Pry::RC_FILES << File.expand_path("../testrcbad", __FILE__)
|
|
|
|
Pry.config.should_load_rc = true
|
|
|
|
|
|
|
|
putsed = nil
|
|
|
|
|
|
|
|
# YUCK! horrible hack to get round the fact that output is not configured
|
|
|
|
# at the point this message is printed.
|
|
|
|
(class << Pry; self; end).send(:define_method, :puts) { |str|
|
|
|
|
putsed = str
|
|
|
|
}
|
|
|
|
|
|
|
|
@doing_it = lambda{
|
|
|
|
Pry.start(self, :input => StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), :output => Pry::NullOutput)
|
|
|
|
putsed
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.remove_const(:TEST_BEFORE_RAISE)
|
|
|
|
Object.remove_const(:TEST_AFTER_RAISE)
|
|
|
|
(class << Pry; undef_method :puts; end)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not raise exceptions" do
|
|
|
|
@doing_it.should.not.raise
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should continue to run pry" do
|
|
|
|
@doing_it[]
|
|
|
|
Object.const_defined?(:TEST_BEFORE_RAISE).should == true
|
|
|
|
Object.const_defined?(:TEST_AFTER_RAISE).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should output an error" do
|
|
|
|
@doing_it[].should =~ /Error loading #{File.expand_path("../testrcbad", __FILE__)}: messin with ya/
|
|
|
|
end
|
|
|
|
end
|
2011-03-05 09:17:54 -05:00
|
|
|
end
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
describe "nesting" do
|
2011-01-10 01:29:26 -05:00
|
|
|
after do
|
|
|
|
Pry.reset_defaults
|
2011-03-05 09:17:54 -05:00
|
|
|
Pry.color = false
|
2011-01-10 01:29:26 -05:00
|
|
|
end
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
it 'should nest properly' do
|
2011-08-21 22:57:59 -04:00
|
|
|
Pry.input = InputTester.new("cd 1", "cd 2", "cd 3", "\"nest:\#\{(_pry_.binding_stack.size - 1)\}\"", "exit-all")
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2012-06-11 09:36:16 -04:00
|
|
|
Pry.output = @str_output
|
2010-12-24 03:30:51 -05:00
|
|
|
|
|
|
|
o = Object.new
|
|
|
|
|
2011-01-09 06:51:45 -05:00
|
|
|
pry_tester = o.pry
|
2012-06-11 09:36:16 -04:00
|
|
|
@str_output.string.should =~ /nest:3/
|
2010-12-24 03:30:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-23 09:03:39 -05:00
|
|
|
describe "defining methods" do
|
|
|
|
it 'should define a method on the singleton class of an object when performing "def meth;end" inside the object' do
|
|
|
|
[Object.new, {}, []].each do |val|
|
|
|
|
str_input = StringIO.new("def hello;end")
|
|
|
|
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2011-01-23 09:03:39 -05:00
|
|
|
val.methods(false).map(&:to_sym).include?(:hello).should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define an instance method on the module when performing "def meth;end" inside the module' do
|
|
|
|
str_input = StringIO.new("def hello;end")
|
|
|
|
hello = Module.new
|
|
|
|
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
|
|
|
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define an instance method on the class when performing "def meth;end" inside the class' do
|
|
|
|
str_input = StringIO.new("def hello;end")
|
|
|
|
hello = Class.new
|
|
|
|
Pry.new(:input => str_input, :output => StringIO.new).rep(hello)
|
|
|
|
hello.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
|
|
|
|
# should include float in here, but test fails for some reason
|
|
|
|
# on 1.8.7, no idea why!
|
|
|
|
[:test, 0, true, false, nil].each do |val|
|
|
|
|
str_input = StringIO.new("def hello;end")
|
|
|
|
Pry.new(:input => str_input, :output => StringIO.new).rep(val)
|
|
|
|
val.class.instance_methods(false).map(&:to_sym).include?(:hello).should == true
|
|
|
|
end
|
|
|
|
end
|
2011-04-16 17:17:30 -04:00
|
|
|
end
|
|
|
|
|
2011-01-09 06:51:45 -05:00
|
|
|
describe "Object#pry" do
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.reset_defaults
|
2011-03-05 09:17:54 -05:00
|
|
|
Pry.color = false
|
2011-01-09 06:51:45 -05:00
|
|
|
end
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2011-01-09 06:51:45 -05:00
|
|
|
it "should start a pry session on the receiver (first form)" do
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.input = InputTester.new("self", "exit-all")
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
str_output = StringIO.new
|
2011-01-10 01:29:26 -05:00
|
|
|
Pry.output = str_output
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
20.pry
|
|
|
|
|
|
|
|
str_output.string.should =~ /20/
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should start a pry session on the receiver (second form)" do
|
2011-08-25 05:41:43 -04:00
|
|
|
Pry.input = InputTester.new("self", "exit-all")
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
str_output = StringIO.new
|
2011-01-10 01:29:26 -05:00
|
|
|
Pry.output = str_output
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
pry 20
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2011-01-09 06:51:45 -05:00
|
|
|
str_output.string.should =~ /20/
|
|
|
|
end
|
|
|
|
|
2012-04-01 05:10:46 -04:00
|
|
|
it "should raise if more than two arguments are passed to Object#pry" do
|
|
|
|
lambda { pry(20, :quiet, :input => Readline) }.should.raise ArgumentError
|
2011-01-09 06:51:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-16 11:27:55 -05:00
|
|
|
describe "Pry.binding_for" do
|
2011-01-09 06:51:45 -05:00
|
|
|
it 'should return TOPLEVEL_BINDING if parameter self is main' do
|
|
|
|
_main_ = lambda { TOPLEVEL_BINDING.eval('self') }
|
2011-02-16 11:27:55 -05:00
|
|
|
Pry.binding_for(_main_.call).is_a?(Binding).should == true
|
|
|
|
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
|
|
|
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
2011-01-09 06:51:45 -05:00
|
|
|
end
|
|
|
|
end
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
2012-01-13 02:48:09 -05:00
|
|
|
end
|
2012-01-02 14:23:22 -05:00
|
|
|
|
2012-01-13 02:48:09 -05:00
|
|
|
describe 'setting custom options' do
|
|
|
|
it 'should not raise for unrecognized options' do
|
|
|
|
should.not.raise?(NoMethodError) {
|
|
|
|
instance = Pry.new(:custom_option => 'custom value')
|
|
|
|
}
|
2012-01-02 14:23:22 -05:00
|
|
|
end
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
2012-01-13 02:48:09 -05:00
|
|
|
end
|