1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/spec/method/patcher_spec.rb
Kyrylo Silin 18c45d26c5 rubocop: enable the Style/FrozenStringLiteralComment cop
This will greatly ease Pry support on Ruby 3.0 (when it's out).
2019-05-08 00:13:17 +03:00

37 lines
1.2 KiB
Ruby

# frozen_string_literal: true
describe Pry::Method::Patcher do
# rubocop:disable Style/SingleLineMethods
before do
@x = Object.new
def @x.test; :before; end
@method = Pry::Method(@x.method(:test))
end
# rubocop:enable Style/SingleLineMethods
it "should change the behaviour of the method" do
expect(@x.test).to eq :before
@method.redefine "def @x.test; :after; end\n"
expect(@x.test).to eq :after
end
it "should return a new method with new source" do
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"
end
it "should change the source of new Pry::Method objects" do
@method.redefine "def @x.test; :after; end\n"
expect(Pry::Method(@x.method(:test)).source.strip).to eq "def @x.test; :after; end"
end
it "should preserve visibility" do
class << @x
private :test # rubocop:disable Style/AccessModifierDeclarations
end
expect(@method.visibility).to eq :private
@method.redefine "def @x.test; :after; end\n"
expect(Pry::Method(@x.method(:test)).visibility).to eq :private
end
end