1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/spec/commands/find_method_spec.rb

71 lines
2 KiB
Ruby
Raw Normal View History

require 'helper'
# we turn off the test for MRI 1.8 because our source_location hack
# for C methods actually runs the methods - and since it runs ALL
# methods (in an attempt to find a match) it runs 'exit' and aborts
# the test, causing a failure. We should fix this in the future by
# blacklisting certain methods for 1.8 MRI (such as exit, fork, and so on)
2012-04-13 02:29:35 -04:00
unless Pry::Helpers::BaseHelpers.mri_18?
MyKlass = Class.new do
def hello
"timothy"
end
def goodbye
"jenny"
end
def tea_tim?
"timothy"
end
def tea_time?
"polly"
end
end
describe "find-method" do
describe "find matching methods by name regex (-n option)" do
it "should find a method by regex" do
2012-08-04 19:26:57 -04:00
pry_eval("find-method hell MyKlass").should =~
/MyKlass.*?hello/m
end
it "should NOT match a method that does not match the regex" do
2012-08-04 19:26:57 -04:00
pry_eval("find-method hell MyKlass").should.not =~
/MyKlass.*?goodbye/m
end
end
describe "find matching methods by content regex (-c option)" do
it "should find a method by regex" do
2012-08-04 19:26:57 -04:00
pry_eval("find-method -c timothy MyKlass").should =~
/MyKlass.*?hello/m
end
it "should NOT match a method that does not match the regex" do
2012-08-04 19:26:57 -04:00
pry_eval("find-method timothy MyKlass").should.not =~
/MyKlass.*?goodbye/m
end
end
2012-05-20 02:18:15 -04:00
it "should work with badly behaved constants" do
MyKlass::X = Object.new
def (MyKlass::X).hash
raise "mooo"
end
2012-08-04 19:26:57 -04:00
pry_eval("find-method -c timothy MyKlass").should =~
/MyKlass.*?hello/m
2012-05-20 02:18:15 -04:00
end
it "should escape regexes correctly" do
2012-08-04 19:26:57 -04:00
good = /tea_time\?/
bad = /tea_tim\?/
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time? MyKlass').should =~ good
pry_eval('find-method tea_time\? MyKlass').should.not =~ bad
pry_eval('find-method tea_time\? MyKlass').should =~ good
end
end
Object.remove_const(:MyKlass)
end