test/test.rb in method_source-0.4.1 vs test/test.rb in method_source-0.6.0
- old
+ new
@@ -1,19 +1,28 @@
direc = File.dirname(__FILE__)
require 'rubygems'
require 'bacon'
+require 'open4'
require "#{direc}/../lib/method_source"
require "#{direc}/test_helper"
describe MethodSource do
+ describe "emitted warnings" do
+ it 'should emit no warnings' do
+ Open4.popen4 'ruby -I lib -rubygems -r"method_source" -W -e "exit"' do |pid,stdin,stdout,stderr|
+ stderr.read.empty?.should == true
+ end
+ end
+ end
+
describe "source_location (testing 1.8 implementation)" do
it 'should return correct source_location for a method' do
method(:hello).source_location.first.should =~ /test_helper/
end
-
+
it 'should not raise for immediate instance methods' do
[Symbol, Fixnum, TrueClass, FalseClass, NilClass].each do |immediate_class|
lambda { immediate_class.instance_method(:to_s).source_location }.should.not.raise
end
end
@@ -32,11 +41,11 @@
@hello_comment = "# A comment for hello\n# It spans two lines and is indented by 2 spaces\n"
@lambda_comment = "# This is a comment for MyLambda\n"
@lambda_source = "MyLambda = lambda { :lambda }\n"
@proc_source = "MyProc = Proc.new { :proc }\n"
end
-
+
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
@@ -55,40 +64,43 @@
end
it 'should return source for a singleton method' do
$o.method(:hello).source.should == @hello_singleton_source
end
-
-
+
+
it 'should return a comment for method' do
method(:hello).comment.should == @hello_comment
end
- it 'should raise for C methods' do
- lambda { method(:puts).source }.should.raise RuntimeError
+
+ if !is_rbx?
+ it 'should raise for C methods' do
+ lambda { method(:puts).source }.should.raise RuntimeError
+ end
end
end
- if RUBY_VERSION =~ /1.9/
+ # if RUBY_VERSION =~ /1.9/ || is_rbx?
describe "Lambdas and Procs" do
it 'should return source for proc' do
MyProc.source.should == @proc_source
end
-
+
it 'should return an empty string if there is no comment' do
MyProc.comment.should == ''
end
-
+
it 'should return source for lambda' do
MyLambda.source.should == @lambda_source
end
-
+
it 'should return comment for lambda' do
MyLambda.comment.should == @lambda_comment
end
- end
- end
+ end
+ # end
describe "Comment tests" do
before do
@comment1 = "# a\n# b\n"
@comment2 = "# a\n# b\n"
@comment3 = "# a\n#\n# b\n"
@@ -105,15 +117,15 @@
end
it "should keep empty comment lines" do
method(:comment_test3).comment.should == @comment3
end
-
+
it "should ignore blank lines between comments" do
method(:comment_test4).comment.should == @comment4
end
it "should align all comments to same indent level" do
method(:comment_test5).comment.should == @comment5
- end
+ end
end
end