smparkes-watchr 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/History.txt +32 -0
- data/LICENSE +19 -0
- data/Manifest +30 -0
- data/README.rdoc +82 -0
- data/Rakefile +51 -0
- data/TODO.txt +40 -0
- data/bin/watchr +77 -0
- data/docs.watchr +26 -0
- data/gem.watchr +32 -0
- data/lib/watchr.rb +101 -0
- data/lib/watchr/controller.rb +93 -0
- data/lib/watchr/event_handlers/base.rb +48 -0
- data/lib/watchr/event_handlers/em.rb +147 -0
- data/lib/watchr/event_handlers/portable.rb +60 -0
- data/lib/watchr/event_handlers/rev.rb +104 -0
- data/lib/watchr/event_handlers/unix.rb +25 -0
- data/lib/watchr/script.rb +230 -0
- data/manifest.watchr +70 -0
- data/specs.watchr +38 -0
- data/test/README +11 -0
- data/test/event_handlers/test_base.rb +24 -0
- data/test/event_handlers/test_em.rb +162 -0
- data/test/event_handlers/test_portable.rb +142 -0
- data/test/event_handlers/test_rev.rb +162 -0
- data/test/test_controller.rb +130 -0
- data/test/test_helper.rb +60 -0
- data/test/test_script.rb +124 -0
- data/test/test_watchr.rb +60 -0
- data/watchr.gemspec +64 -0
- metadata +141 -0
data/test/test_script.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestScript < Test::Unit::TestCase
|
4
|
+
include Watchr
|
5
|
+
|
6
|
+
def setup
|
7
|
+
tmpfile = Tempfile.new('foo')
|
8
|
+
@script = Script.new( Pathname.new( tmpfile.path ) )
|
9
|
+
end
|
10
|
+
|
11
|
+
## external api
|
12
|
+
|
13
|
+
test "watch" do
|
14
|
+
@script.watch('pattern')
|
15
|
+
@script.watch('pattern', :event_type)
|
16
|
+
@script.watch('pattern') { nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "default action" do
|
20
|
+
@script.default_action { nil }
|
21
|
+
end
|
22
|
+
|
23
|
+
## functionality
|
24
|
+
|
25
|
+
test "rule object" do
|
26
|
+
rule = @script.watch('pattern', :modified) { nil }
|
27
|
+
rule.pattern.should be('pattern')
|
28
|
+
rule.event_type.should be(:modified)
|
29
|
+
rule.action.call.should be(nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "default event type" do
|
33
|
+
rule = @script.watch('pattern') { nil }
|
34
|
+
rule.event_type.should be(:modified)
|
35
|
+
end
|
36
|
+
|
37
|
+
test "finds action for path" do
|
38
|
+
@script.watch('abc') { :x }
|
39
|
+
@script.watch('def') { :y }
|
40
|
+
@script.call_action_for('abc').should be(:x)
|
41
|
+
end
|
42
|
+
|
43
|
+
test "finds action for path with event type" do
|
44
|
+
@script.watch('abc', :accessed) { :x }
|
45
|
+
@script.watch('abc', :modified) { :y }
|
46
|
+
@script.call_action_for('abc', :accessed).should be(:x)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "finds action for path with any event type" do
|
50
|
+
@script.watch('abc', nil) { :x }
|
51
|
+
@script.watch('abc', :modified) { :y }
|
52
|
+
@script.call_action_for('abc', :accessed).should be(:x)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "no action for path" do
|
56
|
+
@script.watch('abc', :accessed) { :x }
|
57
|
+
@script.call_action_for('abc', :modified).should be(nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
test "collects patterns" do
|
61
|
+
@script.watch('abc')
|
62
|
+
@script.watch('def')
|
63
|
+
@script.patterns.should include('abc')
|
64
|
+
@script.patterns.should include('def')
|
65
|
+
end
|
66
|
+
|
67
|
+
test "parses script file" do
|
68
|
+
file = Pathname( Tempfile.open('bar').path )
|
69
|
+
file.open('w') {|f| f.write <<-STR }
|
70
|
+
watch( 'abc' ) { :x }
|
71
|
+
STR
|
72
|
+
script = Script.new(file)
|
73
|
+
script.parse!
|
74
|
+
script.call_action_for('abc').should be(:x)
|
75
|
+
end
|
76
|
+
|
77
|
+
test "resets state" do
|
78
|
+
@script.default_action { 'x' }
|
79
|
+
@script.watch('foo') { 'bar' }
|
80
|
+
@script.send(:reset)
|
81
|
+
@script.instance_variable_get(:@default_action).call.should be(nil)
|
82
|
+
@script.instance_variable_get(:@rules).should be([])
|
83
|
+
end
|
84
|
+
|
85
|
+
test "resets state on parse" do
|
86
|
+
@script.stubs(:instance_eval)
|
87
|
+
@script.expects(:reset)
|
88
|
+
@script.parse!
|
89
|
+
end
|
90
|
+
|
91
|
+
test "actions receive a MatchData object" do
|
92
|
+
@script.watch('de(.)') {|m| [m[0], m[1]] }
|
93
|
+
@script.call_action_for('def').should be(%w( def f ))
|
94
|
+
end
|
95
|
+
|
96
|
+
test "rule's default action" do
|
97
|
+
@script.watch('abc')
|
98
|
+
@script.call_action_for('abc').should be(nil)
|
99
|
+
@script.default_action { :x }
|
100
|
+
|
101
|
+
@script.watch('def')
|
102
|
+
@script.call_action_for('def').should be(:x)
|
103
|
+
end
|
104
|
+
|
105
|
+
test "file path" do
|
106
|
+
Script.any_instance.stubs(:parse!)
|
107
|
+
path = Pathname('some/file').expand_path
|
108
|
+
script = Script.new(path)
|
109
|
+
script.path.should be(path)
|
110
|
+
end
|
111
|
+
|
112
|
+
test "later rules take precedence" do
|
113
|
+
@script.watch('a/(.*)\.x') { :x }
|
114
|
+
@script.watch('a/b/(.*)\.x') { :y }
|
115
|
+
|
116
|
+
@script.call_action_for('a/b/c.x').should be(:y)
|
117
|
+
end
|
118
|
+
|
119
|
+
test "rule patterns match against paths relative to pwd" do
|
120
|
+
@script.watch('^abc') { :x }
|
121
|
+
path = Pathname(Dir.pwd) + 'abc'
|
122
|
+
@script.call_action_for(path).should be(:x)
|
123
|
+
end
|
124
|
+
end
|
data/test/test_watchr.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestWatchr < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Watchr.options = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
## options
|
10
|
+
|
11
|
+
test "debug option" do
|
12
|
+
Watchr.options.debug.should be(false)
|
13
|
+
Watchr.options.debug = true
|
14
|
+
Watchr.options.debug.should be(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
## functionality
|
18
|
+
|
19
|
+
test "debug" do
|
20
|
+
capture_io { Watchr.debug('abc') }.stdout.should be('')
|
21
|
+
Watchr.options.debug = true
|
22
|
+
capture_io { Watchr.debug('abc') }.stdout.should be("[watchr debug] abc\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
test "picking handler" do
|
26
|
+
|
27
|
+
Watchr.handler = nil
|
28
|
+
ENV['HANDLER'] = 'linux'
|
29
|
+
Watchr.handler.should be(HAVE_REV ? Watchr::EventHandler::Rev : Watchr::EventHandler::Portable)
|
30
|
+
|
31
|
+
Watchr.handler = nil
|
32
|
+
ENV['HANDLER'] = 'bsd'
|
33
|
+
Watchr.handler.should be(HAVE_REV ? Watchr::EventHandler::Rev : Watchr::EventHandler::Portable)
|
34
|
+
|
35
|
+
Watchr.handler = nil
|
36
|
+
ENV['HANDLER'] = 'darwin'
|
37
|
+
Watchr.handler.should be(HAVE_REV ? Watchr::EventHandler::Rev : Watchr::EventHandler::Portable)
|
38
|
+
|
39
|
+
Watchr.handler = nil
|
40
|
+
ENV['HANDLER'] = 'unix'
|
41
|
+
Watchr.handler.should be(HAVE_REV ? Watchr::EventHandler::Rev : Watchr::EventHandler::Portable)
|
42
|
+
|
43
|
+
Watchr.handler = nil
|
44
|
+
ENV['HANDLER'] = 'mswin'
|
45
|
+
Watchr.handler.should be(Watchr::EventHandler::Portable)
|
46
|
+
|
47
|
+
Watchr.handler = nil
|
48
|
+
ENV['HANDLER'] = 'cygwin'
|
49
|
+
Watchr.handler.should be(Watchr::EventHandler::Portable)
|
50
|
+
|
51
|
+
Watchr.handler = nil
|
52
|
+
ENV['HANDLER'] = 'portable'
|
53
|
+
Watchr.handler.should be(Watchr::EventHandler::Portable)
|
54
|
+
|
55
|
+
Watchr.handler = nil
|
56
|
+
ENV['HANDLER'] = 'other'
|
57
|
+
Watchr.handler.should be(Watchr::EventHandler::Portable)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/watchr.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'smparkes-watchr'
|
4
|
+
s.version = '0.5.7'
|
5
|
+
s.summary = "Modern continious testing (flexible alternative to autotest)"
|
6
|
+
s.description = "Modern continious testing (flexible alternative to autotest)."
|
7
|
+
s.author = "mynyml"
|
8
|
+
s.email = 'mynyml@gmail.com'
|
9
|
+
s.homepage = 'http://mynyml.com/ruby/flexible-continuous-testing'
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.rdoc_options = %w( --main README.rdoc )
|
12
|
+
s.extra_rdoc_files = %w( README.rdoc )
|
13
|
+
s.require_path = "lib"
|
14
|
+
s.bindir = "bin"
|
15
|
+
s.executables = "watchr"
|
16
|
+
s.files = %w[
|
17
|
+
.gitignore
|
18
|
+
History.txt
|
19
|
+
LICENSE
|
20
|
+
Manifest
|
21
|
+
README.rdoc
|
22
|
+
Rakefile
|
23
|
+
TODO.txt
|
24
|
+
bin/watchr
|
25
|
+
docs.watchr
|
26
|
+
gem.watchr
|
27
|
+
lib/watchr.rb
|
28
|
+
lib/watchr/controller.rb
|
29
|
+
lib/watchr/event_handlers/base.rb
|
30
|
+
lib/watchr/event_handlers/portable.rb
|
31
|
+
lib/watchr/event_handlers/unix.rb
|
32
|
+
lib/watchr/event_handlers/em.rb
|
33
|
+
lib/watchr/event_handlers/rev.rb
|
34
|
+
lib/watchr/script.rb
|
35
|
+
manifest.watchr
|
36
|
+
specs.watchr
|
37
|
+
test/README
|
38
|
+
test/event_handlers/test_base.rb
|
39
|
+
test/event_handlers/test_portable.rb
|
40
|
+
test/event_handlers/test_em.rb
|
41
|
+
test/event_handlers/test_rev.rb
|
42
|
+
test/test_controller.rb
|
43
|
+
test/test_helper.rb
|
44
|
+
test/test_script.rb
|
45
|
+
test/test_watchr.rb
|
46
|
+
watchr.gemspec
|
47
|
+
]
|
48
|
+
s.test_files = %w[
|
49
|
+
test/test_helper.rb
|
50
|
+
test/test_watchr.rb
|
51
|
+
test/test_script.rb
|
52
|
+
test/test_controller.rb
|
53
|
+
test/event_handlers/test_base.rb
|
54
|
+
test/event_handlers/test_em.rb
|
55
|
+
test/event_handlers/test_rev.rb
|
56
|
+
test/event_handlers/test_portable.rb
|
57
|
+
]
|
58
|
+
|
59
|
+
s.add_development_dependency 'mocha'
|
60
|
+
s.add_development_dependency 'jeremymcanally-matchy'
|
61
|
+
s.add_development_dependency 'jeremymcanally-pending'
|
62
|
+
s.add_development_dependency 'mynyml-every'
|
63
|
+
s.add_development_dependency 'mynyml-redgreen'
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smparkes-watchr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mynyml
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-02 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mocha
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jeremymcanally-matchy
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeremymcanally-pending
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: mynyml-every
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mynyml-redgreen
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
description: Modern continious testing (flexible alternative to autotest).
|
66
|
+
email: mynyml@gmail.com
|
67
|
+
executables:
|
68
|
+
- watchr
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.rdoc
|
73
|
+
files:
|
74
|
+
- .gitignore
|
75
|
+
- History.txt
|
76
|
+
- LICENSE
|
77
|
+
- Manifest
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- TODO.txt
|
81
|
+
- bin/watchr
|
82
|
+
- docs.watchr
|
83
|
+
- gem.watchr
|
84
|
+
- lib/watchr.rb
|
85
|
+
- lib/watchr/controller.rb
|
86
|
+
- lib/watchr/event_handlers/base.rb
|
87
|
+
- lib/watchr/event_handlers/portable.rb
|
88
|
+
- lib/watchr/event_handlers/unix.rb
|
89
|
+
- lib/watchr/event_handlers/em.rb
|
90
|
+
- lib/watchr/event_handlers/rev.rb
|
91
|
+
- lib/watchr/script.rb
|
92
|
+
- manifest.watchr
|
93
|
+
- specs.watchr
|
94
|
+
- test/README
|
95
|
+
- test/event_handlers/test_base.rb
|
96
|
+
- test/event_handlers/test_portable.rb
|
97
|
+
- test/event_handlers/test_em.rb
|
98
|
+
- test/event_handlers/test_rev.rb
|
99
|
+
- test/test_controller.rb
|
100
|
+
- test/test_helper.rb
|
101
|
+
- test/test_script.rb
|
102
|
+
- test/test_watchr.rb
|
103
|
+
- watchr.gemspec
|
104
|
+
has_rdoc: true
|
105
|
+
homepage: http://mynyml.com/ruby/flexible-continuous-testing
|
106
|
+
licenses: []
|
107
|
+
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options:
|
110
|
+
- --main
|
111
|
+
- README.rdoc
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
version:
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: "0"
|
125
|
+
version:
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.3.5
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Modern continious testing (flexible alternative to autotest)
|
133
|
+
test_files:
|
134
|
+
- test/test_helper.rb
|
135
|
+
- test/test_watchr.rb
|
136
|
+
- test/test_script.rb
|
137
|
+
- test/test_controller.rb
|
138
|
+
- test/event_handlers/test_base.rb
|
139
|
+
- test/event_handlers/test_em.rb
|
140
|
+
- test/event_handlers/test_rev.rb
|
141
|
+
- test/event_handlers/test_portable.rb
|