summaryrefslogtreecommitdiff
path: root/spec/ruby/language/yield_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/yield_spec.rb')
-rw-r--r--spec/ruby/language/yield_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb
index 5fad7cb176..e125cf8e73 100644
--- a/spec/ruby/language/yield_spec.rb
+++ b/spec/ruby/language/yield_spec.rb
@@ -183,5 +183,38 @@ describe "The yield call" do
it "uses captured block of a block used in define_method" do
@y.deep(2).should == 4
end
+end
+
+describe "Using yield in a singleton class literal" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ class << Object.new
+ yield
+ end
+ RUBY
+
+ -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/)
+ end
+end
+
+describe "Using yield in non-lambda block" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ 1.times { yield }
+ RUBY
+ -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/)
+ end
+end
+
+describe "Using yield in a module literal" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ module YieldSpecs::ModuleWithYield
+ yield
+ end
+ RUBY
+
+ -> { eval(code) }.should raise_error(SyntaxError, /Invalid yield/)
+ end
end