ruby/spec/rubyspec/language/fixtures/ensure.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

72 lines
1.1 KiB
Ruby

module EnsureSpec
class Container
attr_reader :executed
def initialize
@executed = []
end
def raise_in_method_with_ensure
@executed << :method
raise "An Exception"
ensure
@executed << :ensure
end
def raise_and_rescue_in_method_with_ensure
@executed << :method
raise "An Exception"
rescue
@executed << :rescue
ensure
@executed << :ensure
end
def throw_in_method_with_ensure
@executed << :method
throw(:symbol)
ensure
@executed << :ensure
end
def implicit_return_in_method_with_ensure
:method
ensure
:ensure
end
def explicit_return_in_method_with_ensure
return :method
ensure
return :ensure
end
end
end
module EnsureSpec
class Test
def initialize
@values = []
end
attr_reader :values
def call_block
begin
@values << :start
yield
ensure
@values << :end
end
end
def do_test
call_block do
@values << :in_block
return :did_test
end
end
end
end