Created
October 19, 2016 02:40
-
-
Save willnet/d0c5e3014728db979d71c8cf94acc219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ここに with の定義を書く |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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