summaryrefslogtreecommitdiff
path: root/spec/ruby/language/delegation_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/delegation_spec.rb')
-rw-r--r--spec/ruby/language/delegation_spec.rb46
1 files changed, 25 insertions, 21 deletions
diff --git a/spec/ruby/language/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb
index c711a536c2..cd44956f5d 100644
--- a/spec/ruby/language/delegation_spec.rb
+++ b/spec/ruby/language/delegation_spec.rb
@@ -37,6 +37,16 @@ describe "delegation with def(...)" do
a.new.delegate(1, b: 2, &block).should == [[1], {b: 2}, block]
end
+ it "delegates with additional arguments" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(:first, :second, ...)
+ end
+ RUBY
+ a.new.delegate(1, b: 2).should == [[:first, :second, 1], {b: 2}, nil]
+ end
+
it "parses as open endless Range when brackets are omitted" do
a = Class.new(DelegationSpecs::Target)
suppress_warning do
@@ -99,13 +109,11 @@ describe "delegation with def(*)" do
a.new.delegate(0, 1).should == [[0, 1], {}, nil]
end
- ruby_version_is "3.3" do
- context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
- it "does not allow delegating rest" do
- -> {
- eval "def m(*); proc { |*| n(*) } end"
- }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/)
- end
+ context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
+ it "does not allow delegating rest" do
+ -> {
+ eval "def m(*); proc { |*| n(*) } end"
+ }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/)
end
end
end
@@ -122,13 +130,11 @@ describe "delegation with def(**)" do
a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil]
end
- ruby_version_is "3.3" do
- context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
- it "does not allow delegating kwargs" do
- -> {
- eval "def m(**); proc { |**| n(**) } end"
- }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/)
- end
+ context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
+ it "does not allow delegating kwargs" do
+ -> {
+ eval "def m(**); proc { |**| n(**) } end"
+ }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/)
end
end
end
@@ -146,13 +152,11 @@ describe "delegation with def(&)" do
a.new.delegate(&block).should == [[], {}, block]
end
- ruby_version_is "3.3" do
- context "within a block that accepts anonymous block within a method that accepts anonymous block" do
- it "does not allow delegating a block" do
- -> {
- eval "def m(&); proc { |&| n(&) } end"
- }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/)
- end
+ context "within a block that accepts anonymous block within a method that accepts anonymous block" do
+ it "does not allow delegating a block" do
+ -> {
+ eval "def m(&); proc { |&| n(&) } end"
+ }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/)
end
end
end