spectator 1.1.a
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/bin/spectator +65 -0
- data/lib/rspec-rails-watchr.rb +154 -0
- data/lib/rspec-rails-watchr/version.rb +7 -0
- data/lib/spectator/version.rb +3 -0
- data/spectator.gemspec +28 -0
- metadata +149 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Elia Schito
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Usage
|
2
|
+
|
3
|
+
In your specs.watchr file just add:
|
4
|
+
|
5
|
+
@specs_watchr ||= Rspec::Rails::Watchr.new(self)
|
6
|
+
|
7
|
+
Then launch `watchr` as usual (probably `bundle exec watchr`).
|
8
|
+
|
9
|
+
## Instructions
|
10
|
+
|
11
|
+
The normal behavior is similar to `autotest --fast-start --no-full-after-failed`
|
12
|
+
but gives the user a bit more control over execution. By hitting CTRL+C (or CMD+. on OSX)
|
13
|
+
you get the following prompt:
|
14
|
+
|
15
|
+
^C (Interrupted with CTRL+C)
|
16
|
+
--- What to do now? (q=quit, a=all-specs, r=reload):
|
17
|
+
|
18
|
+
## Advanced
|
19
|
+
|
20
|
+
If you want to override some path matching:
|
21
|
+
|
22
|
+
@specs_watchr ||= Rspec::Rails::Watchr.new(self) do |path, specs|
|
23
|
+
case path
|
24
|
+
when %r{lib/calibration_with_coefficients}
|
25
|
+
specs.grep(%r{models/(logarithmic|polynomial)_calibration})
|
26
|
+
when %r{app/models/telemetry_parameter}
|
27
|
+
specs.grep(%r{models/telemetry_parameter})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
Copyright (c) 2011 Elia Schito, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/spectator
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'rb-fsevent'
|
5
|
+
require 'rspec-rails-watchr'
|
6
|
+
|
7
|
+
class Peepr
|
8
|
+
def watch regexp, &block
|
9
|
+
@rules ||= []
|
10
|
+
@rules << [regexp, block]
|
11
|
+
end
|
12
|
+
attr_reader :rules
|
13
|
+
|
14
|
+
|
15
|
+
def set_files files
|
16
|
+
files.each do |file|
|
17
|
+
changed? file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def changed? file
|
22
|
+
@files ||= {}
|
23
|
+
mtime = File.mtime(file)
|
24
|
+
changed = (@files[file] and @files[file] < mtime)
|
25
|
+
@files[file] = mtime
|
26
|
+
return changed
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
peepr = Peepr.new
|
31
|
+
fsevent = FSEvent.new
|
32
|
+
watchr = SpecWatchr.new(peepr)
|
33
|
+
|
34
|
+
def watchr.reload!
|
35
|
+
end
|
36
|
+
|
37
|
+
peepr.set_files Dir[File.join(Dir.pwd, '{app,spec,lib,script}/**/*')]
|
38
|
+
|
39
|
+
fsevent.watch Dir.pwd do |directories|
|
40
|
+
|
41
|
+
directories.each do |directory|
|
42
|
+
# puts "Detected change inside: #{directory}"
|
43
|
+
pwd = Pathname(Dir.pwd)
|
44
|
+
|
45
|
+
Dir[File.join(directory, '/**/*')].each do |file|
|
46
|
+
# puts "checking: #{file}"
|
47
|
+
if peepr.changed? file
|
48
|
+
file = Pathname(file).relative_path_from(pwd).to_s
|
49
|
+
# puts "CHANGED!"
|
50
|
+
peepr.rules.each do |(regexp, action)|
|
51
|
+
# puts "RULE: #{regexp} =~ #{file} => #{action.inspect}"
|
52
|
+
regexp = Regexp.new(regexp)
|
53
|
+
if file =~ regexp
|
54
|
+
m = regexp.match(file)
|
55
|
+
# puts "CALLING!"
|
56
|
+
action.call(m)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
fsevent.run
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'rspec-rails-watchr/version'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
|
6
|
+
class SpecWatchr
|
7
|
+
String.send :include, Term::ANSIColor
|
8
|
+
|
9
|
+
module CommandLine
|
10
|
+
def terminal_columns
|
11
|
+
cols = `stty -a`.scan(/ (\d+) columns/).flatten.first
|
12
|
+
$?.success? ? cols.to_i : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def run cmd
|
16
|
+
puts "=== running: #{cmd} ".ljust(terminal_columns, '=').cyan
|
17
|
+
success = system cmd
|
18
|
+
puts "===".ljust(terminal_columns, '=').cyan
|
19
|
+
success
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear!
|
23
|
+
system 'clear'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Specs
|
28
|
+
def notify message
|
29
|
+
Thread.new do
|
30
|
+
begin
|
31
|
+
require 'notify'
|
32
|
+
Notify.notify 'RSpec Result:', message
|
33
|
+
rescue
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def rspec_command
|
40
|
+
@rspec_command ||= File.exist?('./.rspec') ? 'rspec' : 'spec'
|
41
|
+
end
|
42
|
+
|
43
|
+
def rspec options
|
44
|
+
unless options.empty?
|
45
|
+
success = run("bundle exec #{rspec_command} #{options}")
|
46
|
+
notify( success ? '♥♥ SUCCESS :) ♥♥' : '♠♠ FAILED >:( ♠♠' )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def rspec_all
|
51
|
+
rspec 'spec'
|
52
|
+
end
|
53
|
+
|
54
|
+
def rspec_files *files
|
55
|
+
rspec files.join(' ')
|
56
|
+
end
|
57
|
+
|
58
|
+
def specs_for(path)
|
59
|
+
print "--- Searching specs for #{path.inspect}...".yellow
|
60
|
+
specs = match_specs path, Dir['spec/**/*_spec.rb']
|
61
|
+
puts specs.empty? ? ' nothing found.'.red : " #{specs.size} matched.".green
|
62
|
+
specs
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_rails_matcher path, specs
|
66
|
+
specs.grep(/\b#{path}((_spec)?\.rb)?$/)
|
67
|
+
end
|
68
|
+
|
69
|
+
def match_specs path, specs
|
70
|
+
matched_specs = @custom_matcher.call(path, specs) if @custom_matcher
|
71
|
+
matched_specs = default_rails_matcher(path, specs) if matched_specs.nil?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module Control
|
76
|
+
def exit_watchr
|
77
|
+
@exiting = true
|
78
|
+
puts '--- Exiting...'.white
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
|
82
|
+
def abort_watchr!
|
83
|
+
puts '--- Forcing abort...'.white
|
84
|
+
abort("\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def reload!
|
88
|
+
# puts ARGV.join(' ')
|
89
|
+
exec('bundle exec ' << $0)
|
90
|
+
end
|
91
|
+
|
92
|
+
def reload_file_list
|
93
|
+
require 'shellwords'
|
94
|
+
system "touch #{__FILE__.shellescape}"
|
95
|
+
# puts '--- Watch\'d file list reloaded.'.green
|
96
|
+
end
|
97
|
+
|
98
|
+
def trap_int!
|
99
|
+
# Ctrl-C
|
100
|
+
|
101
|
+
@interrupted ||= false
|
102
|
+
|
103
|
+
Signal.trap('INT') {
|
104
|
+
puts ' (Interrupted with CTRL+C)'.red
|
105
|
+
if @interrupted
|
106
|
+
@exiting ? abort_watchr : exit_watchr
|
107
|
+
else
|
108
|
+
@interrupted = true
|
109
|
+
# reload_file_list
|
110
|
+
print '--- What to do now? (q=quit, a=all-specs, r=reload): '.yellow
|
111
|
+
case STDIN.gets.chomp.strip.downcase
|
112
|
+
when 'q'; @interrupted = false; exit_watchr
|
113
|
+
when 'a'; @interrupted = false; rspec_all
|
114
|
+
when 'r'; @interrupted = false; reload!
|
115
|
+
else
|
116
|
+
@interrupted = false
|
117
|
+
puts '--- Bad input, ignored.'.yellow
|
118
|
+
end
|
119
|
+
puts '--- Waiting for changes...'.cyan
|
120
|
+
end
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
include CommandLine
|
127
|
+
include Specs
|
128
|
+
include Control
|
129
|
+
|
130
|
+
def initialize watchr, &block
|
131
|
+
@custom_matcher = block if block_given?
|
132
|
+
@watchr = watchr
|
133
|
+
|
134
|
+
watchr.watch('^spec/(.*)_spec\.rb$') {|m| rspec_files specs_for(m[1])}
|
135
|
+
watchr.watch('^(?:app|lib|script)/(.*)(?:\.rb|\.\w+|)$') {|m| rspec_files specs_for(m[1].gsub(/\.rb$/,''))}
|
136
|
+
|
137
|
+
trap_int!
|
138
|
+
|
139
|
+
puts '--- Waiting for changes...'.cyan
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
class Object
|
145
|
+
module Rspec
|
146
|
+
module Rails
|
147
|
+
module Watchr
|
148
|
+
def self.new *args, &block
|
149
|
+
SpecWatchr.new *args, &block
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
data/spectator.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$:.push File.expand_path('../lib', __FILE__)
|
4
|
+
require 'spectator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'spectator'
|
8
|
+
s.version = Spectator::VERSION
|
9
|
+
s.authors = %w[Elia Schito]
|
10
|
+
s.email = %w[perlelia@gmail.com]
|
11
|
+
s.homepage = ''
|
12
|
+
s.summary = %q{Watches specs for a Ruby (1.8 or 1.9) or Rails (2 or 3) project}
|
13
|
+
s.description = %q{Watches specs for a Ruby (1.8 or 1.9) or Rails (2 or 3) project}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.rubyforge_project = 'rspec-rails-watchr'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = %w[lib]
|
22
|
+
|
23
|
+
s.add_dependency 'rb-fsevent'
|
24
|
+
s.add_dependency 'term-ansicolor'
|
25
|
+
s.add_dependency 'notify'
|
26
|
+
s.add_development_dependency 'rake', '~> 0.9'
|
27
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spectator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 118
|
5
|
+
prerelease: 4
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- a
|
10
|
+
version: 1.1.a
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Elia
|
14
|
+
- Schito
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-12-26 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
prerelease: false
|
32
|
+
requirement: *id001
|
33
|
+
type: :runtime
|
34
|
+
name: rb-fsevent
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
prerelease: false
|
46
|
+
requirement: *id002
|
47
|
+
type: :runtime
|
48
|
+
name: term-ansicolor
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
prerelease: false
|
60
|
+
requirement: *id003
|
61
|
+
type: :runtime
|
62
|
+
name: notify
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 25
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
- 9
|
73
|
+
version: "0.9"
|
74
|
+
prerelease: false
|
75
|
+
requirement: *id004
|
76
|
+
type: :development
|
77
|
+
name: rake
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 15
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 0
|
88
|
+
version: "1.0"
|
89
|
+
prerelease: false
|
90
|
+
requirement: *id005
|
91
|
+
type: :development
|
92
|
+
name: bundler
|
93
|
+
description: Watches specs for a Ruby (1.8 or 1.9) or Rails (2 or 3) project
|
94
|
+
email:
|
95
|
+
- perlelia@gmail.com
|
96
|
+
executables:
|
97
|
+
- spectator
|
98
|
+
extensions: []
|
99
|
+
|
100
|
+
extra_rdoc_files: []
|
101
|
+
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- Gemfile
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/spectator
|
109
|
+
- lib/rspec-rails-watchr.rb
|
110
|
+
- lib/rspec-rails-watchr/version.rb
|
111
|
+
- lib/spectator/version.rb
|
112
|
+
- spectator.gemspec
|
113
|
+
homepage: ""
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">"
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 25
|
136
|
+
segments:
|
137
|
+
- 1
|
138
|
+
- 3
|
139
|
+
- 1
|
140
|
+
version: 1.3.1
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project: rspec-rails-watchr
|
144
|
+
rubygems_version: 1.8.11
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Watches specs for a Ruby (1.8 or 1.9) or Rails (2 or 3) project
|
148
|
+
test_files: []
|
149
|
+
|