rspec-rails-watchr 1.0
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 +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/lib/rspec-rails-watchr.rb +143 -0
- data/lib/rspec-rails-watchr/version.rb +7 -0
- data/rspec-rails-watchr.gemspec +25 -0
- metadata +95 -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'
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'rspec-rails-watchr/version'
|
2
|
+
require 'term/ansicolor'
|
3
|
+
|
4
|
+
module Rspec
|
5
|
+
module Rails
|
6
|
+
class Watchr
|
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 watchr')
|
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
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rspec-rails-watchr/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'rspec-rails-watchr'
|
7
|
+
s.version = Rspec::Rails::Watchr::VERSION
|
8
|
+
s.authors = %w[Elia Schito]
|
9
|
+
s.email = %w[perlelia@gmail.com]
|
10
|
+
s.homepage = ''
|
11
|
+
s.summary = %q{Watches specs for a Rails (2 or 3) project}
|
12
|
+
s.description = %q{Watches specs for a Rails (2 or 3) project}
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.rubyforge_project = 'rspec-rails-watchr'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = %w[lib]
|
21
|
+
|
22
|
+
s.add_dependency 'watchr'
|
23
|
+
s.add_dependency 'term-ansicolor'
|
24
|
+
s.add_dependency 'notify'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-rails-watchr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "1.0"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Elia
|
9
|
+
- Schito
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-06-13 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: watchr
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: term-ansicolor
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: notify
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Watches specs for a Rails (2 or 3) project
|
50
|
+
email:
|
51
|
+
- perlelia@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- MIT-LICENSE
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- lib/rspec-rails-watchr.rb
|
65
|
+
- lib/rspec-rails-watchr/version.rb
|
66
|
+
- rspec-rails-watchr.gemspec
|
67
|
+
homepage: ""
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project: rspec-rails-watchr
|
90
|
+
rubygems_version: 1.8.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Watches specs for a Rails (2 or 3) project
|
94
|
+
test_files: []
|
95
|
+
|