# frozen_string_literal: true describe Pry do before do @str_output = StringIO.new end describe ".configure" do it "yields a block with Pry.config as its argument" do Pry.config.foo = nil Pry.configure do |config| config.foo = "bar" end expect(Pry.config.foo).to eq("bar") end end 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 expect(input('BasicObject.new')).to match(/^=> # 2\n") Process.kill("USR1", Process.pid) expect(@str_output).to match(/Unable to obtain mutex lock/) end end describe "multi-line input" do it "works" do expect(mock_pry('x = ', '1 + 4')).to match(/5/) end it 'should suppress output if input ends in a ";" (multi-line)' do expect(mock_pry('def self.blah', ':test', 'end;')).to eq '' end describe "newline stripping from an empty string" do it "with double quotes" do expect(mock_pry('"', '"')).to match(/"\\n"/) expect(mock_pry('"', "\n", "\n", "\n", '"')).to match(/"\\n\\n\\n\\n"/) end it "with single quotes" do expect(mock_pry("'", "'")).to match(/"\\n"/) expect(mock_pry("'", "\n", "\n", "\n", "'")).to match(/"\\n\\n\\n\\n"/) end it "with fancy delimiters" do expect(mock_pry('%(', ')')).to match(/"\\n"/) expect(mock_pry('%|', "\n", "\n", '|')).to match(/"\\n\\n\\n"/) expect(mock_pry('%q[', "\n", "\n", ']')).to match(/"\\n\\n\\n"/) end end describe "newline stripping from an empty regexp" do it "with regular regexp delimiters" do expect(mock_pry('/', '/')).to match(%r{/\n/}) end it "with fancy delimiters" do expect(mock_pry('%r{', "\n", "\n", '}')).to match(%r{/\n\n\n/}) expect(mock_pry('%r<', "\n", '>')).to match(%r{/\n\n/}) end end describe "newline from an empty heredoc" do it "works" do expect(mock_pry('< { TOPLEVEL_BINDING.eval('self') } 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) end end end end describe 'setting custom options' do it 'does not raise for unrecognized options' do expect { Pry.new(custom_option: 'custom value') }.to_not raise_error end it 'correctly handles the :quiet option (#1261)' do instance = Pry.new(quiet: true) expect(instance.quiet?).to eq true end end describe "a fresh instance" do it "should use `caller` as its backtrace" do location = "#{__FILE__}:#{__LINE__ + 1}"[1..-1] # omit leading . backtrace = Pry.new.backtrace expect(backtrace).not_to equal nil expect(backtrace.any? { |l| l.include?(location) }).to equal true end end end