Permalink
Browse files

Add UnboundMethod#source_location specs

  • Loading branch information...
1 parent b3fb7ea commit 176f6623f0e3b82242b9cc9ace9e873db22e8ead @jfirebaugh jfirebaugh committed Mar 15, 2012
View
21 spec/ruby/core/unboundmethod/fixtures/classes.rb
@@ -1,4 +1,25 @@
module UnboundMethodSpecs
+
+
+ class SourceLocation
+ def self.location # This needs to be on this line
+ :location # for the spec to pass
+ end
+
+ def self.redefined
+ :first
+ end
+
+ def self.redefined
+ :last
+ end
+
+ def original
+ end
+
+ alias :aka :original
+ end
+
module Mod
def from_mod; end
end
View
25 spec/ruby/core/unboundmethod/source_location_spec.rb
@@ -1,8 +1,31 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is "1.9" do
describe "UnboundMethod#source_location" do
- it "needs to be reviewed for spec completeness"
+ before(:each) do
+ @method = UnboundMethodSpecs::SourceLocation.method(:location).unbind
+ end
+
+ it "sets the first value to the path of the file in which the method was defined" do
+ file = @method.source_location.first
+ file.should be_an_instance_of(String)
+ file.should == File.dirname(__FILE__) + '/fixtures/classes.rb'
+ end
+
+ it "sets the last value to a Fixnum representing the line on which the method was defined" do
+ line = @method.source_location.last
+ line.should be_an_instance_of(Fixnum)
+ line.should == 5
+ end
+
+ it "returns the last place the method was defined" do
+ UnboundMethodSpecs::SourceLocation.method(:redefined).unbind.source_location.last.should == 13
+ end
+
+ it "returns the location of the original method even if it was aliased" do
+ UnboundMethodSpecs::SourceLocation.instance_method(:aka).source_location.last.should == 17
+ end
it "works for define_method methods" do
line = nil

0 comments on commit 176f662

Please sign in to comment.