Permalink
Browse files

Tests for correctly retrieving block arguments.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
  • Loading branch information...
YorickPeterse committed Mar 24, 2013
1 parent 215c42d commit fdd376eb06fa67c567f1d261b334b57ec35b3d01
@@ -2,10 +2,10 @@ module MethodSpecs
class SourceLocation
- def location # This needs to be on this line
+ def location # This needs to be on this line
:location # for the spec to pass
end
-
+
def redefined
:first
end
@@ -17,19 +17,28 @@ def redefined
def original
end
- alias :aka :original
+ alias :aka :original
end
class Methods
def zero; end
+
+ def zero_with_locals
+ number = 10
+ end
+
def one_req(a); end
def two_req(a, b); end
def zero_with_block(&block); end
def one_req_with_block(a, &block); end
def two_req_with_block(a, b, &block); end
+ def zero_with_block_and_locals(&block)
+ number = 10
+ end
+
def one_opt(a=nil); end
def one_req_one_opt(a, b=nil); end
def one_req_two_opt(a, b=nil, c=nil); end
@@ -7,6 +7,12 @@
MethodSpecs::Methods.instance_method(:zero).parameters.should == []
end
+ it "returns an empty Array when the method expects no arguments but does have local variables" do
+ m = MethodSpecs::Methods.instance_method(:zero_with_locals)
+
+ m.parameters.should == []
+ end
+
it "returns [[:req,:name]] for a method expecting one required argument called 'name'" do
MethodSpecs::Methods.instance_method(:one_req).parameters.should == [[:req,:a]]
end
@@ -21,6 +27,12 @@
m.parameters.should == [[:block,:block]]
end
+ it "returns [[:block,:block]] for a method expecting one block argument with local variables" do
+ m = MethodSpecs::Methods.instance_method(:zero_with_block_and_locals)
+
+ m.parameters.should == [[:block,:block]]
+ end
+
it "returns [[:req,:a],[:block,:b] for a method expecting a required argument ('a') and a block argument ('b')" do
m = MethodSpecs::Methods.instance_method(:one_req_with_block)
m.parameters.should == [[:req,:a], [:block,:block]]
@@ -126,4 +138,4 @@
m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c],[:rest,:d],[:block,:block]]
end
-end
+end
@@ -91,7 +91,7 @@ def send_vcall(meth)
attr_accessor :stream, :ip, :redo, :break, :next, :retry,
:name, :file, :line, :primitive, :for_block,
:required_args, :post_args, :total_args, :splat_index,
- :local_count, :local_names
+ :local_count, :local_names, :block_index
def initialize

0 comments on commit fdd376e

Please sign in to comment.