mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Directify edit-method and tests thereof
This commit is contained in:
parent
5ccd6cb2ee
commit
ed1fb719dc
2 changed files with 16 additions and 16 deletions
|
@ -65,11 +65,11 @@ class Pry
|
||||||
|
|
||||||
if @method.alias?
|
if @method.alias?
|
||||||
with_method_transaction(original_name, @method.owner) do
|
with_method_transaction(original_name, @method.owner) do
|
||||||
Pry.new(:input => StringIO.new(source)).rep(TOPLEVEL_BINDING)
|
_pry_.evaluate_ruby source
|
||||||
Pry.binding_for(@method.owner).eval("alias #{@method.name} #{original_name}")
|
Pry.binding_for(@method.owner).eval("alias #{@method.name} #{original_name}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Pry.new(:input => StringIO.new(source)).rep(TOPLEVEL_BINDING)
|
_pry_.evaluate_ruby source
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -360,31 +360,31 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly find a class method" do
|
it "should correctly find a class method" do
|
||||||
mock_pry("edit-method X.x")
|
pry_eval 'edit-method X.x'
|
||||||
@file.should == @tempfile.path
|
@file.should == @tempfile.path
|
||||||
@line.should == 14
|
@line.should == 14
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly find an instance method" do
|
it "should correctly find an instance method" do
|
||||||
mock_pry("edit-method X#x")
|
pry_eval 'edit-method X#x'
|
||||||
@file.should == @tempfile.path
|
@file.should == @tempfile.path
|
||||||
@line.should == 18
|
@line.should == 18
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly find a method on an instance" do
|
it "should correctly find a method on an instance" do
|
||||||
mock_pry("x = X.new", "edit-method x.x")
|
pry_eval 'x = X.new', 'edit-method x.x'
|
||||||
@file.should == @tempfile.path
|
@file.should == @tempfile.path
|
||||||
@line.should == 18
|
@line.should == 18
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly find a method from a module" do
|
it "should correctly find a method from a module" do
|
||||||
mock_pry("edit-method X#a")
|
pry_eval 'edit-method X#a'
|
||||||
@file.should == @tempfile.path
|
@file.should == @tempfile.path
|
||||||
@line.should == 2
|
@line.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly find an aliased method" do
|
it "should correctly find an aliased method" do
|
||||||
mock_pry("edit-method X#c")
|
pry_eval 'edit-method X#c'
|
||||||
@file.should == @tempfile.path
|
@file.should == @tempfile.path
|
||||||
@line.should == 22
|
@line.should == 22
|
||||||
end
|
end
|
||||||
|
@ -407,7 +407,7 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should successfully replace a class method" do
|
it "should successfully replace a class method" do
|
||||||
mock_pry("edit-method -p X.x")
|
pry_eval 'edit-method -p X.x'
|
||||||
|
|
||||||
class << X
|
class << X
|
||||||
X.method(:x).owner.should == self
|
X.method(:x).owner.should == self
|
||||||
|
@ -417,14 +417,14 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should successfully replace an instance method" do
|
it "should successfully replace an instance method" do
|
||||||
mock_pry("edit-method -p X#x")
|
pry_eval 'edit-method -p X#x'
|
||||||
|
|
||||||
X.instance_method(:x).owner.should == X
|
X.instance_method(:x).owner.should == X
|
||||||
X.new.x.should == :maybe
|
X.new.x.should == :maybe
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should successfully replace a method on an instance" do
|
it "should successfully replace a method on an instance" do
|
||||||
mock_pry("instance = X.new", "edit-method -p instance.x")
|
pry_eval 'instance = X.new', 'edit-method -p instance.x'
|
||||||
|
|
||||||
instance = X.new
|
instance = X.new
|
||||||
instance.method(:x).owner.should == X
|
instance.method(:x).owner.should == X
|
||||||
|
@ -432,21 +432,21 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should successfully replace a method from a module" do
|
it "should successfully replace a method from a module" do
|
||||||
mock_pry("edit-method -p X#a")
|
pry_eval 'edit-method -p X#a'
|
||||||
|
|
||||||
X.instance_method(:a).owner.should == A
|
X.instance_method(:a).owner.should == A
|
||||||
X.new.a.should == :maybe
|
X.new.a.should == :maybe
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should successfully replace a method with a question mark" do
|
it "should successfully replace a method with a question mark" do
|
||||||
mock_pry("edit-method -p X#y?")
|
pry_eval 'edit-method -p X#y?'
|
||||||
|
|
||||||
X.instance_method(:y?).owner.should == X
|
X.instance_method(:y?).owner.should == X
|
||||||
X.new.y?.should == :maybe
|
X.new.y?.should == :maybe
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should preserve module nesting" do
|
it "should preserve module nesting" do
|
||||||
mock_pry("edit-method -p X::B#foo")
|
pry_eval 'edit-method -p X::B#foo'
|
||||||
|
|
||||||
X::B.instance_method(:foo).owner.should == X::B
|
X::B.instance_method(:foo).owner.should == X::B
|
||||||
X::B.new.foo.should == :nawt
|
X::B.new.foo.should == :nawt
|
||||||
|
@ -470,7 +470,7 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should change the alias, but not the original, without breaking super" do
|
it "should change the alias, but not the original, without breaking super" do
|
||||||
mock_pry("edit-method -p X#c")
|
pry_eval 'edit-method -p X#c'
|
||||||
|
|
||||||
Pry::Method.from_str("X#c").alias?.should == true
|
Pry::Method.from_str("X#c").alias?.should == true
|
||||||
|
|
||||||
|
@ -493,9 +493,9 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should pass the editor a reloading arg" do
|
it "should pass the editor a reloading arg" do
|
||||||
mock_pry('edit-method X.x')
|
pry_eval 'edit-method X.x'
|
||||||
@reloading.should == true
|
@reloading.should == true
|
||||||
mock_pry('edit-method -n X.x')
|
pry_eval 'edit-method -n X.x'
|
||||||
@reloading.should == false
|
@reloading.should == false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue