Created
November 2, 2010 23:07
-
-
Save joonyou/660488 to your computer and use it in GitHub Desktop.
calling method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class Victim | |
def called_name | |
caller_name = caller[0].scan(/\`.*\'/).first.gsub(/\`|\'/,"") rescue "outside of self" | |
if caller_name =="my_caller" | |
"looks like it's called from my_caller" | |
else | |
"who's calling me? #{caller_name} is" | |
end | |
end | |
def my_caller | |
called_name | |
end | |
end | |
describe "called from another method" do | |
it "should return my_caller" do | |
Victim.new.my_caller.should eql("looks like it's called from my_caller") | |
end | |
it "should return name of method" do | |
Victim.new.called_name.should eql("who's calling me? outside of self is") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment