guard-rspec 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guard/rspec.rb +10 -7
- data/lib/guard/rspec/formatter.rb +1 -0
- data/lib/guard/rspec/inspector.rb +67 -69
- data/lib/guard/rspec/runner.rb +79 -82
- data/lib/guard/rspec/version.rb +1 -1
- metadata +10 -12
data/lib/guard/rspec.rb
CHANGED
@@ -17,19 +17,22 @@ module Guard
|
|
17
17
|
@last_failed = false
|
18
18
|
@failed_paths = []
|
19
19
|
|
20
|
-
Runner.
|
21
|
-
|
22
|
-
|
20
|
+
@runner = Runner.new
|
21
|
+
@inspector = Inspector.new
|
22
|
+
|
23
|
+
@runner.set_rspec_version(options)
|
24
|
+
@inspector.excluded = @options[:exclude]
|
25
|
+
@inspector.spec_paths = @options[:spec_paths]
|
23
26
|
end
|
24
27
|
|
25
28
|
# Call once when guard starts
|
26
29
|
def start
|
27
|
-
UI.info "Guard::RSpec is running, with RSpec #{
|
30
|
+
UI.info "Guard::RSpec is running, with RSpec #{@runner.rspec_version}!"
|
28
31
|
run_all if @options[:all_on_start]
|
29
32
|
end
|
30
33
|
|
31
34
|
def run_all
|
32
|
-
passed =
|
35
|
+
passed = @runner.run(options[:spec_paths], options.merge(options[:run_all] || {}).merge(:message => "Running all specs"))
|
33
36
|
|
34
37
|
@last_failed = !passed
|
35
38
|
if passed
|
@@ -45,8 +48,8 @@ module Guard
|
|
45
48
|
|
46
49
|
def run_on_change(paths)
|
47
50
|
paths += @failed_paths if @options[:keep_failed]
|
48
|
-
paths =
|
49
|
-
passed =
|
51
|
+
paths = @inspector.clean(paths)
|
52
|
+
passed = @runner.run(paths, options)
|
50
53
|
|
51
54
|
if passed
|
52
55
|
# clean failed paths memory
|
@@ -1,69 +1,67 @@
|
|
1
|
-
module Guard
|
2
|
-
class RSpec
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
1
|
+
module Guard
|
2
|
+
class RSpec
|
3
|
+
class Inspector
|
4
|
+
def excluded
|
5
|
+
@excluded || []
|
6
|
+
end
|
7
|
+
|
8
|
+
def excluded=(glob)
|
9
|
+
@excluded = Dir[glob.to_s]
|
10
|
+
end
|
11
|
+
|
12
|
+
def spec_paths
|
13
|
+
@spec_paths || []
|
14
|
+
end
|
15
|
+
|
16
|
+
def spec_paths=(path_array)
|
17
|
+
@spec_paths = Array(path_array)
|
18
|
+
end
|
19
|
+
|
20
|
+
def clean(paths)
|
21
|
+
paths.uniq!
|
22
|
+
paths.compact!
|
23
|
+
clear_spec_files_list_after do
|
24
|
+
paths = paths.select { |path| should_run_spec_file?(path) }
|
25
|
+
end
|
26
|
+
paths.reject { |p| included_in_other_path?(p, paths) }
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def should_run_spec_file?(path)
|
32
|
+
(spec_file?(path) || feature_file?(path) || spec_folder?(path)) && !excluded.include?(path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def spec_file?(path)
|
36
|
+
spec_files.include?(path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def feature_file?(path)
|
40
|
+
feature_files.include?(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def spec_folder?(path)
|
44
|
+
path.match(%r{^(#{spec_paths.join("|")})[^\.]*$})
|
45
|
+
# path.match(%r{^spec[^\.]*$})
|
46
|
+
end
|
47
|
+
|
48
|
+
def spec_files
|
49
|
+
@spec_files ||= spec_paths.collect { |path| Dir[File.join(path, "**", "*_spec.rb")] }.flatten
|
50
|
+
end
|
51
|
+
|
52
|
+
def feature_files
|
53
|
+
@feature_files ||= spec_paths.collect { |path| Dir[File.join(path, "**", "*.feature")] }.flatten
|
54
|
+
end
|
55
|
+
|
56
|
+
def clear_spec_files_list_after
|
57
|
+
yield
|
58
|
+
@spec_files = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def included_in_other_path?(path, paths)
|
62
|
+
(paths - [path]).any? { |p| path.include?(p) && path.sub(p, '').include?('/') }
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/guard/rspec/runner.rb
CHANGED
@@ -1,108 +1,105 @@
|
|
1
1
|
module Guard
|
2
2
|
class RSpec
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader :rspec_version
|
6
|
-
|
7
|
-
def run(paths, options={})
|
8
|
-
return false if paths.empty?
|
9
|
-
message = options[:message] || "Running: #{paths.join(' ')}"
|
10
|
-
UI.info(message, :reset => true)
|
11
|
-
system(rspec_command(paths, options))
|
12
|
-
|
13
|
-
if options[:notification] != false && !drb?(options) && failure_exit_code_supported?(options) && $? && !$?.success? && $?.exitstatus != failure_exit_code
|
14
|
-
Notifier.notify("Failed", :title => "RSpec results", :image => :failed, :priority => 2)
|
15
|
-
end
|
3
|
+
class Runner
|
4
|
+
attr_reader :rspec_version
|
16
5
|
|
17
|
-
|
18
|
-
|
6
|
+
def run(paths, options={})
|
7
|
+
return false if paths.empty?
|
8
|
+
message = options[:message] || "Running: #{paths.join(' ')}"
|
9
|
+
UI.info(message, :reset => true)
|
10
|
+
system(rspec_command(paths, options))
|
19
11
|
|
20
|
-
|
21
|
-
|
12
|
+
if options[:notification] != false && !drb?(options) && failure_exit_code_supported?(options) && $? && !$?.success? && $?.exitstatus != failure_exit_code
|
13
|
+
Notifier.notify("Failed", :title => "RSpec results", :image => :failed, :priority => 2)
|
22
14
|
end
|
23
15
|
|
24
|
-
|
16
|
+
$?.success?
|
17
|
+
end
|
25
18
|
|
26
|
-
|
27
|
-
|
19
|
+
def set_rspec_version(options={})
|
20
|
+
@rspec_version = options[:version] || determine_rspec_version
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
cmd_parts << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
|
31
|
-
cmd_parts << "bundle exec" if (bundler? && options[:binstubs] == true && options[:bundler] != false) || (bundler? && options[:bundler] != false)
|
32
|
-
cmd_parts << rspec_exec(options)
|
33
|
-
cmd_parts << options[:cli] if options[:cli]
|
34
|
-
cmd_parts << "-f progress" if options[:cli].nil? || !options[:cli].split(' ').any? { |w| %w[-f --format].include?(w) }
|
35
|
-
cmd_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_#{rspec_class.downcase}.rb -f Guard::RSpec::Formatter::Notification#{rspec_class}#{rspec_version == 1 ? ":" : " --out "}/dev/null" if options[:notification] != false
|
36
|
-
cmd_parts << "--failure-exit-code #{failure_exit_code}" if failure_exit_code_supported?(options)
|
37
|
-
cmd_parts << paths.join(' ')
|
23
|
+
private
|
38
24
|
|
39
|
-
|
40
|
-
|
25
|
+
def rspec_command(paths, options={})
|
26
|
+
warn_deprectation(options)
|
41
27
|
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
cmd_parts = []
|
29
|
+
cmd_parts << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
|
30
|
+
cmd_parts << "bundle exec" if (bundler? && options[:binstubs] == true && options[:bundler] != false) || (bundler? && options[:bundler] != false)
|
31
|
+
cmd_parts << rspec_exec(options)
|
32
|
+
cmd_parts << options[:cli] if options[:cli]
|
33
|
+
cmd_parts << "-f progress" if options[:cli].nil? || !options[:cli].split(' ').any? { |w| %w[-f --format].include?(w) }
|
34
|
+
cmd_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_#{rspec_class.downcase}.rb -f Guard::RSpec::Formatter::Notification#{rspec_class}#{rspec_version == 1 ? ":" : " --out "}/dev/null" if options[:notification] != false
|
35
|
+
cmd_parts << "--failure-exit-code #{failure_exit_code}" if failure_exit_code_supported?(options)
|
36
|
+
cmd_parts << paths.join(' ')
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
end
|
38
|
+
cmd_parts.join(' ')
|
39
|
+
end
|
49
40
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
cmd_parts = []
|
54
|
-
cmd_parts << "bundle exec" if (bundler? && options[:bundler].is_a?(TrueClass)) || (bundler? && options[:binstubs].is_a?(TrueClass))
|
55
|
-
( saved = true; options[:binstubs] = false ) if options[:binstubs].is_a?(TrueClass) # failure exit code support is independent of rspec location
|
56
|
-
cmd_parts << rspec_exec(options)
|
57
|
-
options[:binstubs] = true if saved
|
58
|
-
cmd_parts << "--help"
|
59
|
-
`#{cmd_parts.join(' ')}`.include? "--failure-exit-code"
|
60
|
-
end
|
61
|
-
end
|
41
|
+
def drb?(options)
|
42
|
+
!options[:cli].nil? && options[:cli].include?('--drb')
|
43
|
+
end
|
62
44
|
|
63
|
-
|
64
|
-
|
45
|
+
def bundler?
|
46
|
+
@bundler ||= File.exist?("#{Dir.pwd}/Gemfile")
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure_exit_code_supported?(options={})
|
50
|
+
return @failure_exit_code_supported if defined?(@failure_exit_code_supported)
|
51
|
+
@failure_exit_code_supported ||= begin
|
52
|
+
cmd_parts = []
|
53
|
+
cmd_parts << "bundle exec" if (bundler? && options[:bundler].is_a?(TrueClass)) || (bundler? && options[:binstubs].is_a?(TrueClass))
|
54
|
+
( saved = true; options[:binstubs] = false ) if options[:binstubs].is_a?(TrueClass) # failure exit code support is independent of rspec location
|
55
|
+
cmd_parts << rspec_exec(options)
|
56
|
+
options[:binstubs] = true if saved
|
57
|
+
cmd_parts << "--help"
|
58
|
+
`#{cmd_parts.join(' ')}`.include? "--failure-exit-code"
|
65
59
|
end
|
60
|
+
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
def failure_exit_code
|
63
|
+
2
|
64
|
+
end
|
65
|
+
|
66
|
+
def determine_rspec_version
|
67
|
+
if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
|
68
|
+
File.new("#{Dir.pwd}/spec/spec_helper.rb").read.include?("Spec::Runner") ? 1 : 2
|
69
|
+
elsif bundler?
|
70
|
+
# Allow RSpactor to be tested with RSpactor (bundle show inside a bundle exec)
|
71
|
+
ENV['BUNDLE_GEMFILE'] = "#{Dir.pwd}/Gemfile"
|
72
|
+
`bundle show rspec`.include?("/rspec-1.") ? 1 : 2
|
73
|
+
else
|
74
|
+
2
|
77
75
|
end
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
78
|
+
def rspec_class
|
79
|
+
case rspec_version
|
80
|
+
when 1
|
81
|
+
"Spec"
|
82
|
+
when 2
|
83
|
+
"RSpec"
|
86
84
|
end
|
85
|
+
end
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
87
|
+
def rspec_exec(options = {})
|
88
|
+
case rspec_version
|
89
|
+
when 1
|
90
|
+
options[:binstubs] == true && options[:bundler] != false ? "bin/spec" : "spec"
|
91
|
+
when 2
|
92
|
+
options[:binstubs] == true && options[:bundler] != false ? "bin/rspec" : "rspec"
|
95
93
|
end
|
94
|
+
end
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
96
|
+
def warn_deprectation(options={})
|
97
|
+
[:color, :drb, :fail_fast, [:formatter, "format"]].each do |option|
|
98
|
+
key, value = option.is_a?(Array) ? option : [option, option.to_s.gsub('_', '-')]
|
99
|
+
if options.key?(key)
|
100
|
+
UI.info %{DEPRECATION WARNING: The :#{key} option is deprecated. Pass standard command line argument "--#{value}" to RSpec with the :cli option.}
|
103
101
|
end
|
104
102
|
end
|
105
|
-
|
106
103
|
end
|
107
104
|
end
|
108
105
|
end
|
data/lib/guard/rspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
16
|
-
requirement: &
|
16
|
+
requirement: &70118514647500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.8.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70118514647500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70118514646920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70118514646920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70118514646100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '2.7'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70118514646100
|
47
47
|
description: Guard::RSpec automatically run your specs (much like autotest).
|
48
48
|
email:
|
49
49
|
- thibaud@thibaud.me
|
@@ -73,9 +73,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
hash: -4321082312302331503
|
79
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
77
|
none: false
|
81
78
|
requirements:
|
@@ -84,8 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
81
|
version: 1.3.6
|
85
82
|
requirements: []
|
86
83
|
rubyforge_project: guard-rspec
|
87
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.10
|
88
85
|
signing_key:
|
89
86
|
specification_version: 3
|
90
87
|
summary: Guard gem for RSpec
|
91
88
|
test_files: []
|
89
|
+
has_rdoc:
|