From 420b4a738ef4e691fee95ee5c0878667f7dc4c9d Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Sun, 10 Oct 2021 12:46:31 -0400 Subject: [PATCH] add spec raising syntax error when defining yield in singleton class --- language/singleton_class_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/language/singleton_class_spec.rb b/language/singleton_class_spec.rb index 7e9370d6f9..324c55dc98 100644 --- a/language/singleton_class_spec.rb +++ b/language/singleton_class_spec.rb @@ -172,6 +172,21 @@ class << Object.new -> { eval(code) }.should complain(/warning: `yield' in class syntax will not be supported from Ruby 3.0/) end end + + ruby_version_is "3.0" do + it 'raises a SyntaxError' do + code = <<~RUBY + def m + class << Object.new + yield + end + end + m { :ok } + RUBY + + -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/) + end + end end describe "Defining instance methods on a singleton class" do