2014-03-14 05:31:24 +01:00
|
|
|
require_relative '../helper'
|
2013-03-28 00:31:04 -07:00
|
|
|
|
|
|
|
describe Pry::Method::Patcher do
|
|
|
|
|
|
|
|
before do
|
|
|
|
@x = Object.new
|
|
|
|
def @x.test; :before; end
|
|
|
|
@method = Pry::Method(@x.method(:test))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should change the behaviour of the method" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@x.test).to eq :before
|
2013-03-28 00:31:04 -07:00
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@x.test).to eq :after
|
2013-03-28 00:31:04 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a new method with new source" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@method.source.strip).to eq "def @x.test; :before; end"
|
|
|
|
expect(@method.redefine("def @x.test; :after; end\n").
|
|
|
|
source.strip).to eq "def @x.test; :after; end"
|
2013-03-28 00:31:04 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should change the source of new Pry::Method objects" do
|
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(Pry::Method(@x.method(:test)).source.strip).to eq "def @x.test; :after; end"
|
2013-03-28 00:31:04 -07:00
|
|
|
end
|
2013-03-30 17:42:46 -07:00
|
|
|
|
|
|
|
it "should preserve visibility" do
|
|
|
|
class << @x; private :test; end
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@method.visibility).to eq :private
|
2013-03-30 17:42:46 -07:00
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(Pry::Method(@x.method(:test)).visibility).to eq :private
|
2013-03-30 17:42:46 -07:00
|
|
|
end
|
2013-03-28 00:31:04 -07:00
|
|
|
end
|