guard-rspec 1.2.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -10
- data/lib/guard/rspec.rb +1 -1
- data/lib/guard/rspec/formatter.rb +9 -2
- data/lib/guard/rspec/runner.rb +30 -99
- data/lib/guard/rspec/templates/Guardfile +3 -3
- data/lib/guard/rspec/version.rb +1 -1
- metadata +31 -33
- checksums.yaml +0 -7
- data/lib/guard/rspec/command.rb.orig +0 -70
- data/lib/guard/rspec/dsl.rb.orig +0 -52
- data/lib/guard/rspec/formatters/notification_rspec.rb +0 -13
- data/lib/guard/rspec/formatters/notification_spec.rb +0 -13
- data/lib/guard/rspec/results.rb.orig +0 -0
- data/lib/guard/rspec/runner.rb.orig +0 -118
- data/lib/guard/rspec/templates/Guardfile.orig +0 -52
- data/lib/guard/rspec/version.rb.orig +0 -5
- data/lib/guard/rspec_formatter.rb +0 -113
- data/lib/guard/rspec_formatter.rb.orig +0 -116
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RSpec guard allows to automatically & intelligently launch specs when files are modified.
|
4
4
|
|
5
|
-
* Compatible with RSpec
|
5
|
+
* Compatible with RSpec >= 2.11 (use guard-rspec 1.2.x for older release, including RSpec 1.x)
|
6
6
|
* Tested against Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby & Rubinius.
|
7
7
|
|
8
8
|
## Install
|
@@ -66,14 +66,6 @@ Please read [Guard doc](https://github.com/guard/guard#readme) for more informat
|
|
66
66
|
|
67
67
|
## Options
|
68
68
|
|
69
|
-
By default, Guard::RSpec automatically detect your RSpec version (with the `spec_helper.rb` syntax or with Bundler) but you can force the version with the `:version` option:
|
70
|
-
|
71
|
-
``` ruby
|
72
|
-
guard 'rspec', :version => 2 do
|
73
|
-
# ...
|
74
|
-
end
|
75
|
-
```
|
76
|
-
|
77
69
|
You can pass any of the standard RSpec CLI options using the `:cli` option:
|
78
70
|
|
79
71
|
``` ruby
|
@@ -96,6 +88,13 @@ guard 'rspec', :spec_paths => "test" do
|
|
96
88
|
# ...
|
97
89
|
end
|
98
90
|
```
|
91
|
+
If you want to set an environment variable, you can configure `:env` option with a hash:
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
guard 'rspec', :env => {'RAILS_ENV' => 'guard'} do
|
95
|
+
# ...
|
96
|
+
end
|
97
|
+
```
|
99
98
|
[Turnip](https://github.com/jnicklas/turnip) is supported (Ruby 1.9.X only), but you must enable it:
|
100
99
|
``` ruby
|
101
100
|
guard 'rspec', :turnip => true do
|
@@ -109,7 +108,6 @@ Former `:color`, `:drb`, `:fail_fast` and `:formatter` options are deprecated an
|
|
109
108
|
### List of available options:
|
110
109
|
|
111
110
|
``` ruby
|
112
|
-
:version => 1 # force use RSpec version 1, default: 2
|
113
111
|
:cli => "-c -f doc" # pass arbitrary RSpec CLI arguments, default: "-f progress"
|
114
112
|
:bundler => false # use "bundle exec" to run the RSpec command, default: true
|
115
113
|
:binstubs => true # use "bin/rspec" to run the RSpec command (takes precedence over :bundle), default: false
|
data/lib/guard/rspec.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'guard/rspec'
|
2
2
|
require 'guard/notifier'
|
3
|
+
require "rspec/core/formatters/base_formatter"
|
3
4
|
|
4
|
-
|
5
|
+
class Guard::RSpec::Formatter < RSpec::Core::Formatters::BaseFormatter
|
6
|
+
|
7
|
+
def dump_summary(duration, total, failures, pending)
|
8
|
+
message = guard_message(total, failures, pending, duration)
|
9
|
+
image = guard_image(failures, pending)
|
10
|
+
notify(message, image)
|
11
|
+
end
|
5
12
|
|
6
13
|
def guard_message(example_count, failure_count, pending_count, duration)
|
7
14
|
message = "#{example_count} examples, #{failure_count} failures"
|
data/lib/guard/rspec/runner.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'drb/drb'
|
2
|
-
require '
|
3
|
-
|
4
|
-
require 'rspec/core' rescue LoadError
|
2
|
+
require 'rspec'
|
5
3
|
|
6
4
|
module Guard
|
7
5
|
class RSpec
|
8
6
|
class Runner
|
9
|
-
attr_reader :rspec_version
|
10
7
|
|
11
8
|
FAILURE_EXIT_CODE = 2
|
12
9
|
|
@@ -16,6 +13,7 @@ module Guard
|
|
16
13
|
:binstubs => false,
|
17
14
|
:rvm => nil,
|
18
15
|
:cli => nil,
|
16
|
+
:env => nil,
|
19
17
|
:notification => true,
|
20
18
|
:turnip => false
|
21
19
|
}.merge(options)
|
@@ -38,15 +36,8 @@ module Guard
|
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
def rspec_version
|
42
|
-
@rspec_version ||= @options[:version] || determine_rspec_version
|
43
|
-
end
|
44
|
-
|
45
39
|
def rspec_executable
|
46
|
-
@rspec_executable ||=
|
47
|
-
exec = rspec_class.downcase
|
48
|
-
binstubs? ? "#{binstubs}/#{exec}" : exec
|
49
|
-
end
|
40
|
+
@rspec_executable ||= binstubs? ? "#{binstubs}/rspec" : "rspec"
|
50
41
|
end
|
51
42
|
|
52
43
|
def failure_exit_code_supported?
|
@@ -59,52 +50,32 @@ module Guard
|
|
59
50
|
end
|
60
51
|
end
|
61
52
|
|
62
|
-
def rspec_class
|
63
|
-
@rspec_class ||= case rspec_version
|
64
|
-
when 1
|
65
|
-
"Spec"
|
66
|
-
when 2, 3
|
67
|
-
"RSpec"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
53
|
def parsed_or_default_formatter
|
72
54
|
@parsed_or_default_formatter ||= begin
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
55
|
+
# Use RSpec's parser to parse formatters
|
56
|
+
formatters = ::RSpec::Core::ConfigurationOptions.new([]).parse_options()[:formatters]
|
57
|
+
# Use a default formatter if none exists.
|
58
|
+
# RSpec's parser returns an array in the format [[formatter, output], ...], so match their format
|
59
|
+
formatters = [['progress']] if formatters.nil? || formatters.empty?
|
60
|
+
# Construct a matching command line option, including output target
|
61
|
+
formatters.map { |formatter| "-f #{formatter.join ' -o '}" }.join ' '
|
80
62
|
end
|
81
63
|
end
|
82
64
|
|
83
65
|
private
|
84
66
|
|
67
|
+
def environment_variables
|
68
|
+
return if @options[:env].nil?
|
69
|
+
"export " + @options[:env].map {|key, value| "#{key}=#{value}"}.join(' ') + ';'
|
70
|
+
end
|
71
|
+
|
85
72
|
def rspec_arguments(paths, options)
|
86
73
|
arg_parts = []
|
87
74
|
arg_parts << options[:cli]
|
88
75
|
if @options[:notification]
|
89
76
|
arg_parts << parsed_or_default_formatter unless options[:cli] =~ formatter_regex
|
90
|
-
|
91
|
-
|
92
|
-
formatter_class_name = "(undefined)"
|
93
|
-
|
94
|
-
case rspec_version
|
95
|
-
when 1, 2
|
96
|
-
formatter_class_name = "Guard::RSpec::Formatter::Notification#{rspec_class}"
|
97
|
-
formatter_file = "rspec/formatters/notification_#{rspec_class.downcase}.rb"
|
98
|
-
when 3
|
99
|
-
formatter_class_name = "Guard::RSpecFormatter"
|
100
|
-
formatter_file = "rspec_formatter.rb"
|
101
|
-
else
|
102
|
-
fail "Guard::RSpec fatal error: UNKNOWN RSPEC VERSION: #{rspec_version.inspect}"
|
103
|
-
end
|
104
|
-
|
105
|
-
lib_guard = Pathname(__FILE__).dirname.dirname
|
106
|
-
arg_parts << "-r #{lib_guard + formatter_file}"
|
107
|
-
arg_parts << formatter_arg(formatter_class_name)
|
77
|
+
arg_parts << "-r #{File.dirname(__FILE__)}/formatter.rb"
|
78
|
+
arg_parts << "-f Guard::RSpec::Formatter --out /dev/null"
|
108
79
|
end
|
109
80
|
arg_parts << "--failure-exit-code #{FAILURE_EXIT_CODE}" if failure_exit_code_supported?
|
110
81
|
arg_parts << "-r turnip/rspec" if @options[:turnip]
|
@@ -113,17 +84,9 @@ module Guard
|
|
113
84
|
arg_parts.compact.join(' ')
|
114
85
|
end
|
115
86
|
|
116
|
-
def formatter_arg(formatter_name)
|
117
|
-
case rspec_version
|
118
|
-
when 1
|
119
|
-
"-f #{formatter_name}:/dev/null"
|
120
|
-
when 2, 3
|
121
|
-
"-f #{formatter_name} --out /dev/null"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
87
|
def rspec_command(paths, options)
|
126
88
|
cmd_parts = []
|
89
|
+
cmd_parts << environment_variables
|
127
90
|
cmd_parts << "rvm #{@options[:rvm].join(',')} exec" if @options[:rvm].respond_to?(:join)
|
128
91
|
cmd_parts << "bundle exec" if bundle_exec?
|
129
92
|
cmd_parts << rspec_executable
|
@@ -142,8 +105,7 @@ module Guard
|
|
142
105
|
end
|
143
106
|
|
144
107
|
def rspec_command_exited_with_an_exception?
|
145
|
-
|
146
|
-
$?.exitstatus != FAILURE_EXIT_CODE
|
108
|
+
failure_exit_code_supported? && $?.exitstatus != FAILURE_EXIT_CODE
|
147
109
|
end
|
148
110
|
|
149
111
|
# We can optimize this path by hitting up the drb server directly, circumventing the overhead
|
@@ -166,20 +128,15 @@ module Guard
|
|
166
128
|
end
|
167
129
|
|
168
130
|
def drb_used?
|
169
|
-
|
170
|
-
@drb_used = @options[:cli] && @options[:cli].include?('--drb')
|
171
|
-
else
|
172
|
-
@drb_used
|
173
|
-
end
|
131
|
+
@drb_used ||= @options[:cli] && @options[:cli].include?('--drb')
|
174
132
|
end
|
175
133
|
|
176
|
-
#
|
134
|
+
# W we can avoid loading a large chunk of rspec
|
177
135
|
# just to let DRb know what to do.
|
178
136
|
#
|
179
137
|
# For reference:
|
180
138
|
#
|
181
|
-
# * RSpec
|
182
|
-
# * RSpec 2: https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/drb_command_line.rb
|
139
|
+
# * RSpec: https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/drb_command_line.rb
|
183
140
|
def drb_service(port)
|
184
141
|
require "drb/drb"
|
185
142
|
|
@@ -199,54 +156,25 @@ module Guard
|
|
199
156
|
end
|
200
157
|
|
201
158
|
def bundler_allowed?
|
202
|
-
|
203
|
-
@bundler_allowed = File.exist?("#{Dir.pwd}/Gemfile")
|
204
|
-
else
|
205
|
-
@bundler_allowed
|
206
|
-
end
|
159
|
+
@bundler_allowed ||= File.exist?("#{Dir.pwd}/Gemfile")
|
207
160
|
end
|
208
161
|
|
209
162
|
def bundler?
|
210
|
-
|
211
|
-
@bundler = bundler_allowed? && @options[:bundler]
|
212
|
-
else
|
213
|
-
@bundler
|
214
|
-
end
|
163
|
+
@bundler ||= bundler_allowed? && @options[:bundler]
|
215
164
|
end
|
216
165
|
|
217
166
|
def binstubs?
|
218
|
-
|
219
|
-
@binstubs = !!@options[:binstubs]
|
220
|
-
else
|
221
|
-
@binstubs
|
222
|
-
end
|
167
|
+
@binstubs ||= !!@options[:binstubs]
|
223
168
|
end
|
224
169
|
|
225
170
|
def binstubs
|
226
|
-
|
227
|
-
"bin"
|
228
|
-
else
|
229
|
-
@options[:binstubs]
|
230
|
-
end
|
171
|
+
@options[:binstubs] == true ? "bin" : @options[:binstubs]
|
231
172
|
end
|
232
173
|
|
233
174
|
def bundle_exec?
|
234
175
|
bundler? && !binstubs?
|
235
176
|
end
|
236
177
|
|
237
|
-
def determine_rspec_version
|
238
|
-
Integer(::RSpec::Core::Version::STRING.split(".").first)
|
239
|
-
rescue NameError
|
240
|
-
if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
|
241
|
-
File.new("#{Dir.pwd}/spec/spec_helper.rb").read.include?("Spec::Runner") ? 1 : 2
|
242
|
-
elsif bundler_allowed?
|
243
|
-
ENV['BUNDLE_GEMFILE'] = "#{Dir.pwd}/Gemfile"
|
244
|
-
/[\/ ]rspec-1\./ =~ `bundle show rspec 2>&1` ? 1 : 2
|
245
|
-
else
|
246
|
-
2
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
178
|
def deprecations_warnings
|
251
179
|
[:color, :drb, [:fail_fast, "fail-fast"], [:formatter, "format"]].each do |option|
|
252
180
|
key, value = option.is_a?(Array) ? option : [option, option.to_s]
|
@@ -255,12 +183,15 @@ module Guard
|
|
255
183
|
UI.info %{DEPRECATION WARNING: The :#{key} option is deprecated. Pass standard command line argument "--#{value}" to RSpec with the :cli option.}
|
256
184
|
end
|
257
185
|
end
|
186
|
+
if @options.key?(:version)
|
187
|
+
@options.delete(:version)
|
188
|
+
UI.info %{DEPRECATION WARNING: The :version option is deprecated. Only RSpec 2 is now supported.}
|
189
|
+
end
|
258
190
|
end
|
259
191
|
|
260
192
|
def formatter_regex
|
261
193
|
@formatter_regex ||= /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
|
262
194
|
end
|
263
|
-
|
264
195
|
end
|
265
196
|
end
|
266
197
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
guard 'rspec'
|
1
|
+
guard 'rspec' do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
3
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
4
|
watch('spec/spec_helper.rb') { "spec" }
|
@@ -10,10 +10,10 @@ guard 'rspec', :version => 2 do
|
|
10
10
|
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
11
11
|
watch('config/routes.rb') { "spec/routing" }
|
12
12
|
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
13
|
-
|
13
|
+
|
14
14
|
# Capybara request specs
|
15
15
|
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
16
|
-
|
16
|
+
|
17
17
|
# Turnip features and steps
|
18
18
|
watch(%r{^spec/acceptance/(.+)\.feature$})
|
19
19
|
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
data/lib/guard/rspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Thibaud Guillaume-Gentil
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2012-09-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: guard
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '1.1'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.1'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
31
|
+
name: rspec
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
37
|
+
version: '2.11'
|
38
|
+
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
45
|
+
version: '2.11'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
47
|
+
name: bundler
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '1.1'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
61
|
+
version: '1.1'
|
55
62
|
description: Guard::RSpec automatically run your specs (much like autotest).
|
56
63
|
email:
|
57
64
|
- thibaud@thibaud.me
|
@@ -59,45 +66,36 @@ executables: []
|
|
59
66
|
extensions: []
|
60
67
|
extra_rdoc_files: []
|
61
68
|
files:
|
62
|
-
- LICENSE
|
63
|
-
- README.md
|
64
|
-
- lib/guard/rspec.rb
|
65
|
-
- lib/guard/rspec/command.rb.orig
|
66
|
-
- lib/guard/rspec/dsl.rb.orig
|
67
69
|
- lib/guard/rspec/formatter.rb
|
68
|
-
- lib/guard/rspec/formatters/notification_rspec.rb
|
69
|
-
- lib/guard/rspec/formatters/notification_spec.rb
|
70
70
|
- lib/guard/rspec/inspector.rb
|
71
|
-
- lib/guard/rspec/results.rb.orig
|
72
71
|
- lib/guard/rspec/runner.rb
|
73
|
-
- lib/guard/rspec/runner.rb.orig
|
74
72
|
- lib/guard/rspec/templates/Guardfile
|
75
|
-
- lib/guard/rspec/templates/Guardfile.orig
|
76
73
|
- lib/guard/rspec/version.rb
|
77
|
-
- lib/guard/rspec
|
78
|
-
-
|
79
|
-
-
|
74
|
+
- lib/guard/rspec.rb
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
80
77
|
homepage: http://rubygems.org/gems/guard-rspec
|
81
78
|
licenses: []
|
82
|
-
metadata: {}
|
83
79
|
post_install_message:
|
84
80
|
rdoc_options: []
|
85
81
|
require_paths:
|
86
82
|
- lib
|
87
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
88
85
|
requirements:
|
89
|
-
- -
|
86
|
+
- - ! '>='
|
90
87
|
- !ruby/object:Gem::Version
|
91
88
|
version: '0'
|
92
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
93
91
|
requirements:
|
94
|
-
- -
|
92
|
+
- - ! '>='
|
95
93
|
- !ruby/object:Gem::Version
|
96
94
|
version: 1.3.6
|
97
95
|
requirements: []
|
98
96
|
rubyforge_project: guard-rspec
|
99
|
-
rubygems_version:
|
97
|
+
rubygems_version: 1.8.23
|
100
98
|
signing_key:
|
101
|
-
specification_version:
|
99
|
+
specification_version: 3
|
102
100
|
summary: Guard gem for RSpec
|
103
101
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 8b5d7c7623699fd71c39dc1e907b04b7a50600ca
|
4
|
-
data.tar.gz: 8acb79a0ea41075758dbb6ad22c9a4b2619140fa
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 07d0e950425323cfb7198bee3566e923a24b07e342554776a51bb1a341f2b2d132ffecfde4b5b91e29f96012ae97d8f72af657d643d852de2e7973aa1a23a012
|
7
|
-
data.tar.gz: 364fa4dc0e0acf4d75e39df847f415080562f58fb70c937a27a85fc040fdb5e4c8be82a87e21f7436f9bf7c08e555e96e7d223af640727e72f4980fab3379b4c
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require "rspec/core"
|
2
|
-
require "pathname"
|
3
|
-
|
4
|
-
require "guard/rspec"
|
5
|
-
|
6
|
-
module Guard
|
7
|
-
class RSpec < Plugin
|
8
|
-
class Command < String
|
9
|
-
FAILURE_EXIT_CODE = 2
|
10
|
-
|
11
|
-
attr_accessor :paths, :options
|
12
|
-
|
13
|
-
def initialize(paths, options = {})
|
14
|
-
@paths = paths
|
15
|
-
@options = options
|
16
|
-
super(_parts.join(" "))
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def _parts
|
22
|
-
parts = [options[:cmd]]
|
23
|
-
parts << _visual_formatter
|
24
|
-
parts << _guard_formatter
|
25
|
-
parts << "--failure-exit-code #{FAILURE_EXIT_CODE}"
|
26
|
-
parts << options[:cmd_additional_args] || ""
|
27
|
-
|
28
|
-
parts << _paths(options).join(" ")
|
29
|
-
end
|
30
|
-
|
31
|
-
def _paths(options)
|
32
|
-
return paths unless chdir = options[:chdir]
|
33
|
-
paths.map { |path| path.sub(File.join(chdir, "/"), "") }
|
34
|
-
end
|
35
|
-
|
36
|
-
def _visual_formatter
|
37
|
-
return if _cmd_include_formatter?
|
38
|
-
_rspec_formatters || "-f progress"
|
39
|
-
end
|
40
|
-
|
41
|
-
def _rspec_formatters
|
42
|
-
# RSpec::Core::ConfigurationOptions#parse_options method was renamed to
|
43
|
-
# #options in rspec-core v3.0.0.beta2 so call the first one if
|
44
|
-
# available. Fixes #249
|
45
|
-
config = ::RSpec::Core::ConfigurationOptions.new([])
|
46
|
-
config.parse_options if config.respond_to?(:parse_options)
|
47
|
-
formatters = config.options[:formatters] || nil
|
48
|
-
|
49
|
-
# RSpec's parser returns an array in the format
|
50
|
-
#
|
51
|
-
# [[formatter, output], ...],
|
52
|
-
#
|
53
|
-
# so match their format Construct a matching command line option,
|
54
|
-
# including output target
|
55
|
-
|
56
|
-
return formatters unless formatters
|
57
|
-
formatters.map { |entries| "-f #{entries.join " -o "}" }.join(" ")
|
58
|
-
end
|
59
|
-
|
60
|
-
def _cmd_include_formatter?
|
61
|
-
options[:cmd] =~ /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
|
62
|
-
end
|
63
|
-
|
64
|
-
def _guard_formatter
|
65
|
-
dir = Pathname.new(__FILE__).dirname.dirname
|
66
|
-
"-r #{dir + "rspec_formatter.rb"} -f Guard::RSpecFormatter"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/lib/guard/rspec/dsl.rb.orig
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require "ostruct"
|
2
|
-
|
3
|
-
require "guard/rspec"
|
4
|
-
|
5
|
-
module Guard
|
6
|
-
class RSpec < Plugin
|
7
|
-
class Dsl
|
8
|
-
def initialize(dsl)
|
9
|
-
@dsl = dsl
|
10
|
-
end
|
11
|
-
|
12
|
-
def watch_spec_files_for(expr)
|
13
|
-
@dsl.send(:watch, expr) { |m| rspec.spec.(m[1]) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def rspec
|
17
|
-
@rspec ||= OpenStruct.new(to_s: "spec").tap do |rspec|
|
18
|
-
rspec.spec_dir = "spec"
|
19
|
-
rspec.spec = ->(m) { "#{rspec.spec_dir}/#{m}_spec.rb" }
|
20
|
-
rspec.spec_helper = "#{rspec.spec_dir}/spec_helper.rb"
|
21
|
-
rspec.spec_files = %r{^#{rspec.spec_dir}/.+_spec\.rb$}
|
22
|
-
rspec.spec_support = %r{^#{rspec.spec_dir}/support/(.+)\.rb$}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def ruby
|
27
|
-
# Ruby apps
|
28
|
-
@ruby || OpenStruct.new.tap do |ruby|
|
29
|
-
ruby.lib_files = %r{^(lib/.+)\.rb$}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def rails(options = {})
|
34
|
-
# Rails example
|
35
|
-
@rails ||= OpenStruct.new.tap do |rails|
|
36
|
-
exts = options.dup.delete(:view_extensions) || %w(erb haml slim)
|
37
|
-
|
38
|
-
rails.app_files = %r{^app/(.+)\.rb$}
|
39
|
-
|
40
|
-
rails.views = %r{^app/(views/.+/[^/]*\.(?:#{exts * "|"}))$}
|
41
|
-
rails.view_dirs = %r{^app/views/(.+)/[^/]*\.(?:#{exts * "|"})$}
|
42
|
-
rails.layouts = %r{^app/layouts/(.+)/.*\.("#{exts * "|"}")$}
|
43
|
-
|
44
|
-
rails.controllers = %r{^app/controllers/(.+)_controller\.rb$}
|
45
|
-
rails.routes = "config/routes.rb"
|
46
|
-
rails.app_controller = "app/controllers/application_controller.rb"
|
47
|
-
rails.spec_helper = "#{rspec.spec_dir}/rails_helper.rb"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../formatter"
|
2
|
-
require "rspec/core/formatters/base_formatter"
|
3
|
-
|
4
|
-
class Guard::RSpec::Formatter::NotificationRSpec < RSpec::Core::Formatters::BaseFormatter
|
5
|
-
include Guard::RSpec::Formatter
|
6
|
-
|
7
|
-
def dump_summary(duration, total, failures, pending)
|
8
|
-
message = guard_message(total, failures, pending, duration)
|
9
|
-
image = guard_image(failures, pending)
|
10
|
-
notify(message, image)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../formatter"
|
2
|
-
require "spec/runner/formatter/base_formatter"
|
3
|
-
|
4
|
-
class Guard::RSpec::Formatter::NotificationSpec < Spec::Runner::Formatter::BaseFormatter
|
5
|
-
include Guard::RSpec::Formatter
|
6
|
-
|
7
|
-
def dump_summary(duration, total, failures, pending)
|
8
|
-
message = guard_message(total, failures, pending, duration)
|
9
|
-
image = guard_image(failures, pending)
|
10
|
-
notify(message, image)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
File without changes
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require "guard/rspec/inspectors/factory"
|
2
|
-
require "guard/rspec/command"
|
3
|
-
require "guard/rspec/notifier"
|
4
|
-
|
5
|
-
module Guard
|
6
|
-
class RSpec < Plugin
|
7
|
-
class Runner
|
8
|
-
# NOTE: must match with const in RspecFormatter!
|
9
|
-
TEMPORARY_FILE_PATH ||= "tmp/rspec_guard_result"
|
10
|
-
|
11
|
-
attr_accessor :options, :inspector, :notifier
|
12
|
-
|
13
|
-
def initialize(options = {})
|
14
|
-
@options = options
|
15
|
-
@inspector = Inspectors::Factory.create(@options)
|
16
|
-
@notifier = Notifier.new(@options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def run_all
|
20
|
-
paths = options[:spec_paths]
|
21
|
-
options = @options.merge(@options[:run_all])
|
22
|
-
return true if paths.empty?
|
23
|
-
Compat::UI.info(options[:message], reset: true)
|
24
|
-
_run(true, paths, options)
|
25
|
-
end
|
26
|
-
|
27
|
-
def run(paths)
|
28
|
-
paths = inspector.paths(paths)
|
29
|
-
return true if paths.empty?
|
30
|
-
Compat::UI.info("Running: #{paths.join(" ")}", reset: true)
|
31
|
-
_run(false, paths, options)
|
32
|
-
end
|
33
|
-
|
34
|
-
def reload
|
35
|
-
inspector.reload
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def _run(all, paths, options)
|
41
|
-
return unless _cmd_option_present(options)
|
42
|
-
command = Command.new(paths, options)
|
43
|
-
|
44
|
-
_without_bundler_env { Kernel.system(command) }.tap do |success|
|
45
|
-
_process_run_result(success, all)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def _without_bundler_env
|
50
|
-
if defined?(::Bundler)
|
51
|
-
::Bundler.with_clean_env { yield }
|
52
|
-
else
|
53
|
-
yield
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def _cmd_option_present(options)
|
58
|
-
return true if options[:cmd]
|
59
|
-
Compat::UI.error("No cmd option specified, unable to run specs!")
|
60
|
-
notifier.notify_failure
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
def _command_success?(success)
|
65
|
-
return false if success.nil?
|
66
|
-
[Command::FAILURE_EXIT_CODE, 0].include?($CHILD_STATUS.exitstatus)
|
67
|
-
end
|
68
|
-
|
69
|
-
def _command_output
|
70
|
-
formatter_tmp_file = _tmp_file(options[:chdir])
|
71
|
-
lines = File.readlines(formatter_tmp_file)
|
72
|
-
summary = lines.first.strip
|
73
|
-
failed_paths = lines[1..11].map(&:strip).compact
|
74
|
-
|
75
|
-
[summary, failed_paths]
|
76
|
-
rescue
|
77
|
-
[nil, nil]
|
78
|
-
ensure
|
79
|
-
File.delete(formatter_tmp_file) if File.exist?(formatter_tmp_file)
|
80
|
-
end
|
81
|
-
|
82
|
-
def _open_launchy
|
83
|
-
return unless options[:launchy]
|
84
|
-
require "launchy"
|
85
|
-
pn = Pathname.new(options[:launchy])
|
86
|
-
::Launchy.open(options[:launchy]) if pn.exist?
|
87
|
-
end
|
88
|
-
|
89
|
-
def _run_all_after_pass
|
90
|
-
return unless options[:all_after_pass]
|
91
|
-
run_all
|
92
|
-
end
|
93
|
-
|
94
|
-
def _process_run_result(result, all)
|
95
|
-
unless _command_success?(result)
|
96
|
-
notifier.notify_failure
|
97
|
-
return
|
98
|
-
end
|
99
|
-
|
100
|
-
summary, failed_paths = _command_output
|
101
|
-
unless summary && failed_paths
|
102
|
-
notifier.notify_failure
|
103
|
-
return
|
104
|
-
end
|
105
|
-
|
106
|
-
inspector.failed(failed_paths)
|
107
|
-
notifier.notify(summary)
|
108
|
-
_open_launchy
|
109
|
-
|
110
|
-
_run_all_after_pass if !all && result
|
111
|
-
end
|
112
|
-
|
113
|
-
def _tmp_file(chdir)
|
114
|
-
chdir ? File.join(chdir, TEMPORARY_FILE_PATH) : TEMPORARY_FILE_PATH
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Note: The cmd option is now required due to the increasing number of ways
|
2
|
-
# rspec may be run, below are examples of the most common uses.
|
3
|
-
# * bundler: 'bundle exec rspec'
|
4
|
-
# * bundler binstubs: 'bin/rspec'
|
5
|
-
# * spring: 'bin/rspec' (This will use spring if running and you have
|
6
|
-
# installed the spring binstubs per the docs)
|
7
|
-
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
8
|
-
# * 'just' rspec: 'rspec'
|
9
|
-
|
10
|
-
guard :rspec, cmd: "bundle exec rspec" do
|
11
|
-
require "guard/rspec/dsl"
|
12
|
-
dsl = Guard::RSpec::Dsl.new(self)
|
13
|
-
|
14
|
-
# Feel free to open issues for suggestions and improvements
|
15
|
-
|
16
|
-
# RSpec files
|
17
|
-
rspec = dsl.rspec
|
18
|
-
watch(rspec.spec_helper) { rspec.spec_dir }
|
19
|
-
watch(rspec.spec_support) { rspec.spec_dir }
|
20
|
-
watch(rspec.spec_files)
|
21
|
-
|
22
|
-
# Ruby files
|
23
|
-
ruby = dsl.ruby
|
24
|
-
dsl.watch_spec_files_for(ruby.lib_files)
|
25
|
-
|
26
|
-
# Rails files
|
27
|
-
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
28
|
-
dsl.watch_spec_files_for(rails.app_files)
|
29
|
-
dsl.watch_spec_files_for(rails.views)
|
30
|
-
|
31
|
-
watch(rails.controllers) do |m|
|
32
|
-
[
|
33
|
-
rspec.spec.("routing/#{m[1]}_routing"),
|
34
|
-
rspec.spec.("controllers/#{m[1]}_controller"),
|
35
|
-
rspec.spec.("acceptance/#{m[1]}")
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
|
-
# Rails config changes
|
40
|
-
watch(rails.spec_helper) { rspec.spec_dir }
|
41
|
-
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
42
|
-
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
43
|
-
|
44
|
-
# Capybara features specs
|
45
|
-
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
46
|
-
|
47
|
-
# Turnip features and steps
|
48
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
49
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
50
|
-
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
51
|
-
end
|
52
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
# NOTE: This class only exists for RSpec and should not be used by
|
2
|
-
# other classes in this project!
|
3
|
-
|
4
|
-
require "pathname"
|
5
|
-
require "fileutils"
|
6
|
-
|
7
|
-
#require "rspec"
|
8
|
-
require "rspec/core/formatters/base_formatter"
|
9
|
-
|
10
|
-
module Guard
|
11
|
-
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
|
12
|
-
TEMPORARY_FILE_PATH ||= "tmp/rspec_guard_result"
|
13
|
-
|
14
|
-
def self.rspec_3?
|
15
|
-
::RSpec::Core::Version::STRING.split(".").first == "3"
|
16
|
-
end
|
17
|
-
|
18
|
-
if rspec_3?
|
19
|
-
::RSpec::Core::Formatters.register self, :dump_summary, :example_failed
|
20
|
-
|
21
|
-
def example_failed(failure)
|
22
|
-
examples.push failure.example
|
23
|
-
end
|
24
|
-
|
25
|
-
def examples
|
26
|
-
@examples ||= []
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# rspec issue https://github.com/rspec/rspec-core/issues/793
|
31
|
-
def self.extract_spec_location(metadata)
|
32
|
-
root_metadata = metadata
|
33
|
-
location = metadata[:location]
|
34
|
-
|
35
|
-
until spec_path?(location)
|
36
|
-
metadata = metadata[:example_group]
|
37
|
-
|
38
|
-
unless metadata
|
39
|
-
STDERR.puts "no spec file found for #{root_metadata[:location]}"
|
40
|
-
return root_metadata[:location]
|
41
|
-
end
|
42
|
-
|
43
|
-
# rspec issue https://github.com/rspec/rspec-core/issues/1243
|
44
|
-
location = (metadata[:location] || "").split(":").first
|
45
|
-
end
|
46
|
-
|
47
|
-
location
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.spec_path?(path)
|
51
|
-
path ||= ""
|
52
|
-
flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
|
53
|
-
if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
|
54
|
-
flags |= File::FNM_EXTGLOB
|
55
|
-
end
|
56
|
-
pattern = ::RSpec.configuration.pattern
|
57
|
-
path = path.sub(/:\d+\z/, "")
|
58
|
-
path = Pathname.new(path).cleanpath.to_s
|
59
|
-
File.fnmatch(pattern, path, flags)
|
60
|
-
end
|
61
|
-
|
62
|
-
def dump_summary(*args)
|
63
|
-
return write_summary(*args) unless self.class.rspec_3?
|
64
|
-
|
65
|
-
notification = args[0]
|
66
|
-
write_summary(
|
67
|
-
notification.duration,
|
68
|
-
notification.example_count,
|
69
|
-
notification.failure_count,
|
70
|
-
notification.pending_count
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
# Write summary to temporary file for runner
|
77
|
-
def write_summary(duration, total, failures, pending)
|
78
|
-
_write do |f|
|
79
|
-
f.puts _message(total, failures, pending, duration)
|
80
|
-
f.puts _failed_paths.join("\n") if failures > 0
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def _write(&block)
|
85
|
-
file = File.expand_path(TEMPORARY_FILE_PATH)
|
86
|
-
FileUtils.mkdir_p(File.dirname(file))
|
87
|
-
File.open(file, "w", &block)
|
88
|
-
end
|
89
|
-
|
90
|
-
def _failed_paths
|
91
|
-
klass = self.class
|
92
|
-
failed = examples.select { |example| _status_failed?(example) }
|
93
|
-
failed.map { |e| klass.extract_spec_location(e.metadata) }.sort.uniq
|
94
|
-
end
|
95
|
-
|
96
|
-
def _message(example_count, failure_count, pending_count, duration)
|
97
|
-
message = "#{example_count} examples, #{failure_count} failures"
|
98
|
-
if pending_count > 0
|
99
|
-
message << " (#{pending_count} pending)"
|
100
|
-
end
|
101
|
-
message << " in #{duration.round(4)} seconds"
|
102
|
-
message
|
103
|
-
end
|
104
|
-
|
105
|
-
def _status_failed?(example)
|
106
|
-
if self.class.rspec_3?
|
107
|
-
example.execution_result.status.to_s == "failed"
|
108
|
-
else
|
109
|
-
example.execution_result[:status].to_s == "failed"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# NOTE: This class only exists for RSpec and should not be used by
|
2
|
-
# other classes in this project!
|
3
|
-
|
4
|
-
require "pathname"
|
5
|
-
require "fileutils"
|
6
|
-
|
7
|
-
require "rspec"
|
8
|
-
require "rspec/core/formatters/base_formatter"
|
9
|
-
|
10
|
-
module Guard
|
11
|
-
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
|
12
|
-
TEMPORARY_FILE_PATH ||= "tmp/rspec_guard_result"
|
13
|
-
|
14
|
-
def self.rspec_3?
|
15
|
-
::RSpec::Core::Version::STRING.split(".").first == "3"
|
16
|
-
end
|
17
|
-
|
18
|
-
if rspec_3?
|
19
|
-
::RSpec::Core::Formatters.register self, :dump_summary, :example_failed
|
20
|
-
|
21
|
-
def example_failed(failure)
|
22
|
-
examples.push failure.example
|
23
|
-
end
|
24
|
-
|
25
|
-
def examples
|
26
|
-
@examples ||= []
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# rspec issue https://github.com/rspec/rspec-core/issues/793
|
31
|
-
def self.extract_spec_location(metadata)
|
32
|
-
root_metadata = metadata
|
33
|
-
location = metadata[:location]
|
34
|
-
|
35
|
-
until spec_path?(location)
|
36
|
-
metadata = metadata[:example_group]
|
37
|
-
|
38
|
-
unless metadata
|
39
|
-
STDERR.puts "no spec file found for #{root_metadata[:location]}"
|
40
|
-
return root_metadata[:location]
|
41
|
-
end
|
42
|
-
|
43
|
-
# rspec issue https://github.com/rspec/rspec-core/issues/1243
|
44
|
-
location = (metadata[:location] || "").split(":").first
|
45
|
-
end
|
46
|
-
|
47
|
-
location
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.spec_path?(path)
|
51
|
-
path ||= ""
|
52
|
-
flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
|
53
|
-
if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
|
54
|
-
flags |= File::FNM_EXTGLOB
|
55
|
-
end
|
56
|
-
pattern = ::RSpec.configuration.pattern
|
57
|
-
path = path.sub(/:\d+\z/, "")
|
58
|
-
path = Pathname.new(path).cleanpath.to_s
|
59
|
-
File.fnmatch(pattern, path, flags)
|
60
|
-
end
|
61
|
-
|
62
|
-
def dump_summary(*args)
|
63
|
-
if self.class.rspec_3?
|
64
|
-
notification = args[0]
|
65
|
-
write_summary(
|
66
|
-
notification.duration,
|
67
|
-
notification.example_count,
|
68
|
-
notification.failure_count,
|
69
|
-
notification.pending_count
|
70
|
-
)
|
71
|
-
else
|
72
|
-
write_summary(*args)
|
73
|
-
end
|
74
|
-
rescue
|
75
|
-
# nothing really we can do, at least don"t kill the test runner
|
76
|
-
end
|
77
|
-
|
78
|
-
# Write summary to temporary file for runner
|
79
|
-
def write_summary(duration, total, failures, pending)
|
80
|
-
_write do |f|
|
81
|
-
f.puts _message(total, failures, pending, duration)
|
82
|
-
f.puts _failed_paths.join("\n") if failures > 0
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def _write(&block)
|
89
|
-
file = File.expand_path(TEMPORARY_FILE_PATH)
|
90
|
-
FileUtils.mkdir_p(File.dirname(file))
|
91
|
-
File.open(file, "w", &block)
|
92
|
-
end
|
93
|
-
|
94
|
-
def _failed_paths
|
95
|
-
failed = examples.select do |e|
|
96
|
-
if self.class.rspec_3?
|
97
|
-
e.execution_result.status.to_s == "failed"
|
98
|
-
else
|
99
|
-
e.execution_result[:status].to_s == "failed"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
klass = self.class
|
104
|
-
failed.map { |e| klass.extract_spec_location(e.metadata) }.sort.uniq
|
105
|
-
end
|
106
|
-
|
107
|
-
def _message(example_count, failure_count, pending_count, duration)
|
108
|
-
message = "#{example_count} examples, #{failure_count} failures"
|
109
|
-
if pending_count > 0
|
110
|
-
message << " (#{pending_count} pending)"
|
111
|
-
end
|
112
|
-
message << " in #{duration.round(4)} seconds"
|
113
|
-
message
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|