2013-01-13 23:55:35 -05:00
|
|
|
require 'pathname'
|
2014-03-14 00:31:24 -04:00
|
|
|
require_relative '../helper'
|
2012-09-15 17:50:15 -04:00
|
|
|
|
|
|
|
describe "edit" do
|
|
|
|
before do
|
|
|
|
@old_editor = Pry.config.editor
|
2012-10-21 20:00:51 -04:00
|
|
|
@file = @line = @contents = nil
|
2012-09-15 17:50:15 -04:00
|
|
|
Pry.config.editor = lambda do |file, line|
|
|
|
|
@file = file; @line = line; @contents = File.read(@file)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.config.editor = @old_editor
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with FILE" do
|
2013-01-13 23:55:35 -05:00
|
|
|
before do
|
|
|
|
# OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's
|
|
|
|
# something "Temp".
|
2013-01-14 05:11:37 -05:00
|
|
|
@tf_dir =
|
2018-11-01 12:16:35 -04:00
|
|
|
if Pry::Helpers::Platform.mri_19?
|
2013-01-14 05:11:37 -05:00
|
|
|
Pathname.new(Dir::Tmpname.tmpdir)
|
2013-01-14 11:43:19 -05:00
|
|
|
else
|
|
|
|
Pathname.new(Dir.tmpdir)
|
2013-01-14 05:11:37 -05:00
|
|
|
end
|
2013-01-13 23:55:35 -05:00
|
|
|
|
|
|
|
@tf_path = File.expand_path(File.join(@tf_dir.to_s, 'bar.rb'))
|
|
|
|
FileUtils.touch(@tf_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2015-01-23 04:30:41 -05:00
|
|
|
FileUtils.rm(@tf_path) if File.exist?(@tf_path)
|
2013-01-13 23:55:35 -05:00
|
|
|
end
|
|
|
|
|
2014-01-25 16:55:47 -05:00
|
|
|
it "should not allow patching any known kind of file" do
|
|
|
|
["file.rb", "file.c", "file.py", "file.yml", "file.gemspec",
|
|
|
|
"/tmp/file", "\\\\Temp\\\\file"].each do |file|
|
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_eval "edit -p #{file}" }.to raise_error(NotImplementedError, /Cannot yet patch false objects!/)
|
2014-01-25 16:55:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it "should invoke Pry.config.editor with absolutified filenames" do
|
|
|
|
pry_eval 'edit lib/pry.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq File.expand_path('lib/pry.rb')
|
2012-09-15 17:50:15 -04:00
|
|
|
|
2013-01-13 23:55:35 -05:00
|
|
|
pry_eval "edit #@tf_path"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tf_path
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should guess the line number from a colon" do
|
|
|
|
pry_eval 'edit lib/pry.rb:10'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@line).to eq 10
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use the line number from -l" do
|
|
|
|
pry_eval 'edit -l 10 lib/pry.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@line).to eq 10
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not delete the file!" do
|
|
|
|
pry_eval 'edit Rakefile'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(File.exist?(@file)).to eq true
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-01-13 16:09:09 -05:00
|
|
|
it "works with files that contain blanks in their names" do
|
2013-01-13 23:55:35 -05:00
|
|
|
tf_path = File.join(File.dirname(@tf_path), 'swoop and doop.rb')
|
|
|
|
FileUtils.touch(tf_path)
|
|
|
|
pry_eval "edit #{ tf_path }"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq tf_path
|
2013-01-13 23:55:35 -05:00
|
|
|
FileUtils.rm(tf_path)
|
2013-01-13 16:09:09 -05:00
|
|
|
end
|
|
|
|
|
2013-03-23 02:35:27 -04:00
|
|
|
if respond_to?(:require_relative, true)
|
|
|
|
it "should work with require relative" do
|
|
|
|
Pry.config.editor = lambda { |file, line|
|
2018-11-04 04:34:24 -05:00
|
|
|
File.open(file, 'w') { |f| f << 'require_relative "baz.rb"' }
|
|
|
|
File.open(file.gsub('bar.rb', 'baz.rb'), 'w') { |f| f << "Pad.required = true; FileUtils.rm(__FILE__)" }
|
2013-03-23 02:35:27 -04:00
|
|
|
nil
|
|
|
|
}
|
|
|
|
pry_eval "edit #@tf_path"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.required).to eq true
|
2013-03-23 02:35:27 -04:00
|
|
|
end
|
2013-03-23 02:26:52 -04:00
|
|
|
end
|
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
describe do
|
|
|
|
before do
|
|
|
|
Pad.counter = 0
|
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "Pad.counter = Pad.counter + 1" }
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should reload the file if it is a ruby file" do
|
2012-12-07 17:08:49 -05:00
|
|
|
temp_file do |tf|
|
2012-09-15 17:50:15 -04:00
|
|
|
counter = Pad.counter
|
|
|
|
path = tf.path
|
|
|
|
|
|
|
|
pry_eval "edit #{path}"
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.counter).to eq counter + 1
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not reload the file if it is not a ruby file" do
|
2012-12-07 17:08:49 -05:00
|
|
|
temp_file('.py') do |tf|
|
2012-09-15 17:50:15 -04:00
|
|
|
counter = Pad.counter
|
|
|
|
path = tf.path
|
|
|
|
|
|
|
|
pry_eval "edit #{path}"
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.counter).to eq counter
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not reload a ruby file if -n is given" do
|
2012-12-07 17:08:49 -05:00
|
|
|
temp_file do |tf|
|
2012-09-15 17:50:15 -04:00
|
|
|
counter = Pad.counter
|
|
|
|
path = tf.path
|
|
|
|
|
2015-01-23 04:30:41 -05:00
|
|
|
pry_eval "edit -n #{path}"
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.counter).to eq counter
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should reload a non-ruby file if -r is given" do
|
2012-12-07 17:08:49 -05:00
|
|
|
temp_file('.pryrc') do |tf|
|
2012-09-15 17:50:15 -04:00
|
|
|
counter = Pad.counter
|
|
|
|
path = tf.path
|
|
|
|
|
|
|
|
pry_eval "edit -r #{path}"
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pad.counter).to eq counter + 1
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe do
|
|
|
|
before do
|
|
|
|
@reloading = nil
|
|
|
|
Pry.config.editor = lambda do |file, line, reloading|
|
|
|
|
@file = file; @line = line; @reloading = reloading
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should pass the editor a reloading arg" do
|
|
|
|
pry_eval 'edit lib/pry.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@reloading).to eq true
|
2012-09-15 17:50:15 -04:00
|
|
|
pry_eval 'edit -n lib/pry.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@reloading).to eq false
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with --ex" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester do
|
|
|
|
def last_exception=(exception)
|
|
|
|
@pry.last_exception = exception
|
|
|
|
end
|
2018-10-14 02:23:34 -04:00
|
|
|
|
2013-01-15 14:06:44 -05:00
|
|
|
def last_exception; @pry.last_exception; end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with a real file" do
|
|
|
|
before do
|
|
|
|
@tf = Tempfile.new(["pry", ".rb"])
|
|
|
|
@path = @tf.path
|
2015-01-23 07:02:38 -05:00
|
|
|
@tf << "_foo = 1\n_bar = 2\nraise RuntimeError"
|
2012-09-15 17:50:15 -04:00
|
|
|
@tf.flush
|
|
|
|
|
|
|
|
begin
|
|
|
|
load @path
|
|
|
|
rescue RuntimeError => e
|
|
|
|
@t.last_exception = e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@tf.close(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should reload the file" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "FOO = 'BAR'" }
|
2012-09-15 17:50:15 -04:00
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(defined?(FOO)).to equal nil
|
2012-09-15 17:50:15 -04:00
|
|
|
|
|
|
|
@t.eval 'edit --ex'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(FOO).to eq 'BAR'
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-01-15 14:06:44 -05:00
|
|
|
# regression test (this used to edit the current method instead
|
|
|
|
# of the exception)
|
|
|
|
it 'edits the exception even when in a patched method context' do
|
|
|
|
source_location = nil
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
2013-01-15 14:06:44 -05:00
|
|
|
source_location = [file, line]
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Pad.le = @t.last_exception
|
|
|
|
redirect_pry_io(InputTester.new("def broken_method", "binding.pry", "end",
|
|
|
|
"broken_method",
|
|
|
|
"_pry_.last_exception = Pad.le",
|
|
|
|
"edit --ex -n", "exit-all", "exit-all")) do
|
|
|
|
Object.new.pry
|
|
|
|
end
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(source_location).to eq [@path, 3]
|
2013-01-15 14:06:44 -05:00
|
|
|
Pad.clear
|
|
|
|
end
|
|
|
|
|
2012-09-15 17:50:15 -04:00
|
|
|
it "should not reload the file if -n is passed" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "FOO2 = 'BAZ'" }
|
2012-09-15 17:50:15 -04:00
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(defined?(FOO2)).to equal nil
|
2012-09-15 17:50:15 -04:00
|
|
|
|
|
|
|
@t.eval 'edit -n --ex'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(defined?(FOO2)).to equal nil
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
2012-10-21 20:00:51 -04:00
|
|
|
|
|
|
|
describe "with --patch" do
|
|
|
|
# Original source code must be untouched.
|
|
|
|
it "should apply changes only in memory (monkey patching)" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "FOO3 = 'PIYO'" }
|
2012-10-21 20:00:51 -04:00
|
|
|
@patched_def = File.open(file, 'r').read
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(defined?(FOO3)).to equal nil
|
2012-10-21 20:00:51 -04:00
|
|
|
|
|
|
|
@t.eval 'edit --ex --patch'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(FOO3).to eq 'PIYO'
|
2012-10-21 20:00:51 -04:00
|
|
|
|
|
|
|
@tf.rewind
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@tf.read).to eq "_foo = 1\n_bar = 2\nraise RuntimeError"
|
|
|
|
expect(@patched_def).to eq "FOO3 = 'PIYO'"
|
2012-10-21 20:00:51 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "with --ex NUM" do
|
|
|
|
before do
|
|
|
|
Pry.config.editor = proc do |file, line|
|
|
|
|
@__ex_file__ = file
|
|
|
|
@__ex_line__ = line
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
@t.last_exception = mock_exception('a:1', 'b:2', 'c:3')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should start on first level of backtrace with just --ex' do
|
|
|
|
@t.eval 'edit -n --ex'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@__ex_file__).to eq "a"
|
|
|
|
expect(@__ex_line__).to eq 1
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should start editor on first level of backtrace with --ex 0' do
|
|
|
|
@t.eval 'edit -n --ex 0'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@__ex_file__).to eq "a"
|
|
|
|
expect(@__ex_line__).to eq 1
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should start editor on second level of backtrace with --ex 1' do
|
|
|
|
@t.eval 'edit -n --ex 1'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@__ex_file__).to eq "b"
|
|
|
|
expect(@__ex_line__).to eq 2
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should start editor on third level of backtrace with --ex 2' do
|
|
|
|
@t.eval 'edit -n --ex 2'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@__ex_file__).to eq "c"
|
|
|
|
expect(@__ex_line__).to eq 3
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display error message when backtrace level is invalid' 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 { @t.eval 'edit -n --ex 4' }.to raise_error Pry::CommandError
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "without FILE" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should edit the current expression if it's incomplete" do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push 'def a'
|
2012-12-18 03:51:21 -05:00
|
|
|
@t.process_command 'edit'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "def a\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should edit the previous expression if the current is empty" do
|
2015-01-23 06:28:22 -05:00
|
|
|
@t.eval 'undef a if self.singleton_class.method_defined? :a'
|
2012-09-15 17:50:15 -04:00
|
|
|
@t.eval 'def a; 2; end', 'edit'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "def a; 2; end\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use a blank file if -t is specified" do
|
2015-01-23 06:28:22 -05:00
|
|
|
@t.eval 'undef a if self.singleton_class.method_defined? :a'
|
2012-09-15 17:50:15 -04:00
|
|
|
@t.eval 'def a; 5; end', 'edit -t'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use a blank file if -t given, even during an expression" do
|
2012-12-28 01:06:50 -05:00
|
|
|
@t.push 'def a;'
|
2012-12-18 03:51:21 -05:00
|
|
|
@t.process_command 'edit -t'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should position the cursor at the end of the expression" do
|
2015-01-23 06:28:22 -05:00
|
|
|
@t.eval 'undef a if self.singleton_class.method_defined? :a'
|
2012-12-18 03:51:21 -05:00
|
|
|
@t.eval "def a; 2;\nend"
|
|
|
|
@t.process_command 'edit'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@line).to eq 2
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should evaluate the expression" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "'FOO'\n" }
|
2012-09-15 17:50:15 -04:00
|
|
|
nil
|
|
|
|
}
|
2012-12-18 03:51:21 -05:00
|
|
|
@t.process_command 'edit'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq "'FOO'\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-07-26 19:52:15 -04:00
|
|
|
it "should ignore -n for tempfiles" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "'FOO'\n" }
|
2012-09-15 17:50:15 -04:00
|
|
|
nil
|
|
|
|
}
|
2013-07-26 19:52:15 -04:00
|
|
|
@t.process_command "edit -n"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@t.eval_string).to eq "'FOO'\n"
|
2013-07-26 19:52:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not evaluate a file with -n" do
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
|
|
|
File.open(file, 'w') { |f| f << "'FOO'\n" }
|
2013-07-26 19:52:15 -04:00
|
|
|
nil
|
|
|
|
}
|
|
|
|
begin
|
|
|
|
@t.process_command 'edit -n spec/fixtures/foo.rb'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(File.read("spec/fixtures/foo.rb")).to eq "'FOO'\n"
|
|
|
|
expect(@t.eval_string).to eq ''
|
2013-07-26 19:52:15 -04:00
|
|
|
ensure
|
|
|
|
FileUtils.rm "spec/fixtures/foo.rb"
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
2018-03-25 11:43:27 -04:00
|
|
|
|
|
|
|
it "should write the evaluated command to history" do
|
|
|
|
quote = 'history repeats itself, first as tradegy...'
|
2018-11-04 04:34:24 -05:00
|
|
|
Pry.config.editor = lambda { |file, line|
|
2018-10-06 12:58:53 -04:00
|
|
|
File.open(file, 'w') { |f|
|
2018-05-19 06:56:52 -04:00
|
|
|
f << quote
|
2018-03-25 11:43:27 -04:00
|
|
|
}
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
@t.process_command 'edit'
|
|
|
|
expect(Pry.history.to_a.last).to eq quote
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "with --in" do
|
|
|
|
it "should edit the nth line of _in_" do
|
|
|
|
pry_eval '10', '11', 'edit --in -2'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "10\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should edit the last line if no argument is given" do
|
|
|
|
pry_eval '10', '11', 'edit --in'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "11\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should edit a range of lines if a range is given" do
|
|
|
|
pry_eval "10", "11", "edit -i 1,2"
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@contents).to eq "10\n11\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should edit a multi-line expression as it occupies one line of _in_" do
|
2017-06-03 08:50:31 -04:00
|
|
|
pry_eval "class #{1.class}\n def invert; -self; end\nend", "edit -i 1"
|
|
|
|
expect(@contents).to eq "class #{1.class}\n def invert; -self; end\nend\n"
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not work with a filename" 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_eval 'edit ruby.rb -i' }.to raise_error(Pry::CommandError, /Only one of --ex, --temp, --in, --method and FILE/)
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not work with nonsense" 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_eval 'edit --in three' }.to raise_error(Pry::CommandError, /Not a valid range: three/)
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-10 02:00:42 -04:00
|
|
|
describe 'when editing a method by name' do
|
2014-08-10 02:33:38 -04:00
|
|
|
def use_editor(tester, options)
|
|
|
|
tester.pry.config.editor = lambda do |filename, line|
|
|
|
|
File.open(filename, 'w') { |f| f.write options.fetch(:replace_all) }
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
tester
|
|
|
|
end
|
|
|
|
|
2014-08-10 02:00:42 -04:00
|
|
|
it 'uses patch editing on methods that were previously patched' do
|
|
|
|
# initial definition
|
2014-08-10 02:33:38 -04:00
|
|
|
tester = pry_tester binding
|
2014-08-10 02:00:42 -04:00
|
|
|
filename = __FILE__
|
|
|
|
line = __LINE__ + 2
|
|
|
|
klass = Class.new do
|
2014-08-10 02:33:38 -04:00
|
|
|
def m; 1; end
|
2014-08-10 02:00:42 -04:00
|
|
|
end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(klass.new.m).to eq 1
|
2014-08-10 02:00:42 -04:00
|
|
|
|
|
|
|
# now patch it
|
2014-08-10 02:33:38 -04:00
|
|
|
use_editor(tester, replace_all: 'def m; 2; end').eval('edit --patch klass#m')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(klass.new.m).to eq 2
|
2014-08-10 02:00:42 -04:00
|
|
|
|
|
|
|
# edit by name, no --patch
|
2014-08-10 02:33:38 -04:00
|
|
|
use_editor(tester, replace_all: 'def m; 3; end').eval("edit klass#m")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(klass.new.m).to eq 3
|
2014-08-10 02:00:42 -04:00
|
|
|
|
|
|
|
# original file is unchanged
|
2018-11-04 04:34:24 -05:00
|
|
|
expect(File.readlines(filename)[line - 1].strip).to eq 'def m; 1; end'
|
2014-08-10 02:00:42 -04:00
|
|
|
end
|
|
|
|
|
2014-08-10 02:33:38 -04:00
|
|
|
it 'can repeatedly edit methods that were defined in the console' do
|
|
|
|
# initial definition
|
|
|
|
tester = pry_tester binding
|
|
|
|
tester.eval("klass = Class.new do\n"\
|
|
|
|
" def m; 1; end\n"\
|
|
|
|
"end")
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(tester.eval("klass.new.m")).to eq 1
|
2014-08-10 02:33:38 -04:00
|
|
|
|
|
|
|
# first edit
|
|
|
|
use_editor(tester, replace_all: 'def m; 2; end').eval('edit klass#m')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(tester.eval('klass.new.m')).to eq 2
|
2014-08-10 02:33:38 -04:00
|
|
|
|
|
|
|
# repeat edit
|
|
|
|
use_editor(tester, replace_all: 'def m; 3; end').eval('edit klass#m')
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(tester.eval('klass.new.m')).to eq 3
|
2014-08-10 02:33:38 -04:00
|
|
|
end
|
2014-08-10 02:00:42 -04:00
|
|
|
end
|
|
|
|
|
2012-12-31 19:25:43 -05:00
|
|
|
describe "old edit-method tests now migrated to edit" do
|
|
|
|
describe "on a method defined in a file" do
|
|
|
|
before do
|
2015-01-23 04:30:41 -05:00
|
|
|
Object.remove_const :X if defined? ::X
|
|
|
|
Object.remove_const :A if defined? ::A
|
2013-01-07 18:02:39 -05:00
|
|
|
@tempfile = (Tempfile.new(['pry', '.rb']))
|
2012-12-31 19:25:43 -05:00
|
|
|
@tempfile.puts <<-EOS
|
|
|
|
module A
|
|
|
|
def a
|
|
|
|
:yup
|
|
|
|
end
|
|
|
|
|
|
|
|
def b
|
|
|
|
:kinda
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class X
|
|
|
|
include A
|
|
|
|
|
|
|
|
def self.x
|
|
|
|
:double_yup
|
|
|
|
end
|
|
|
|
|
|
|
|
def x
|
|
|
|
:nope
|
|
|
|
end
|
|
|
|
|
|
|
|
def b
|
|
|
|
super
|
|
|
|
end
|
|
|
|
alias c b
|
|
|
|
|
|
|
|
def y?
|
|
|
|
:because
|
|
|
|
end
|
|
|
|
|
|
|
|
class B
|
|
|
|
G = :nawt
|
|
|
|
|
|
|
|
def foo
|
2015-01-23 04:30:41 -05:00
|
|
|
_foo = :possibly
|
2012-12-31 19:25:43 -05:00
|
|
|
G
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
@tempfile.flush
|
|
|
|
load @tempfile.path
|
|
|
|
|
2013-01-14 00:17:47 -05:00
|
|
|
@tempfile_path = @tempfile.path
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@tempfile.close(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without -p' do
|
|
|
|
before do
|
|
|
|
@file = @line = @contents = nil
|
|
|
|
Pry.config.editor = lambda do |file, line|
|
|
|
|
@file = file; @line = line
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should correctly find a class method" do
|
|
|
|
pry_eval 'edit X.x'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tempfile_path
|
|
|
|
expect(@line).to eq 14
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should correctly find an instance method" do
|
|
|
|
pry_eval 'edit X#x'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tempfile_path
|
|
|
|
expect(@line).to eq 18
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should correctly find a method on an instance" do
|
|
|
|
pry_eval 'x = X.new', 'edit x.x'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tempfile_path
|
|
|
|
expect(@line).to eq 18
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should correctly find a method from a module" do
|
|
|
|
pry_eval 'edit X#a'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tempfile_path
|
|
|
|
expect(@line).to eq 2
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should correctly find an aliased method" do
|
|
|
|
pry_eval 'edit X#c'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@file).to eq @tempfile_path
|
|
|
|
expect(@line).to eq 22
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with -p' do
|
|
|
|
before do
|
|
|
|
Pry.config.editor = lambda do |file, line|
|
|
|
|
lines = File.read(file).lines.to_a
|
2015-01-23 06:15:40 -05:00
|
|
|
lines[1] = if lines[2] =~ /end/
|
|
|
|
":maybe\n"
|
|
|
|
else
|
|
|
|
"_foo = :maybe\n"
|
|
|
|
end
|
2012-12-31 19:25:43 -05:00
|
|
|
File.open(file, 'w') do |f|
|
|
|
|
f.write(lines.join)
|
|
|
|
end
|
|
|
|
@patched_def = String(lines[1]).chomp
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should successfully replace a class method" do
|
|
|
|
pry_eval 'edit -p X.x'
|
|
|
|
|
|
|
|
class << X
|
|
|
|
X.method(:x).owner.should == self
|
|
|
|
end
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X.method(:x).receiver).to eq X
|
|
|
|
expect(X.x).to eq :maybe
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should successfully replace an instance method" do
|
|
|
|
pry_eval 'edit -p X#x'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X.instance_method(:x).owner).to eq X
|
|
|
|
expect(X.new.x).to eq :maybe
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should successfully replace a method on an instance" do
|
|
|
|
pry_eval 'instance = X.new', 'edit -p instance.x'
|
|
|
|
|
|
|
|
instance = X.new
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(instance.method(:x).owner).to eq X
|
|
|
|
expect(instance.x).to eq :maybe
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should successfully replace a method from a module" do
|
|
|
|
pry_eval 'edit -p X#a'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X.instance_method(:a).owner).to eq A
|
|
|
|
expect(X.new.a).to eq :maybe
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should successfully replace a method with a question mark" do
|
|
|
|
pry_eval 'edit -p X#y?'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X.instance_method(:y?).owner).to eq X
|
|
|
|
expect(X.new.y?).to eq :maybe
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should preserve module nesting" do
|
|
|
|
pry_eval 'edit -p X::B#foo'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X::B.instance_method(:foo).owner).to eq X::B
|
|
|
|
expect(X::B.new.foo).to eq :nawt
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "monkey-patching" do
|
|
|
|
before do
|
|
|
|
@edit = 'edit --patch ' # A shortcut.
|
|
|
|
end
|
|
|
|
|
|
|
|
# @param [Integer] lineno
|
|
|
|
# @return [String] the stripped line from the tempfile at +lineno+
|
|
|
|
def stripped_line_at(lineno)
|
|
|
|
@tempfile.rewind
|
2015-01-23 04:30:41 -05:00
|
|
|
@tempfile.each_line.to_a[lineno].strip
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Applies the monkey patch for +method+ with help of evaluation of
|
|
|
|
# +eval_strs+. The idea is to capture the initial line number (before
|
|
|
|
# the monkey patch), because it gets overwritten by the line number from
|
|
|
|
# the monkey patch. And our goal is to check that the original
|
|
|
|
# definition hasn't changed.
|
|
|
|
# @param [UnboundMethod] method
|
|
|
|
# @param [Array<String>] eval_strs
|
|
|
|
# @return [Array<String] the lines with definitions of the same line
|
|
|
|
# before monkey patching and after (normally, they should be equal)
|
|
|
|
def apply_monkey_patch(method, *eval_strs)
|
|
|
|
_, lineno = method.source_location
|
|
|
|
definition_before = stripped_line_at(lineno)
|
|
|
|
|
|
|
|
pry_eval(*eval_strs)
|
|
|
|
|
|
|
|
definition_after = stripped_line_at(lineno)
|
|
|
|
|
|
|
|
[definition_before, definition_after]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should work for a class method" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X.method(:x), "#@edit X.x")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq ':double_yup'
|
|
|
|
expect(def_after).to eq ':double_yup'
|
|
|
|
expect(@patched_def).to eq ':maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work for an instance method" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X.instance_method(:x), "#@edit X#x")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq ':nope'
|
|
|
|
expect(def_after).to eq ':nope'
|
|
|
|
expect(@patched_def).to eq ':maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work for a method on an instance" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X.instance_method(:x), 'instance = X.new', "#@edit instance.x")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq ':nope'
|
|
|
|
expect(def_after).to eq ':nope'
|
|
|
|
expect(@patched_def).to eq ':maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work for a method from a module" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X.instance_method(:a), "#@edit X#a")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq ':yup'
|
|
|
|
expect(def_after).to eq ':yup'
|
|
|
|
expect(@patched_def).to eq ':maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work for a method with a question mark" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X.instance_method(:y?), "#@edit X#y?")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq ':because'
|
|
|
|
expect(def_after).to eq ':because'
|
|
|
|
expect(@patched_def).to eq ':maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work with nesting" do
|
|
|
|
def_before, def_after =
|
|
|
|
apply_monkey_patch(X::B.instance_method(:foo), "#@edit X::B#foo")
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(def_before).to eq '_foo = :possibly'
|
|
|
|
expect(def_after).to eq '_foo = :possibly'
|
|
|
|
expect(@patched_def).to eq '_foo = :maybe'
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'on an aliased method' do
|
|
|
|
before do
|
|
|
|
Pry.config.editor = lambda do |file, line|
|
|
|
|
lines = File.read(file).lines.to_a
|
|
|
|
lines[1] = '"#{super}aa".to_sym' + "\n"
|
|
|
|
File.open(file, 'w') do |f|
|
|
|
|
f.write(lines.join)
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should change the alias, but not the original, without breaking super" do
|
|
|
|
$x = :bebe
|
|
|
|
pry_eval 'edit -p X#c'
|
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(Pry::Method.from_str("X#c").alias?).to eq true
|
2012-12-31 19:25:43 -05:00
|
|
|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(X.new.b).to eq :kinda
|
|
|
|
expect(X.new.c).to eq :kindaaa
|
2012-12-31 19:25:43 -05:00
|
|
|
$x = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with three-arg editor' do
|
|
|
|
before do
|
|
|
|
@file = @line = @reloading = nil
|
|
|
|
Pry.config.editor = lambda do |file, line, reloading|
|
|
|
|
@file = file; @line = line; @reloading = reloading
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should pass the editor a reloading arg" do
|
|
|
|
pry_eval 'edit X.x'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@reloading).to eq true
|
2012-12-31 19:25:43 -05:00
|
|
|
pry_eval 'edit -n X.x'
|
2015-03-10 16:49:29 -04:00
|
|
|
expect(@reloading).to eq false
|
2012-12-31 19:25:43 -05:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|
|
|
|
end
|
2013-01-11 14:38:12 -05:00
|
|
|
|
|
|
|
describe "--method flag" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester
|
|
|
|
class BinkyWink
|
|
|
|
eval %{
|
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
|
|
|
def m1
|
2013-01-11 14:38:12 -05:00
|
|
|
binding
|
|
|
|
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
|
|
|
def m2
|
2015-01-23 04:30:41 -05:00
|
|
|
_foo = :jeremy_jones
|
2013-01-11 14:38:12 -05:00
|
|
|
binding
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.remove_const(:BinkyWink)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should edit method context' do
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.editor = lambda do |file, line|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect([file, line]).to eq BinkyWink.instance_method(:m2).source_location
|
2013-01-11 14:38:12 -05:00
|
|
|
nil
|
|
|
|
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
|
|
|
t = pry_tester(BinkyWink.new.m2)
|
2013-01-11 14:38:12 -05:00
|
|
|
t.process_command "edit -m -n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors when cannot find method context' do
|
2014-04-29 03:03:15 -04:00
|
|
|
Pry.config.editor = lambda do |file, line|
|
2015-03-10 16:49:29 -04:00
|
|
|
expect([file, line]).to eq BinkyWink.instance_method(:m1).source_location
|
2013-01-11 14:38:12 -05:00
|
|
|
nil
|
|
|
|
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
|
|
|
t = pry_tester(BinkyWink.new.m1)
|
2018-10-12 12:54:00 -04:00
|
|
|
expect { t.process_command "edit -m -n" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
|
2013-01-11 14:38:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors when a filename arg is passed with --method' 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 { @t.process_command "edit -m Pry#repl" }.to raise_error(Pry::CommandError, /Only one of/)
|
2013-01-11 14:38:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "pretty error messages" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester
|
|
|
|
class TrinkyDink
|
|
|
|
eval %{
|
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
|
|
|
def m
|
2013-01-11 14:38:12 -05:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.remove_const(:TrinkyDink)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display a nice error message when cannot open a file' 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 { @t.process_command "edit TrinkyDink#m" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
|
2013-01-11 14:38:12 -05:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 17:50:15 -04:00
|
|
|
end
|