diff options
Diffstat (limited to 'test/unit/test_util.rb')
-rw-r--r-- | test/unit/test_util.rb | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/test/unit/test_util.rb b/test/unit/test_util.rb index b267179..377f6b8 100644 --- a/test/unit/test_util.rb +++ b/test/unit/test_util.rb @@ -8,26 +8,29 @@ class TestUtil < Test::Unit::TestCase EXPECT_FLAGS = File::WRONLY | File::APPEND def test_reopen_logs_noop tmp = Tempfile.new('') - tmp.reopen(tmp.path, 'a') - tmp.sync = true - ext = tmp.external_encoding rescue nil - int = tmp.internal_encoding rescue nil - before = tmp.stat.inspect + fp = File.open(tmp.path, 'ab') + fp.sync = true + ext = fp.external_encoding rescue nil + int = fp.internal_encoding rescue nil + before = fp.stat.inspect Unicorn::Util.reopen_logs - assert_equal before, File.stat(tmp.path).inspect - assert_equal ext, (tmp.external_encoding rescue nil) - assert_equal int, (tmp.internal_encoding rescue nil) + assert_equal before, File.stat(fp.path).inspect + assert_equal ext, (fp.external_encoding rescue nil) + assert_equal int, (fp.internal_encoding rescue nil) + assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & fp.fcntl(Fcntl::F_GETFL)) assert_nothing_raised { tmp.close! } + assert_nothing_raised { fp.close } end def test_reopen_logs_renamed tmp = Tempfile.new('') tmp_path = tmp.path.freeze - tmp.reopen(tmp_path, 'a') - tmp.sync = true - ext = tmp.external_encoding rescue nil - int = tmp.internal_encoding rescue nil - before = tmp.stat.inspect + fp = File.open(tmp_path, 'ab') + fp.sync = true + + ext = fp.external_encoding rescue nil + int = fp.internal_encoding rescue nil + before = fp.stat.inspect to = Tempfile.new('') File.rename(tmp_path, to.path) assert ! File.exist?(tmp_path) @@ -35,13 +38,14 @@ class TestUtil < Test::Unit::TestCase assert_equal tmp_path, tmp.path assert File.exist?(tmp_path) assert before != File.stat(tmp_path).inspect - assert_equal tmp.stat.inspect, File.stat(tmp_path).inspect - assert_equal ext, (tmp.external_encoding rescue nil) - assert_equal int, (tmp.internal_encoding rescue nil) - assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & tmp.fcntl(Fcntl::F_GETFL)) - assert tmp.sync + assert_equal fp.stat.inspect, File.stat(tmp_path).inspect + assert_equal ext, (fp.external_encoding rescue nil) + assert_equal int, (fp.internal_encoding rescue nil) + assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & fp.fcntl(Fcntl::F_GETFL)) + assert fp.sync assert_nothing_raised { tmp.close! } assert_nothing_raised { to.close! } + assert_nothing_raised { fp.close } end def test_reopen_logs_renamed_with_encoding |