2012-04-01 03:51:11 -04:00
|
|
|
require 'helper'
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
MyKlass = Class.new do
|
|
|
|
def hello
|
|
|
|
"timothy"
|
2012-04-01 03:51:11 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
def goodbye
|
|
|
|
"jenny"
|
|
|
|
end
|
|
|
|
def tea_tim?
|
|
|
|
"timothy"
|
|
|
|
end
|
|
|
|
def tea_time?
|
|
|
|
"polly"
|
|
|
|
end
|
|
|
|
end
|
2012-04-01 03:51:11 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
describe "find-method" do
|
|
|
|
describe "find matching methods by name regex (-n option)" do
|
|
|
|
it "should find a method by regex" do
|
|
|
|
pry_eval("find-method hell MyKlass").should =~
|
|
|
|
/MyKlass.*?hello/m
|
2012-04-01 03:51:11 -04:00
|
|
|
end
|
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "should NOT match a method that does not match the regex" do
|
|
|
|
pry_eval("find-method hell MyKlass").should.not =~
|
|
|
|
/MyKlass.*?goodbye/m
|
2012-04-01 03:51:11 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
end
|
2012-05-20 02:18:15 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
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
|
2012-05-20 02:18:15 -04:00
|
|
|
end
|
2012-07-19 02:30:16 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "should NOT match a method that does not match the regex" do
|
|
|
|
pry_eval("find-method timothy MyKlass").should.not =~
|
|
|
|
/MyKlass.*?goodbye/m
|
2012-07-19 02:30:16 -04:00
|
|
|
end
|
2012-04-01 03:51:11 -04:00
|
|
|
end
|
2012-04-01 15:30:17 -04:00
|
|
|
|
2013-10-24 01:58:26 -04:00
|
|
|
it "should work with badly behaved constants" do
|
|
|
|
MyKlass::X = Object.new
|
|
|
|
def (MyKlass::X).hash
|
|
|
|
raise "mooo"
|
|
|
|
end
|
|
|
|
|
|
|
|
pry_eval("find-method -c timothy MyKlass").should =~
|
|
|
|
/MyKlass.*?hello/m
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should escape regexes correctly" do
|
|
|
|
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
|
2012-04-01 19:21:37 -04:00
|
|
|
end
|
2013-10-24 01:58:26 -04:00
|
|
|
|
|
|
|
Object.remove_const(:MyKlass)
|