Skip to content

Commit

Permalink
Remove tmp dir after spec run
Browse files Browse the repository at this point in the history
  • Loading branch information
mynyml committed Aug 23, 2010
1 parent 8b9e2ed commit 943040a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
28 changes: 11 additions & 17 deletions test/event_handlers/test_darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'pathname'
require 'tmpdir'
require 'tempfile'
require 'set'
require 'fileutils'

require 'minitest/autorun'
require 'mocha'
Expand Down

0 comments on commit 943040a

Please sign in to comment.