Sha256: b3e1c258dd87dce4d9adeffce6e727204d314a58cfe520eb14677713ed7bad72

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

direc = File.dirname(__FILE__)

require 'bacon'
require "#{direc}/../lib/method_source"

hello_source = "def hello; :hello; end\n"
lambda_source = "MyLambda = lambda { :lambda }\n"
proc_source = "MyProc = Proc.new { :proc }\n"

def hello; :hello; end

MyLambda = lambda { :lambda }
MyProc = Proc.new { :proc }

describe MethodSource do
  it 'should define methods on Method and UnboundMethod and Proc' do
    Method.method_defined?(:source).should == true
    UnboundMethod.method_defined?(:source).should == true
    Proc.method_defined?(:source).should == true
  end

  describe "Methods" do
    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

  describe "Lambdas and Procs" do
    if RUBY_VERSION =~ /1.9/
      it 'should return source for proc' do
        MyProc.source.should == proc_source
      end

      it 'should return source for lambda' do
        MyLambda.source.should == lambda_source
      end
    else
      it 'should raise on #source' do
        lambda { method(:hello).source }.should.raise RuntimeError
      end
    end      
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
method_source-0.1.4 test/test.rb
method_source-0.1.1 test/test.rb