Permalink
Browse files

Remove tmp dir after spec run

  • Loading branch information...
1 parent 8b9e2ed commit 943040af2c69d4458eb85c349efcc77903fb9ac7 @mynyml mynyml committed Aug 23, 2010
Showing with 13 additions and 18 deletions.
  1. +11 −17 test/event_handlers/test_darwin.rb
  2. +2 −1 test/test_helper.rb
View
28 test/event_handlers/test_darwin.rb
@@ -14,33 +14,27 @@ def restart() end #noop
class DarwinEventHandlerTest < MiniTest::Unit::TestCase
include Watchr
- private
-
def tempfile(name)
- file = Tempfile.new(name, tmpdir.to_s)
+ file = Tempfile.new(name, @root.to_s)
Pathname(file.path)
ensure
file.close
end
- # TODO clean up tmpdirs after tests run
- def tmpdir
- @@_tmpdir ||= Pathname(Dir.mktmpdir("watchrspecs_"))
- end
- alias :root :tmpdir
-
- #at_exit { @@_tmpdir.delete }
-
- public
-
def setup
+ @root = Pathname(Dir.mktmpdir("WATCHR_SPECS-"))
+
@now = Time.now
@handler = EventHandler::Darwin.new
@foo = tempfile('foo').expand_path
@bar = tempfile('bar').expand_path
end
+ def teardown
+ FileUtils.remove_entry_secure(@root.to_s)
+ end
+
test "listening triggers listening state" do
@handler.expects(:start)
@handler.listen([])
@@ -74,31 +68,31 @@ def setup
@handler.listen [ @foo, @bar ]
@handler.expects(:notify).with(@foo, :deleted)
- @handler.on_change [root]
+ @handler.on_change [@root]
end
test "modified file event" do
@foo.stubs(:mtime).returns(@now + 100)
@handler.expects(:notify).with(@foo, :modified)
@handler.listen [ @foo, @bar ]
- @handler.on_change [root]
+ @handler.on_change [@root]
end
test "accessed file event" do
@foo.stubs(:atime).returns(@now + 100)
@handler.expects(:notify).with(@foo, :accessed)
@handler.listen [ @foo, @bar ]
- @handler.on_change [root]
+ @handler.on_change [@root]
end
test "changed file event" do
@foo.stubs(:ctime).returns(@now + 100)
@handler.expects(:notify).with(@foo, :changed)
@handler.listen [ @foo, @bar ]
- @handler.on_change [root]
+ @handler.on_change [@root]
end
## internal
View
3 test/test_helper.rb
@@ -1,6 +1,7 @@
require 'pathname'
+require 'tmpdir'
require 'tempfile'
-require 'set'
+require 'fileutils'
require 'minitest/autorun'
require 'mocha'

0 comments on commit 943040a

Please sign in to comment.