Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added helper Kernel#extract to work with method overloading (useful f…
…or complicated APIs like View#find)
- Loading branch information
Oleg Andreev
committed
May 1, 2008
1 parent
008157e
commit 8806a20
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
describe "Kernel#extract" do | ||
|
||
it "should correctly extract various arguments" do | ||
extract(Regexp, String, Hash, [ ]).should == [nil, nil, nil] | ||
|
||
extract(Regexp, String, Hash, [/a/ ]).should == [/a/, nil, nil] | ||
extract(Regexp, String, Hash, [ "a" ]).should == [nil, "a", nil] | ||
extract(Regexp, String, Hash, [ {1=>2}]).should == [nil, nil, {1=>2}] | ||
|
||
extract(Regexp, String, Hash, [//, "" ]).should == [//, "", nil] | ||
extract(Regexp, String, Hash, [//, {}]).should == [//, nil, {} ] | ||
extract(Regexp, String, Hash, [ "", {}]).should == [nil, "", {}] | ||
|
||
extract(Regexp, String, Hash, [//, "", {}]).should == [//, "", {} ] | ||
end | ||
|
||
it "should raise ArgumentError when wrong arguments are passed" do | ||
|
||
bad_case(Regexp, String, Hash, [123]) | ||
bad_case(Regexp, String, Hash, ["", //]) | ||
bad_case(Regexp, String, Hash, [{}, ""]) | ||
bad_case(Regexp, String, Hash, [true]) | ||
bad_case(Regexp, String, Hash, [false]) | ||
bad_case(Regexp, String, Hash, [//,false]) | ||
bad_case(Regexp, String, Hash, [nil]) | ||
bad_case(Regexp, String, Hash, ["", nil]) | ||
bad_case(Regexp, String, Hash, [nil, nil]) | ||
bad_case(Regexp, String, Hash, [{}, {}]) | ||
bad_case(Regexp, String, Hash, [//, //]) | ||
bad_case(Regexp, String, Hash, [ [] ]) | ||
bad_case(Regexp, String, Hash, [Object.new]) | ||
bad_case(Regexp, String, Hash, [Object.new, Object.new]) | ||
|
||
end | ||
|
||
def bad_case(*args) | ||
lambda { extract(*args) }.should raise_error(ArgumentError) | ||
end | ||
|
||
end |