2019-05-02 18:33:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-17 23:43:07 -05:00
|
|
|
describe Pry do
|
|
|
|
describe 'loading rc files' do
|
|
|
|
before do
|
2019-05-02 19:25:25 -04:00
|
|
|
Pry.config.rc_file = 'spec/fixtures/testrc'
|
2019-03-02 04:59:33 -05:00
|
|
|
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testrc/../testrc')
|
|
|
|
|
2013-02-17 23:43:07 -05:00
|
|
|
Pry.instance_variable_set(:@initial_session, true)
|
|
|
|
Pry.config.should_load_rc = true
|
|
|
|
Pry.config.should_load_local_rc = true
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.config.should_load_rc = false
|
|
|
|
Object.remove_const(:TEST_RC) if defined?(TEST_RC)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should never run the rc file twice" do
|
2018-10-12 15:09:29 -04:00
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(TEST_RC).to eq [0]
|
2013-02-17 23:43:07 -05:00
|
|
|
|
2018-10-12 15:09:29 -04:00
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(TEST_RC).to eq [0]
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
|
2013-02-18 02:17:05 -05:00
|
|
|
# Resolving symlinks doesn't work on jruby 1.9 [jruby issue #538]
|
2018-11-01 12:16:35 -04:00
|
|
|
unless Pry::Helpers::Platform.jruby_19?
|
2013-02-18 02:17:05 -05:00
|
|
|
it "should not load the rc file twice if it's symlinked differently" do
|
2019-05-02 19:25:25 -04:00
|
|
|
Pry.config.rc_file = 'spec/fixtures/testrc'
|
2019-03-02 04:59:33 -05:00
|
|
|
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testlinkrc')
|
2013-02-17 23:43:07 -05:00
|
|
|
|
2018-10-12 15:09:29 -04:00
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
2013-02-17 23:43:07 -05:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(TEST_RC).to eq [0]
|
2013-02-18 02:17:05 -05:00
|
|
|
end
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
|
2018-10-06 12:58:53 -04:00
|
|
|
it "should not load the pryrc if pryrc's directory permissions do not allow this" do
|
2015-06-28 14:38:05 -04:00
|
|
|
Dir.mktmpdir do |dir|
|
2019-03-02 05:07:44 -05:00
|
|
|
File.chmod 0o000, dir
|
2019-05-07 17:13:29 -04:00
|
|
|
stub_const('Pry::LOCAL_RC_FILE', File.join(dir, '.pryrc'))
|
2015-06-28 14:38:05 -04:00
|
|
|
Pry.config.should_load_rc = true
|
2019-03-03 10:37:58 -05:00
|
|
|
expect do
|
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
|
|
|
end.to_not raise_error
|
2019-03-02 05:07:44 -05:00
|
|
|
File.chmod 0o777, dir
|
2015-06-28 14:38:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-17 23:43:07 -05:00
|
|
|
it "should not load the pryrc if it cannot expand ENV[HOME]" do
|
|
|
|
old_home = ENV['HOME']
|
|
|
|
ENV['HOME'] = nil
|
|
|
|
Pry.config.should_load_rc = true
|
2019-03-03 10:37:58 -05:00
|
|
|
expect do
|
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
|
|
|
end.to_not raise_error
|
2013-02-17 23:43:07 -05:00
|
|
|
|
|
|
|
ENV['HOME'] = old_home
|
|
|
|
end
|
|
|
|
|
|
|
|
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_local_rc = false
|
2018-10-12 15:09:29 -04:00
|
|
|
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Object.const_defined?(:TEST_RC)).to eq false
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "that raise exceptions" do
|
|
|
|
before do
|
2019-05-02 19:25:25 -04:00
|
|
|
Pry.config.rc_file = 'spec/fixtures/testrcbad'
|
2013-02-17 23:43:07 -05:00
|
|
|
Pry.config.should_load_local_rc = false
|
|
|
|
|
|
|
|
putsed = nil
|
|
|
|
|
|
|
|
# YUCK! horrible hack to get round the fact that output is not configured
|
|
|
|
# at the point this message is printed.
|
2018-11-17 11:36:09 -05:00
|
|
|
(class << Pry; self; end).send(:define_method, :puts) do |str|
|
2013-02-17 23:43:07 -05:00
|
|
|
putsed = str
|
2018-11-17 11:36:09 -05:00
|
|
|
end
|
2013-02-17 23:43:07 -05:00
|
|
|
|
2018-11-04 04:34:24 -05:00
|
|
|
@doing_it = lambda {
|
2019-03-03 10:37:58 -05:00
|
|
|
input = StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n")
|
|
|
|
Pry.start(self, input: input, output: StringIO.new)
|
2013-02-17 23:43:07 -05:00
|
|
|
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
|
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(&@doing_it).to_not raise_error
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should continue to run pry" do
|
|
|
|
@doing_it[]
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Object.const_defined?(:TEST_BEFORE_RAISE)).to eq true
|
|
|
|
expect(Object.const_defined?(:TEST_AFTER_RAISE)).to eq true
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should output an error" do
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@doing_it.call.split("\n").first).to match(
|
2013-02-17 23:43:07 -05:00
|
|
|
%r{Error loading .*spec/fixtures/testrcbad: messin with ya}
|
2015-03-10 16:49:29 -04:00
|
|
|
)
|
2013-02-17 23:43:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|