Skip to content

Commit

Permalink
Reset default_action when reparsing script
Browse files Browse the repository at this point in the history
  • Loading branch information
mynyml committed Sep 29, 2009
1 parent 7bad051 commit 8461353
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
9 changes: 3 additions & 6 deletions TODO.txt
@@ -1,12 +1,6 @@

* reset default_action when reparsing script
* def reset

* 1.9 compatibility

* version.watchr
* sync versions (gemspec & Watchr::VERSION)

* sometimes an action is fired without a file being saved
* buffer flushing issue?
* libev issue?
Expand Down Expand Up @@ -39,3 +33,6 @@

* memory profiling / benchmarks

* version.watchr
* sync versions (gemspec & Watchr::VERSION)

7 changes: 6 additions & 1 deletion lib/watchr/script.rb
Expand Up @@ -110,7 +110,7 @@ def default_action(&action)
def parse!
Watchr.debug('loading script file %s' % @path.to_s.inspect)

@rules.clear
reset
instance_eval(@path.read)

rescue Errno::ENOENT
Expand All @@ -120,6 +120,11 @@ def parse!
instance_eval(@path.read)
end

def reset
@default_action = lambda {}
@rules.clear
end

# Find an action corresponding to a path. The returned action is actually a
# wrapper around the rule's action, with the match_data prepopulated.
#
Expand Down
15 changes: 15 additions & 0 deletions test/test_script.rb
Expand Up @@ -49,6 +49,21 @@ def setup
script.action_for('abc').call.should be(:x)
end

test "resets state" do
@script.default_action { 'x' }
@script.watch('foo') { 'bar' }
@script.reset
@script.instance_variable_get(:@default_action).should be_kind_of(Proc)
@script.instance_variable_get(:@default_action).call.should be(nil)
@script.instance_variable_get(:@rules).should be([])
end

test "resets state on parse" do
@script.stubs(:instance_eval)
@script.expects(:reset)
@script.parse!
end

test "actions receive a MatchData object" do
@script.watch('de(.)') {|m| [m[0], m[1]] }
@script.action_for('def').call.should be(%w( def f ))
Expand Down

0 comments on commit 8461353

Please sign in to comment.