2014-03-14 00:31:24 -04:00
|
|
|
require_relative '../helper'
|
2013-03-28 03:31:04 -04: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
|
|
|
|
@x.test.should == :before
|
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
|
|
|
@x.test.should == :after
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a new method with new source" do
|
|
|
|
@method.source.strip.should == "def @x.test; :before; end"
|
|
|
|
@method.redefine("def @x.test; :after; end\n").
|
|
|
|
source.strip.should == "def @x.test; :after; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should change the source of new Pry::Method objects" do
|
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
|
|
|
Pry::Method(@x.method(:test)).source.strip.should == "def @x.test; :after; end"
|
|
|
|
end
|
2013-03-30 20:42:46 -04:00
|
|
|
|
|
|
|
it "should preserve visibility" do
|
|
|
|
class << @x; private :test; end
|
|
|
|
@method.visibility.should == :private
|
|
|
|
@method.redefine "def @x.test; :after; end\n"
|
|
|
|
Pry::Method(@x.method(:test)).visibility.should == :private
|
|
|
|
end
|
2013-03-28 03:31:04 -04:00
|
|
|
end
|