rspec-rails-watchr 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Rspec
2
2
  module Rails
3
3
  module Watchr
4
- VERSION = "1.0"
4
+ VERSION = '1.0.1'
5
5
  end
6
6
  end
7
7
  end
@@ -1,143 +1,152 @@
1
1
  require 'rspec-rails-watchr/version'
2
2
  require 'term/ansicolor'
3
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
4
+ class SpecWatchr
5
+ String.send :include, Term::ANSIColor
14
6
 
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
7
+ module CommandLine
8
+ def terminal_columns
9
+ cols = `stty -a`.scan(/ (\d+) columns/).flatten.first
10
+ $?.success? ? cols.to_i : nil
11
+ end
12
+
13
+ def run cmd
14
+ puts "=== running: #{cmd} ".ljust(terminal_columns, '=').cyan
15
+ success = system cmd
16
+ puts "===".ljust(terminal_columns, '=').cyan
17
+ success
18
+ end
19
+
20
+ def clear!
21
+ system 'clear'
22
+ end
23
+ end
21
24
 
22
- def clear!
23
- system 'clear'
25
+ module Specs
26
+ def notify message
27
+ Thread.new do
28
+ begin
29
+ require 'notify'
30
+ Notify.notify 'RSpec Result:', message
31
+ rescue
32
+ nil
24
33
  end
25
34
  end
35
+ end
26
36
 
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
37
+ def rspec_command
38
+ @rspec_command ||= File.exist?('./.rspec') ? 'rspec' : 'spec'
39
+ end
38
40
 
39
- def rspec_command
40
- @rspec_command ||= File.exist?('./.rspec') ? 'rspec' : 'spec'
41
- end
41
+ def rspec options
42
+ unless options.empty?
43
+ success = run("bundle exec #{rspec_command} #{options}")
44
+ notify( success ? '♥♥ SUCCESS :) ♥♥' : '♠♠ FAILED >:( ♠♠' )
45
+ end
46
+ end
42
47
 
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
48
+ def rspec_all
49
+ rspec 'spec'
50
+ end
49
51
 
50
- def rspec_all
51
- rspec 'spec'
52
- end
52
+ def rspec_files *files
53
+ rspec files.join(' ')
54
+ end
53
55
 
54
- def rspec_files *files
55
- rspec files.join(' ')
56
- end
56
+ def specs_for(path)
57
+ print "--- Searching specs for #{path.inspect}...".yellow
58
+ specs = match_specs path, Dir['spec/**/*_spec.rb']
59
+ puts specs.empty? ? ' nothing found.'.red : " #{specs.size} matched.".green
60
+ specs
61
+ end
57
62
 
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
63
+ def default_rails_matcher path, specs
64
+ specs.grep(/\b#{path}((_spec)?\.rb)?$/)
65
+ end
64
66
 
65
- def default_rails_matcher path, specs
66
- specs.grep(/\b#{path}((_spec)?\.rb)?$/)
67
- end
67
+ def match_specs path, specs
68
+ matched_specs = @custom_matcher.call(path, specs) if @custom_matcher
69
+ matched_specs = default_rails_matcher(path, specs) if matched_specs.nil?
70
+ end
71
+ end
68
72
 
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
73
+ module Control
74
+ def exit_watchr
75
+ @exiting = true
76
+ puts '--- Exiting...'.white
77
+ exit
78
+ end
74
79
 
75
- module Control
76
- def exit_watchr
77
- @exiting = true
78
- puts '--- Exiting...'.white
79
- exit
80
- end
80
+ def abort_watchr!
81
+ puts '--- Forcing abort...'.white
82
+ abort("\n")
83
+ end
81
84
 
82
- def abort_watchr!
83
- puts '--- Forcing abort...'.white
84
- abort("\n")
85
- end
85
+ def reload!
86
+ # puts ARGV.join(' ')
87
+ exec('bundle exec watchr')
88
+ end
86
89
 
87
- def reload!
88
- # puts ARGV.join(' ')
89
- exec('bundle exec watchr')
90
- end
90
+ def reload_file_list
91
+ require 'shellwords'
92
+ system "touch #{__FILE__.shellescape}"
93
+ # puts '--- Watch\'d file list reloaded.'.green
94
+ end
91
95
 
92
- def reload_file_list
93
- require 'shellwords'
94
- system "touch #{__FILE__.shellescape}"
95
- # puts '--- Watch\'d file list reloaded.'.green
96
+ def trap_int!
97
+ # Ctrl-C
98
+
99
+ @interrupted ||= false
100
+
101
+ Signal.trap('INT') {
102
+ puts ' (Interrupted with CTRL+C)'.red
103
+ if @interrupted
104
+ @exiting ? abort_watchr : exit_watchr
105
+ else
106
+ @interrupted = true
107
+ # reload_file_list
108
+ print '--- What to do now? (q=quit, a=all-specs, r=reload): '.yellow
109
+ case STDIN.gets.chomp.strip.downcase
110
+ when 'q'; @interrupted = false; exit_watchr
111
+ when 'a'; @interrupted = false; rspec_all
112
+ when 'r'; @interrupted = false; reload!
113
+ else
114
+ @interrupted = false
115
+ puts '--- Bad input, ignored.'.yellow
116
+ end
117
+ puts '--- Waiting for changes...'.cyan
96
118
  end
119
+ }
120
+ end
121
+ end
97
122
 
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
123
 
124
+ include CommandLine
125
+ include Specs
126
+ include Control
125
127
 
126
- include CommandLine
127
- include Specs
128
- include Control
128
+ def initialize watchr, &block
129
+ @custom_matcher = block if block_given?
130
+ @watchr = watchr
129
131
 
130
- def initialize watchr, &block
131
- @custom_matcher = block if block_given?
132
- @watchr = watchr
132
+ watchr.watch('^spec/(.*)_spec\.rb$') {|m| rspec_files specs_for(m[1])}
133
+ watchr.watch('^(?:app|lib|script)/(.*)(?:\.rb|\.\w+|)$') {|m| rspec_files specs_for(m[1].gsub(/\.rb$/,''))}
133
134
 
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$/,''))}
135
+ trap_int!
136
+
137
+ puts '--- Waiting for changes...'.cyan
138
+ end
139
+ end
136
140
 
137
- trap_int!
138
141
 
139
- puts '--- Waiting for changes...'.cyan
142
+ class Object
143
+ module Rspec
144
+ module Rails
145
+ module Watchr
146
+ def self.new *args, &block
147
+ SpecWatchr.new *args, &block
148
+ end
140
149
  end
141
150
  end
142
151
  end
143
- end
152
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rspec-rails-watchr
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "1.0"
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Elia