diff options
author | wycats <wycats@gmail.com> | 2011-02-06 13:41:56 -0800 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2011-02-06 13:42:22 -0800 |
commit | 1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98 (patch) | |
tree | 4642ca3e6ffcbc86d6252f6f55555af0fceafa7e /activesupport/test | |
parent | 3026843dc1ff42a632ebe989e1f6dfadb0cd10a5 (diff) | |
download | rails-1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98.tar.gz rails-1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98.tar.bz2 rails-1fd9d978a737d36cf7cca698f0fcbfc6fcdbed98.zip |
Add initial FileWatcher implementation. The Backend is just an abstract implementation, which will be inherited by backends that do the heavy lifting.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/file_watcher_test.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/activesupport/test/file_watcher_test.rb b/activesupport/test/file_watcher_test.rb new file mode 100644 index 0000000000..54aa9f92f1 --- /dev/null +++ b/activesupport/test/file_watcher_test.rb @@ -0,0 +1,65 @@ +require 'abstract_unit' + +class FileWatcherTest < ActiveSupport::TestCase + class DumbBackend < ActiveSupport::FileWatcher::Backend + end + + def setup + @watcher = ActiveSupport::FileWatcher.new + + # In real life, the backend would take the path and use it to observe the file + # system. In our case, we will manually trigger the events for unit testing, + # so we can pass any path. + @backend = DumbBackend.new("RAILS_WOOT", @watcher) + + @payload = [] + @watcher.watch %r{^app/assets/.*\.scss$} do |pay| + pay.each do |status, files| + files.sort! + end + @payload << pay + end + end + + def test_one_change + @backend.trigger("app/assets/main.scss" => :changed) + assert_equal({:changed => ["app/assets/main.scss"]}, @payload.first) + end + + def test_multiple_changes + @backend.trigger("app/assets/main.scss" => :changed, "app/assets/javascripts/foo.coffee" => :changed) + assert_equal([{:changed => ["app/assets/main.scss"]}], @payload) + end + + def test_multiple_changes_match + @backend.trigger("app/assets/main.scss" => :changed, "app/assets/print.scss" => :changed, "app/assets/javascripts/foo.coffee" => :changed) + assert_equal([{:changed => ["app/assets/main.scss", "app/assets/print.scss"]}], @payload) + end + + def test_multiple_state_changes + @backend.trigger("app/assets/main.scss" => :created, "app/assets/print.scss" => :changed) + assert_equal([{:changed => ["app/assets/print.scss"], :created => ["app/assets/main.scss"]}], @payload) + end + + def test_more_blocks + payload = [] + @watcher.watch %r{^config/routes\.rb$} do |pay| + payload << pay + end + + @backend.trigger "config/routes.rb" => :changed + assert_equal [:changed => ["config/routes.rb"]], payload + assert_equal [], @payload + end + + def test_overlapping_watchers + payload = [] + @watcher.watch %r{^app/assets/main\.scss$} do |pay| + payload << pay + end + + @backend.trigger "app/assets/print.scss" => :changed, "app/assets/main.scss" => :changed + assert_equal [:changed => ["app/assets/main.scss"]], payload + assert_equal [:changed => ["app/assets/main.scss", "app/assets/print.scss"]], @payload + end +end |