2014-03-14 00:31:24 -04:00
|
|
|
require_relative '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
|
|
|
|
2015-12-27 01:19:04 -05:00
|
|
|
describe ".configure" do
|
2015-12-27 00:38:53 -05:00
|
|
|
it "yields a block with Pry.config as its argument" do
|
2015-12-27 01:19:04 -05:00
|
|
|
Pry.config.foo = nil
|
2015-12-27 00:38:53 -05:00
|
|
|
Pry.configure do |config|
|
|
|
|
config.foo = "bar"
|
|
|
|
end
|
|
|
|
expect(Pry.config.foo).to eq("bar")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "Exotic object support" do
|
|
|
|
# regression test for exotic object support
|
|
|
|
it "Should not error when return value is a BasicObject instance" do
|
|
|
|
ReplTester.start do
|
|
|
|
input('BasicObject.new').should =~ /^=> #<BasicObject:/
|
2011-07-25 09:07:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-31 04:42:55 -04:00
|
|
|
describe 'DISABLE_PRY' do
|
2012-10-31 04:24:06 -04:00
|
|
|
before do
|
2012-10-31 04:42:55 -04:00
|
|
|
ENV['DISABLE_PRY'] = 'true'
|
2012-10-31 04:24:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2012-10-31 04:42:55 -04:00
|
|
|
ENV.delete 'DISABLE_PRY'
|
2012-10-31 04:24:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not binding.pry' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(binding.pry).to eq nil
|
2012-10-31 04:24:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not Pry.start' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry.start).to eq nil
|
2012-10-31 04:24:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-31 16:32:37 -04:00
|
|
|
describe 'FAIL_PRY' do
|
|
|
|
before do
|
|
|
|
ENV['FAIL_PRY'] = 'true'
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
ENV.delete 'FAIL_PRY'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for binding.pry' do
|
|
|
|
expect{binding.pry}.to raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for Pry.start' do
|
|
|
|
expect{Pry.start}.to raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-14 00:59:59 -05:00
|
|
|
describe "Pry.critical_section" do
|
|
|
|
it "should prevent Pry being called" do
|
|
|
|
output = StringIO.new
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.output = output
|
2012-11-14 00:59:59 -05:00
|
|
|
Pry.critical_section do
|
|
|
|
Pry.start
|
|
|
|
end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(output.string).to match(/Pry started inside Pry/)
|
2012-11-14 00:59:59 -05:00
|
|
|
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
|
|
|
|
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { Pry.binding_for(o) }.to_not raise_error
|
2011-07-24 09:11:40 -04:00
|
|
|
end
|
2012-07-22 17:30:05 -04:00
|
|
|
|
|
|
|
it "should not leak local variables" do
|
|
|
|
[Object.new, Array, 3].each do |obj|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry.binding_for(obj).eval("local_variables")).to be_empty
|
2012-07-22 17:30:05 -04:00
|
|
|
end
|
|
|
|
end
|
2013-04-25 04:09:06 -04:00
|
|
|
|
|
|
|
it "should work on frozen objects" do
|
|
|
|
a = "hello".freeze
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry.binding_for(a).eval("self")).to equal(a)
|
2013-04-25 04:09:06 -04:00
|
|
|
end
|
2011-07-24 09:11:40 -04:00
|
|
|
end
|
|
|
|
|
2014-03-09 20:28:12 -04:00
|
|
|
describe "#last_exception=" do
|
|
|
|
before do
|
|
|
|
@pry = Pry.new binding: binding
|
|
|
|
@e = mock_exception "foo.rb:1"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an instance of Pry::LastException" do
|
|
|
|
@pry.last_exception = @e
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@pry.last_exception.wrapped_exception).to eq @e
|
2014-03-09 20:28:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a frozen exception" do
|
|
|
|
@pry.last_exception = @e.freeze
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect(@pry.last_exception).to be_frozen
|
2014-03-09 20:28:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an object who mirrors itself as the wrapped exception" do
|
|
|
|
@pry.last_exception = @e.freeze
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect(@pry.last_exception).to be_an_instance_of StandardError
|
2014-03-09 20:28:12 -04:00
|
|
|
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
|
|
|
|
|
2014-08-10 02:52:24 -04:00
|
|
|
# bug fix for https://github.com/pry/pry/issues/93
|
2011-04-30 06:01:26 -04:00
|
|
|
it 'should not leak pry constants into Object namespace' do
|
2015-06-20 19:56:04 -04:00
|
|
|
expect { pry_eval(Object.new, "Command") }.to raise_error NameError
|
2011-04-30 06:01:26 -04:00
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it 'should be able to operate inside the BasicObject class' do
|
|
|
|
pry_eval(BasicObject, ":foo", "Pad.obj = _")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.obj).to eq :foo
|
2011-06-11 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
2010-12-21 09:03:52 -05:00
|
|
|
it 'should set an ivar on an object' do
|
|
|
|
o = Object.new
|
2012-12-15 18:51:02 -05:00
|
|
|
pry_eval(o, "@x = 10")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(o.instance_variable_get(:@x)).to eq 10
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
|
|
|
|
2012-09-06 02:46:18 -04:00
|
|
|
it 'should display error if Pry instance runs out of input' do
|
|
|
|
redirect_pry_io(StringIO.new, @str_output) do
|
2012-12-20 04:28:04 -05:00
|
|
|
Pry.start
|
2012-09-06 02:46:18 -04:00
|
|
|
end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@str_output.string).to match(/Error: Pry ran out of things to read/)
|
2012-09-06 02:46:18 -04:00
|
|
|
end
|
2011-09-04 09:50:27 -04:00
|
|
|
|
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
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval(o, "self")).to eq o
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
2010-12-24 08:22:08 -05:00
|
|
|
|
|
|
|
it 'should define a nested class under Hello and not on top-level or Pry' do
|
2012-12-18 03:10:52 -05:00
|
|
|
mock_pry(Pry.binding_for(Hello), "class Nested", "end")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Hello.const_defined?(:Nested)).to eq 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
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry("Exception.new;")).to eq ""
|
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
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry("x = 5;")).to eq ""
|
2011-04-16 00:47:48 -04:00
|
|
|
end
|
2011-04-24 10:25:07 -04:00
|
|
|
|
2011-04-16 17:17:30 -04:00
|
|
|
it 'should be able to evaluate exceptions normally' do
|
|
|
|
was_called = false
|
2012-12-18 03:10:52 -05:00
|
|
|
mock_pry("RuntimeError.new", :exception_handler => proc{ was_called = true })
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(was_called).to eq false
|
2011-04-16 17:17:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should notice when exceptions are raised' do
|
|
|
|
was_called = false
|
2012-12-18 03:10:52 -05:00
|
|
|
mock_pry("raise RuntimeError", :exception_handler => proc{ was_called = true })
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(was_called).to eq true
|
2011-04-16 17:17:30 -04:00
|
|
|
end
|
2011-08-26 20:44:13 -04:00
|
|
|
|
|
|
|
it 'should not try to catch intended exceptions' do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { mock_pry("raise SystemExit") }.to raise_error SystemExit
|
2011-08-26 20:44:13 -04:00
|
|
|
# SIGTERM
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { mock_pry("raise SignalException.new(15)") }.to raise_error SignalException
|
2011-08-26 20:44:13 -04:00
|
|
|
end
|
2013-02-01 00:25:22 -05:00
|
|
|
|
|
|
|
describe "multi-line input" do
|
|
|
|
it "works" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('x = ', '1 + 4')).to match(/5/)
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should suppress output if input ends in a ";" (multi-line)' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('def self.blah', ':test', 'end;')).to eq ''
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "newline stripping from an empty string" do
|
|
|
|
it "with double quotes" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('"', '"')).to match(%r|"\\n"|)
|
|
|
|
expect(mock_pry('"', "\n", "\n", "\n", '"')).to match(%r|"\\n\\n\\n\\n"|)
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "with single quotes" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry("'", "'")).to match(%r|"\\n"|)
|
|
|
|
expect(mock_pry("'", "\n", "\n", "\n", "'")).to match(%r|"\\n\\n\\n\\n"|)
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "with fancy delimiters" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('%(', ')')).to match(%r|"\\n"|)
|
|
|
|
expect(mock_pry('%|', "\n", "\n", '|')).to match(%r|"\\n\\n\\n"|)
|
|
|
|
expect(mock_pry('%q[', "\n", "\n", ']')).to match(%r|"\\n\\n\\n"|)
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "newline stripping from an empty regexp" do
|
|
|
|
it "with regular regexp delimiters" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('/', '/')).to match(%r{/\n/})
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "with fancy delimiters" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('%r{', "\n", "\n", '}')).to match(%r{/\n\n\n/})
|
|
|
|
expect(mock_pry('%r<', "\n", '>')).to match(%r{/\n\n/})
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "newline from an empty heredoc" do
|
|
|
|
it "works" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('<<HERE', 'HERE')).to match(%r|""|)
|
|
|
|
expect(mock_pry("<<'HERE'", "\n", 'HERE')).to match(%r|"\\n"|)
|
|
|
|
expect(mock_pry("<<-'HERE'", "\n", "\n", 'HERE')).to match(%r|"\\n\\n"|)
|
2013-02-01 00:25:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2015-01-22 16:52:20 -05:00
|
|
|
Pry.start(o, :input => input, :output => StringIO.new)
|
2010-12-24 03:30:51 -05:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(o.instance_variable_get(:@x)).to eq 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)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(a).to eq clean
|
2011-10-12 02:19:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-06 11:14:29 -04:00
|
|
|
describe "history arrays" do
|
|
|
|
it 'sets _ to the last result' do
|
2012-12-20 04:28:04 -05:00
|
|
|
t = pry_tester
|
|
|
|
t.eval ":foo"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("_")).to eq :foo
|
2012-12-20 04:28:04 -05:00
|
|
|
t.eval "42"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(t.eval("_")).to eq 42
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
|
|
|
|
2011-06-07 08:57:01 -04:00
|
|
|
it 'sets out to an array with the result' do
|
2012-12-20 04:28:04 -05:00
|
|
|
t = pry_tester
|
|
|
|
t.eval ":foo"
|
|
|
|
t.eval "42"
|
|
|
|
res = t.eval "_out_"
|
2011-06-06 11:14:29 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(res).to be_a_kind_of Pry::HistoryArray
|
|
|
|
expect(res[1..2]).to eq [:foo, 42]
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
|
|
|
|
2011-09-01 00:58:38 -04:00
|
|
|
it 'sets _in_ to an array with the entered lines' do
|
2012-12-20 04:28:04 -05:00
|
|
|
t = pry_tester
|
|
|
|
t.eval ":foo"
|
|
|
|
t.eval "42"
|
|
|
|
res = t.eval "_in_"
|
2011-06-06 11:14:29 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(res).to be_a_kind_of Pry::HistoryArray
|
|
|
|
expect(res[1..2]).to eq [":foo\n", "42\n"]
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
|
|
|
|
2011-09-01 00:58:38 -04:00
|
|
|
it 'uses 100 as the size of _in_ and _out_' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_tester.eval("[_in_.max_size, _out_.max_size]")).to eq [100, 100]
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can change the size of the history arrays' do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_tester(:memory_size => 1000).eval("[_out_, _in_].map(&:max_size)")).to eq [1000, 1000]
|
2011-06-06 11:14:29 -04:00
|
|
|
end
|
2011-06-08 05:36:49 -04:00
|
|
|
|
|
|
|
it 'store exceptions' do
|
2012-12-18 03:10:52 -05:00
|
|
|
mock_pry("foo!", "Pad.in = _in_[-1]; Pad.out = _out_[-1]")
|
2011-06-08 05:36:49 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.in).to eq "foo!\n"
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect(Pad.out).to be_a_kind_of NoMethodError
|
2011-06-08 05:36:49 -04:00
|
|
|
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
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("2", "_ + 82")).to eq 84
|
2012-01-13 02:43:06 -05:00
|
|
|
end
|
|
|
|
|
2012-09-09 01:29:00 -04:00
|
|
|
# This test needs mock_pry because the command retvals work by
|
|
|
|
# replacing the eval_string, so _ won't be modified without Pry doing
|
|
|
|
# a REPL loop.
|
2012-01-13 02:43:06 -05:00
|
|
|
it "should be set to the result of a command with :keep_retval" do
|
2012-09-09 01:29:00 -04:00
|
|
|
Pry::Commands.block_command '++', '', :keep_retval => true do |a|
|
|
|
|
a.to_i + 1
|
|
|
|
end
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(mock_pry('++ 86', '++ #{_}')).to match(/88/)
|
2012-01-13 02:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be preserved over an empty line" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("2 + 2", " ", "\t", " ", "_ + 92")).to eq 96
|
2012-01-13 02:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be preserved when evalling a command without :keep_retval" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(pry_eval("2 + 2", "ls -l", "_ + 96")).to eq 100
|
2012-01-13 02:43:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
describe "nesting" do
|
2011-01-10 01:29:26 -05:00
|
|
|
after do
|
|
|
|
Pry.reset_defaults
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.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
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.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
|
|
|
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.output = @str_output
|
2010-12-24 03:30:51 -05:00
|
|
|
|
|
|
|
o = Object.new
|
2015-01-22 16:52:20 -05:00
|
|
|
o.pry
|
2010-12-24 03:30:51 -05:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@str_output.string).to match(/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|
|
2012-12-15 18:51:02 -05:00
|
|
|
pry_eval(val, 'def hello; end')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(val.methods(false).map(&:to_sym).include?(:hello)).to eq true
|
2011-01-23 09:03:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define an instance method on the module when performing "def meth;end" inside the module' do
|
|
|
|
hello = Module.new
|
2012-12-15 18:51:02 -05:00
|
|
|
pry_eval(hello, "def hello; end")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(hello.instance_methods(false).map(&:to_sym).include?(:hello)).to eq true
|
2011-01-23 09:03:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define an instance method on the class when performing "def meth;end" inside the class' do
|
|
|
|
hello = Class.new
|
2012-12-15 18:51:02 -05:00
|
|
|
pry_eval(hello, "def hello; end")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(hello.instance_methods(false).map(&:to_sym).include?(:hello)).to eq true
|
2011-01-23 09:03:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
|
2017-09-12 21:35:00 -04:00
|
|
|
# JRuby behaves different than CRuby here (seems it always has to some extent, see 'unless' below).
|
|
|
|
# It didn't seem trivial to work around. Skip for now.
|
|
|
|
skip "JRuby incompatibility" if Pry::Helpers::BaseHelpers.jruby?
|
2013-10-24 02:22:42 -04:00
|
|
|
[:test, 0, true, false, nil,
|
|
|
|
(0.0 unless Pry::Helpers::BaseHelpers.jruby?)].each do |val|
|
2012-12-15 18:51:02 -05:00
|
|
|
pry_eval(val, "def hello; end");
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(val.class.instance_methods(false).map(&:to_sym).include?(:hello)).to eq true
|
2011-01-23 09:03:39 -05:00
|
|
|
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
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.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
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.input = InputTester.new("self", "exit-all")
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
str_output = StringIO.new
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.output = str_output
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
20.pry
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(str_output.string).to match(/20/)
|
2011-01-09 06:51:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should start a pry session on the receiver (second form)" do
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.input = InputTester.new("self", "exit-all")
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
str_output = StringIO.new
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.output = str_output
|
2011-01-09 06:51:45 -05:00
|
|
|
|
|
|
|
pry 20
|
2011-04-16 17:17:30 -04:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(str_output.string).to match(/20/)
|
2011-01-09 06:51:45 -05:00
|
|
|
end
|
|
|
|
|
2012-04-01 05:10:46 -04:00
|
|
|
it "should raise if more than two arguments are passed to Object#pry" do
|
Switch test suite to RSpec
Removes Bacon and Mocha
Reasoning explained in this comment: https://github.com/pry/pry/issues/277#issuecomment-51708712
Mostly this went smoothly. There were a few errors that I fixed along
the way, e.g. tests that were failing but for various reasons still
passed. Should have documented them, but didn't think about it until
very near the end. But generaly, I remember 2 reasons this would happen:
`lambda { raise "omg" }.should.raise(RuntimeError, /not-omg/)` will pass
because the second argument is ignored by Bacon. And `1.should == 2`
will return false instead of raising an error when it is not in an it
block (e.g. if stuck in a describe block, that would just return false)
The only one that I felt unsure about was spec/helpers/table_spec.rb
`Pry::Helpers.tablify_or_one_line('head', %w(ing)).should == 'head: ing'`
This is wrong, but was not failing because it was in a describe block
instead of an it block. In reality, it returns `"head: ing\n"`,
I updated the test to reflect this, though I don't know for sure
this is the right thing to do
This will fail on master until https://github.com/pry/pry/pull/1281 is merged.
This makes https://github.com/pry/pry/pull/1278 unnecessary.
2014-08-10 18:26:47 -04:00
|
|
|
expect { pry(20, :quiet, :input => Readline) }.to raise_error 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') }
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry.binding_for(_main_.call).is_a?(Binding)).to eq true
|
|
|
|
expect(Pry.binding_for(_main_.call)).to eq TOPLEVEL_BINDING
|
|
|
|
expect(Pry.binding_for(_main_.call)).to eq 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
|
2014-07-06 19:27:46 -04:00
|
|
|
it 'does not raise for unrecognized options' do
|
2015-01-22 16:52:20 -05:00
|
|
|
expect { Pry.new(:custom_option => 'custom value') }.to_not raise_error
|
2012-01-02 14:23:22 -05:00
|
|
|
end
|
2014-07-06 19:27:46 -04:00
|
|
|
|
|
|
|
it 'correctly handles the :quiet option (#1261)' do
|
|
|
|
instance = Pry.new(:quiet => true)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(instance.quiet?).to eq true
|
2014-07-06 19:27:46 -04:00
|
|
|
end
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
2012-12-27 22:34:52 -05:00
|
|
|
|
|
|
|
describe "a fresh instance" do
|
|
|
|
it "should use `caller` as its backtrace" do
|
2013-07-27 19:13:54 -04:00
|
|
|
location = "#{__FILE__}:#{__LINE__ + 1}"[1..-1] # omit leading .
|
2012-12-27 22:34:52 -05:00
|
|
|
backtrace = Pry.new.backtrace
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(backtrace).not_to equal nil
|
|
|
|
expect(backtrace.any? { |l| l.include?(location) }).to equal true
|
2012-12-27 22:34:52 -05:00
|
|
|
end
|
|
|
|
end
|
2012-01-13 02:48:09 -05:00
|
|
|
end
|