Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tests for correctly retrieving block arguments.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
  • Loading branch information...
commit fdd376eb06fa67c567f1d261b334b57ec35b3d01 1 parent 215c42d
@YorickPeterse YorickPeterse authored
View
15 spec/core/unboundmethod/fixtures/classes.rb
@@ -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,12 +17,17 @@ 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
@@ -30,6 +35,10 @@ 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
View
14 spec/core/unboundmethod/parameters_spec.rb
@@ -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
View
2  spec/custom/helpers/generator.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.