Skip to content

Instantly share code, notes, and snippets.

@willnet
Created October 19, 2016 02:40
Show Gist options
  • Select an option

  • Save willnet/d0c5e3014728db979d71c8cf94acc219 to your computer and use it in GitHub Desktop.

Select an option

Save willnet/d0c5e3014728db979d71c8cf94acc219 to your computer and use it in GitHub Desktop.
# ここに with の定義を書く
require 'test/unit'
require_relative 'with'
class TestWith < Test::Unit::TestCase
class Resource
def dispose
@disposed = true
end
def disposed?
@disposed
end
end
def test_disposed_of_resources
r = Resource.new
with(r) {}
assert r.disposed?
end
def test_disposed_of_resources_in_case_of_exception
r = Resource.new
assert_raises(Exception) {
with(r) {
raise Exception
}
}
assert r.disposed?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment