nestor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +34 -0
  5. data/Rakefile +76 -0
  6. data/VERSION +1 -0
  7. data/bin/nestor +3 -0
  8. data/doc/.gitignore +3 -0
  9. data/doc/state-diagram.graffle +3870 -0
  10. data/doc/state-diagram.png +0 -0
  11. data/lib/nestor/cli.rb +52 -0
  12. data/lib/nestor/machine.rb +161 -0
  13. data/lib/nestor/strategies/test/unit.rb +116 -0
  14. data/lib/nestor/strategies.rb +18 -0
  15. data/lib/nestor/watchers/rails.rb +56 -0
  16. data/lib/nestor/watchers/rails_script.rb +83 -0
  17. data/lib/nestor/watchers.rb +1 -0
  18. data/lib/nestor.rb +11 -0
  19. data/spec/machine_spec.rb +56 -0
  20. data/spec/spec_helper.rb +9 -0
  21. data/vendor/watchr-0.5.7/.gitignore +5 -0
  22. data/vendor/watchr-0.5.7/History.txt +32 -0
  23. data/vendor/watchr-0.5.7/LICENSE +19 -0
  24. data/vendor/watchr-0.5.7/Manifest +27 -0
  25. data/vendor/watchr-0.5.7/README.rdoc +108 -0
  26. data/vendor/watchr-0.5.7/Rakefile +49 -0
  27. data/vendor/watchr-0.5.7/TODO.txt +40 -0
  28. data/vendor/watchr-0.5.7/bin/watchr +77 -0
  29. data/vendor/watchr-0.5.7/docs.watchr +26 -0
  30. data/vendor/watchr-0.5.7/gem.watchr +32 -0
  31. data/vendor/watchr-0.5.7/lib/watchr/controller.rb +81 -0
  32. data/vendor/watchr-0.5.7/lib/watchr/event_handlers/base.rb +48 -0
  33. data/vendor/watchr-0.5.7/lib/watchr/event_handlers/portable.rb +55 -0
  34. data/vendor/watchr-0.5.7/lib/watchr/event_handlers/unix.rb +97 -0
  35. data/vendor/watchr-0.5.7/lib/watchr/script.rb +203 -0
  36. data/vendor/watchr-0.5.7/lib/watchr.rb +113 -0
  37. data/vendor/watchr-0.5.7/manifest.watchr +70 -0
  38. data/vendor/watchr-0.5.7/specs.watchr +38 -0
  39. data/vendor/watchr-0.5.7/test/README +11 -0
  40. data/vendor/watchr-0.5.7/test/event_handlers/test_base.rb +24 -0
  41. data/vendor/watchr-0.5.7/test/event_handlers/test_portable.rb +58 -0
  42. data/vendor/watchr-0.5.7/test/event_handlers/test_unix.rb +162 -0
  43. data/vendor/watchr-0.5.7/test/test_controller.rb +103 -0
  44. data/vendor/watchr-0.5.7/test/test_helper.rb +52 -0
  45. data/vendor/watchr-0.5.7/test/test_script.rb +123 -0
  46. data/vendor/watchr-0.5.7/test/test_watchr.rb +60 -0
  47. data/vendor/watchr-0.5.7/watchr.gemspec +60 -0
  48. metadata +152 -0
@@ -0,0 +1,103 @@
1
+ require 'test/test_helper'
2
+ require 'observer'
3
+
4
+ class MockHandler
5
+ include Observable
6
+ def listen(paths) end
7
+ def refresh(paths) end
8
+ end
9
+
10
+ class TestController < Test::Unit::TestCase
11
+ include Watchr
12
+
13
+ def to_p(str)
14
+ Pathname(str).expand_path
15
+ end
16
+
17
+ def setup
18
+ tmpfile = Tempfile.new('foo')
19
+ @script = Script.new( Pathname.new( tmpfile.path ) )
20
+ @handler = MockHandler.new
21
+ @controller = Controller.new(@script, @handler)
22
+ end
23
+
24
+ test "triggers listening state on run" do
25
+ @controller.stubs(:monitored_paths).returns %w( foo bar )
26
+ @handler.expects(:listen).with %w( foo bar )
27
+ @controller.run
28
+ end
29
+
30
+ test "adds itself as handler observer" do
31
+ @handler.count_observers.should be(1)
32
+ @handler.delete_observer(@controller)
33
+ @handler.count_observers.should be(0)
34
+ end
35
+
36
+ ## monitored paths list
37
+
38
+ test "fetches monitored paths" do
39
+ Dir.expects(:[]).at_least_once.with('**/*').returns(%w(
40
+ a
41
+ b/x.z
42
+ b/c
43
+ b/c/y.z
44
+ ))
45
+ @script.watch('.\.z') { :x }
46
+
47
+ contrl = Controller.new(@script, MockHandler.new)
48
+ contrl.monitored_paths.should include(to_p('b/x.z'))
49
+ contrl.monitored_paths.should include(to_p('b/c/y.z'))
50
+ end
51
+
52
+ test "doesn't fetch unmonitored paths" do
53
+ Dir.expects(:[]).at_least_once.with('**/*').returns(%w(
54
+ a
55
+ b/x.z
56
+ b/c
57
+ b/c/y.z
58
+ ))
59
+ @script.watch('.\.z') { :x }
60
+
61
+ contrl = Controller.new(@script, MockHandler.new)
62
+ contrl.monitored_paths.should exclude(to_p('a'))
63
+ contrl.monitored_paths.should exclude(to_p('b/c'))
64
+ contrl.monitored_paths.should exclude(to_p('p/q.z'))
65
+ end
66
+
67
+ test "monitored paths include script" do
68
+ Dir.expects(:[]).at_least_once.with('**/*').returns(%w( a ))
69
+ Script.any_instance.stubs(:parse!)
70
+
71
+ path = to_p('some/file')
72
+ script = Script.new(path)
73
+ contrl = Controller.new(script, MockHandler.new)
74
+ contrl.monitored_paths.should include(path)
75
+ end
76
+
77
+ ## on update
78
+
79
+ test "calls action for path" do
80
+ path = to_p('abc')
81
+ @script.expects(:action_for).with(path, :modified).returns(lambda {})
82
+
83
+ @controller.update('abc', :modified)
84
+ end
85
+
86
+ test "parses script on script file update" do
87
+ path = to_p('abc')
88
+ @script.stubs(:path).returns(path)
89
+ @script.expects(:parse!)
90
+
91
+ @controller.update('abc')
92
+ end
93
+
94
+ test "refreshes handler on script file update" do
95
+ path = to_p('abc')
96
+ @script.stubs(:path).returns(path)
97
+ @controller.stubs(:monitored_paths).returns %w( foo bar )
98
+
99
+ @handler.expects(:refresh).with %w( foo bar )
100
+ @controller.update(path)
101
+ end
102
+ end
103
+
@@ -0,0 +1,52 @@
1
+ require 'pathname'
2
+ require 'tempfile'
3
+ require 'test/unit'
4
+
5
+ require 'matchy'
6
+ require 'mocha'
7
+ require 'every'
8
+ require 'pending'
9
+ begin
10
+ require 'redgreen'
11
+ require 'phocus'
12
+ require 'ruby-debug'
13
+ rescue LoadError, RuntimeError
14
+ end
15
+
16
+ root = Pathname(__FILE__).dirname.parent.expand_path
17
+ $:.unshift(root.join('lib').to_s).uniq!
18
+
19
+ require 'watchr'
20
+
21
+ class Test::Unit::TestCase
22
+ class << self
23
+ def test(name, &block)
24
+ name = :"test_#{name.gsub(/\s/,'_')}"
25
+ define_method(name, &block)
26
+ end
27
+ alias :should :test
28
+
29
+ # noop
30
+ def xtest(*args) end
31
+ end
32
+ end
33
+
34
+ # taken from minitest/unit.rb
35
+ # (with modifications)
36
+ def capture_io
37
+ require 'stringio'
38
+
39
+ orig_stdout, orig_stderr = $stdout, $stderr
40
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
41
+ $stdout, $stderr = captured_stdout, captured_stderr
42
+
43
+ yield
44
+
45
+ return Struct.new(:stdout, :stderr).new(
46
+ captured_stdout.string,
47
+ captured_stderr.string
48
+ )
49
+ ensure
50
+ $stdout = orig_stdout
51
+ $stderr = orig_stderr
52
+ end
@@ -0,0 +1,123 @@
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.action_for('abc').call.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.action_for('abc', :accessed).call.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.action_for('abc', :accessed).call.should be(:x)
53
+ end
54
+
55
+ test "no action for path" do
56
+ @script.watch('abc', :accessed) { :x }
57
+ @script.action_for('abc', :modified).call.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.action_for('abc').call.should be(:x)
74
+ end
75
+
76
+ test "resets state" do
77
+ @script.default_action { 'x' }
78
+ @script.watch('foo') { 'bar' }
79
+ @script.send(:reset)
80
+ @script.instance_variable_get(:@default_action).call.should be(nil)
81
+ @script.instance_variable_get(:@rules).should be([])
82
+ end
83
+
84
+ test "resets state on parse" do
85
+ @script.stubs(:instance_eval)
86
+ @script.expects(:reset)
87
+ @script.parse!
88
+ end
89
+
90
+ test "actions receive a MatchData object" do
91
+ @script.watch('de(.)') {|m| [m[0], m[1]] }
92
+ @script.action_for('def').call.should be(%w( def f ))
93
+ end
94
+
95
+ test "rule's default action" do
96
+ @script.watch('abc')
97
+ @script.action_for('abc').call.should be(nil)
98
+ @script.default_action { :x }
99
+
100
+ @script.watch('def')
101
+ @script.action_for('def').call.should be(:x)
102
+ end
103
+
104
+ test "file path" do
105
+ Script.any_instance.stubs(:parse!)
106
+ path = Pathname('some/file').expand_path
107
+ script = Script.new(path)
108
+ script.path.should be(path)
109
+ end
110
+
111
+ test "later rules take precedence" do
112
+ @script.watch('a/(.*)\.x') { :x }
113
+ @script.watch('a/b/(.*)\.x') { :y }
114
+
115
+ @script.action_for('a/b/c.x').call.should be(:y)
116
+ end
117
+
118
+ test "rule patterns match against paths relative to pwd" do
119
+ @script.watch('^abc') { :x }
120
+ path = Pathname(Dir.pwd) + 'abc'
121
+ @script.action_for(path).call.should be(:x)
122
+ end
123
+ end
@@ -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(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)
30
+
31
+ Watchr.handler = nil
32
+ ENV['HANDLER'] = 'bsd'
33
+ Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)
34
+
35
+ Watchr.handler = nil
36
+ ENV['HANDLER'] = 'darwin'
37
+ Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)
38
+
39
+ Watchr.handler = nil
40
+ ENV['HANDLER'] = 'unix'
41
+ Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : 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
+
@@ -0,0 +1,60 @@
1
+
2
+ Gem::Specification.new do |s|
3
+ s.name = '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/script.rb
33
+ manifest.watchr
34
+ specs.watchr
35
+ test/README
36
+ test/event_handlers/test_base.rb
37
+ test/event_handlers/test_portable.rb
38
+ test/event_handlers/test_unix.rb
39
+ test/test_controller.rb
40
+ test/test_helper.rb
41
+ test/test_script.rb
42
+ test/test_watchr.rb
43
+ watchr.gemspec
44
+ ]
45
+ s.test_files = %w[
46
+ test/test_helper.rb
47
+ test/test_watchr.rb
48
+ test/test_script.rb
49
+ test/test_controller.rb
50
+ test/event_handlers/test_base.rb
51
+ test/event_handlers/test_unix.rb
52
+ test/event_handlers/test_portable.rb
53
+ ]
54
+
55
+ s.add_development_dependency 'mocha'
56
+ s.add_development_dependency 'jeremymcanally-matchy'
57
+ s.add_development_dependency 'jeremymcanally-pending'
58
+ s.add_development_dependency 'mynyml-every'
59
+ s.add_development_dependency 'mynyml-redgreen'
60
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nestor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Fran\xC3\xA7ois Beausoleil"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-29 00:00:00 -04:00
13
+ default_executable: nestor
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
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: yard
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: watchr
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.7
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: pluginaweek-state_machine
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.0
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.11.6
64
+ version:
65
+ description: Nestor watches file system events and responds by running the tests or specs that match the changed files.
66
+ email: francois@teksol.info
67
+ executables:
68
+ - nestor
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - bin/nestor
82
+ - doc/.gitignore
83
+ - doc/state-diagram.graffle
84
+ - doc/state-diagram.png
85
+ - lib/nestor.rb
86
+ - lib/nestor/cli.rb
87
+ - lib/nestor/machine.rb
88
+ - lib/nestor/strategies.rb
89
+ - lib/nestor/strategies/test/unit.rb
90
+ - lib/nestor/watchers.rb
91
+ - lib/nestor/watchers/rails.rb
92
+ - lib/nestor/watchers/rails_script.rb
93
+ - spec/machine_spec.rb
94
+ - spec/spec_helper.rb
95
+ - vendor/watchr-0.5.7/.gitignore
96
+ - vendor/watchr-0.5.7/History.txt
97
+ - vendor/watchr-0.5.7/LICENSE
98
+ - vendor/watchr-0.5.7/Manifest
99
+ - vendor/watchr-0.5.7/README.rdoc
100
+ - vendor/watchr-0.5.7/Rakefile
101
+ - vendor/watchr-0.5.7/TODO.txt
102
+ - vendor/watchr-0.5.7/bin/watchr
103
+ - vendor/watchr-0.5.7/docs.watchr
104
+ - vendor/watchr-0.5.7/gem.watchr
105
+ - vendor/watchr-0.5.7/lib/watchr.rb
106
+ - vendor/watchr-0.5.7/lib/watchr/controller.rb
107
+ - vendor/watchr-0.5.7/lib/watchr/event_handlers/base.rb
108
+ - vendor/watchr-0.5.7/lib/watchr/event_handlers/portable.rb
109
+ - vendor/watchr-0.5.7/lib/watchr/event_handlers/unix.rb
110
+ - vendor/watchr-0.5.7/lib/watchr/script.rb
111
+ - vendor/watchr-0.5.7/manifest.watchr
112
+ - vendor/watchr-0.5.7/specs.watchr
113
+ - vendor/watchr-0.5.7/test/README
114
+ - vendor/watchr-0.5.7/test/event_handlers/test_base.rb
115
+ - vendor/watchr-0.5.7/test/event_handlers/test_portable.rb
116
+ - vendor/watchr-0.5.7/test/event_handlers/test_unix.rb
117
+ - vendor/watchr-0.5.7/test/test_controller.rb
118
+ - vendor/watchr-0.5.7/test/test_helper.rb
119
+ - vendor/watchr-0.5.7/test/test_script.rb
120
+ - vendor/watchr-0.5.7/test/test_watchr.rb
121
+ - vendor/watchr-0.5.7/watchr.gemspec
122
+ has_rdoc: true
123
+ homepage: http://github.com/francois/nestor
124
+ licenses: []
125
+
126
+ post_install_message:
127
+ rdoc_options:
128
+ - --charset=UTF-8
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ version:
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ version:
143
+ requirements: []
144
+
145
+ rubyforge_project:
146
+ rubygems_version: 1.3.5
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Nestor keeps the place tidy by running your specs/tests everytime a file changes
150
+ test_files:
151
+ - spec/machine_spec.rb
152
+ - spec/spec_helper.rb