summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2010-12-17 02:58:01 +1300
committerJohn Mair <jrmair@gmail.com>2010-12-17 02:58:01 +1300
commit2895bb245fd216be96da6e4d6b9e361248934450 (patch)
treebd0a0480b25a3eb11f1aba0ef9fc2825a4a16d3b /test
downloadmethod_source-2895bb245fd216be96da6e4d6b9e361248934450.tar.gz
first commit
Diffstat (limited to 'test')
-rw-r--r--test/test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test.rb b/test/test.rb
new file mode 100644
index 0000000..8a4beaa
--- /dev/null
+++ b/test/test.rb
@@ -0,0 +1,32 @@
+direc = File.dirname(__FILE__)
+
+require 'bacon'
+require "#{direc}/../lib/method_source"
+
+hello_source = "def hello; :hello; end\n"
+
+def hello; :hello; end
+
+describe MethodSource do
+
+ it 'should define methods on both Method and UnboundMethod' do
+ Method.method_defined?(:source).should == true
+ UnboundMethod.method_defined?(:source).should == true
+ end
+
+ if RUBY_VERSION =~ /1.9/
+ it 'should return source for method' do
+ method(:hello).source.should == hello_source
+ end
+
+ it 'should raise for C methods' do
+ lambda { method(:puts).source }.should.raise RuntimeError
+ end
+
+ else
+ it 'should raise on #source' do
+ lambda { method(:hello).source }.should.raise RuntimeError
+ end
+ end
+end
+