guard-rspec 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1dc600657deb79e8869f2128d794a1c3324c665
4
- data.tar.gz: 32efeed7f726f7d57dd4a2da8fca8192305b69ce
3
+ metadata.gz: 72a879771ebb51c3975137af34723ce17a908abe
4
+ data.tar.gz: e6f562c2149e0d7a7312831a706565be60bdc018
5
5
  SHA512:
6
- metadata.gz: 6e600eccab4db141d8d50c5b8df3ae5fd2c01c0cbb5e5208fdeb6c6b03e59d61826c1b96fc905c2eee92e28ba0fa8b5ecc10365927cd9cd4fa0fc92b4405e557
7
- data.tar.gz: a72d49552ebe12e9b85b8121ea4de2a9bd6ebb24fc3ce960a953e0a9789cea684ae3f75a9f7e2043d82dd49af31f7824013f414e7c45fe4c3f2f9c57f44a1a7d
6
+ metadata.gz: ea1fd12cd64193718d5be568ff09ede36a6dafadf4f30a3bfa3050842aa73b1e0ccdc036985a513c0a6898328d0fcf28b997ce84423efba52180cef5e5ddb095
7
+ data.tar.gz: ce1aa592392b715825347bbcc3c95c85eb3e795488c3aeb37f650583524a3784fd8a127e3a09bd31b100058a88d431f7c26c3d31d37fa8bd49c515defa7e1e38
@@ -0,0 +1,8 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .DS_Store
5
+ .rvmrc
6
+ .rbx/*
7
+ Gemfile.lock
8
+ coverage/
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ bundler_args: --without tool
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
7
+ - rbx-19mode
@@ -0,0 +1,38 @@
1
+ Contribute to Guard::RSpec
2
+ ==========================
3
+
4
+ File an issue
5
+ -------------
6
+
7
+ You can report bugs and feature requests to [GitHub Issues](https://github.com/guard/guard-rspec/issues).
8
+
9
+ **Please don't ask question in the issue tracker**, instead ask them on at Stack Overflow and use the
10
+ [guard](http://stackoverflow.com/questions/tagged/guard) tag and/or [guard-rspec](http://stackoverflow.com/questions/tagged/guard-rspec).
11
+
12
+ Try to figure out where the issue belongs to: Is it an issue with Guard::RSpec itself or with Guard?
13
+
14
+ When you file a bug, please try to follow these simple rules if applicable:
15
+
16
+ * Make sure you've read the README carefully.
17
+ * Make sure you run Guard with `bundle exec` first.
18
+ * Add debug information to the issue by running Guard with the `--debug` option.
19
+ * Add your `Guardfile` and `Gemfile` to the issue.
20
+ * Make sure that the issue is reproducible with your description.
21
+
22
+ **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
23
+
24
+ Development
25
+ -----------
26
+
27
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard-rspec/master/frames).
28
+ * Source hosted at [GitHub](https://github.com/guard/guard-rspec).
29
+
30
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
31
+
32
+ * Please create a topic branch for every separate change you make.
33
+ * Make sure your patches are well tested. All specs run with `rake spec:portability` must pass.
34
+ * Update the [README](https://github.com/guard/guard-rspec/blob/master/README.md).
35
+ * Please **do not change** the version number.
36
+
37
+ For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
38
+ `#guard` (irc.freenode.net).
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'coveralls', require: false
7
+ end
8
+
9
+ group :tool do
10
+ gem 'ruby_gntp', require: false
11
+ end
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb})
3
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -1,5 +1,7 @@
1
1
  Copyright (c) 2010-2013 Thibaud Guillaume-Gentil
2
2
 
3
+ MIT License
4
+
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
5
7
  "Software"), to deal in the Software without restriction, including
data/README.md CHANGED
@@ -1,27 +1,18 @@
1
1
  # Guard::RSpec
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/guard-rspec.png)](http://badge.fury.io/rb/guard-rspec) [![Build Status](https://secure.travis-ci.org/guard/guard-rspec.png?branch=master)](http://travis-ci.org/guard/guard-rspec) [![Dependency Status](https://gemnasium.com/guard/guard-rspec.png)](https://gemnasium.com/guard/guard-rspec) [![Code Climate](https://codeclimate.com/github/guard/guard-rspec.png)](https://codeclimate.com/github/guard/guard-rspec) [![Coverage Status](https://coveralls.io/repos/guard/guard-rspec/badge.png?branch=master)](https://coveralls.io/r/guard/guard-rspec)
3
4
 
4
- RSpec guard allows to automatically & intelligently launch specs when files are modified.
5
+ Guard::RSpec allows to automatically & intelligently launch specs when files are modified.
5
6
 
6
- * Compatible with RSpec >= 2.13 (use guard-rspec 1.2.x for older release, including RSpec 1.x)
7
- * Tested against Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, Ruby head, REE, JRuby (1.8 mode, 1.9 mode & head) & Rubinius (1.8 mode, 1.9 mode & head).
7
+ * Compatible with RSpec ~> 2.14
8
+ * Tested against Ruby 1.9.3, 2.0.0, JRuby and Rubinius.
8
9
 
9
10
  ## Install
10
11
 
11
- Please be sure to have [Guard](https://github.com/guard/guard) installed before continuing.
12
-
13
- Install the gem:
14
-
15
- ```
16
- $ gem install guard-rspec
17
- ```
18
-
19
- Add it to your Gemfile (inside development group):
12
+ Add the gem to your Gemfile (inside development group):
20
13
 
21
14
  ``` ruby
22
- group :development do
23
- gem 'guard-rspec'
24
- end
15
+ gem 'guard-rspec', require: false
25
16
  ```
26
17
 
27
18
  Add guard definition to your Guardfile by running this command:
@@ -36,7 +27,7 @@ Please read [Guard usage doc](https://github.com/guard/guard#readme).
36
27
 
37
28
  ## Guardfile
38
29
 
39
- RSpec guard can be adapted to all kinds of projects.
30
+ Guard::RSpec can be adapted to all kinds of projects, some examples:
40
31
 
41
32
  ### Standard RubyGem project
42
33
 
@@ -62,157 +53,44 @@ guard :rspec do
62
53
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
63
54
  end
64
55
  ```
56
+
65
57
  Please read [Guard doc](https://github.com/guard/guard#readme) for more information about the Guardfile DSL.
66
58
 
67
59
  ## Options
68
60
 
69
- You can pass any of the standard RSpec CLI options using the `:cli` option:
70
-
71
- ``` ruby
72
- guard 'rspec', :cli => "--color --format nested --fail-fast --drb" do
73
- # ...
74
- end
75
- ```
76
-
77
- By default, Guard::RSpec will only look for spec files within `spec` in your project root. You can configure Guard::RSpec to look in additional paths by using the `:spec_paths` option:
78
-
79
- ``` ruby
80
- guard 'rspec', :spec_paths => ["spec", "vendor/engines/reset/spec"] do
81
- # ...
82
- end
83
- ```
84
- If you have only one path to look in, you can configure the `:spec_paths` option with a string:
85
-
86
- ``` ruby
87
- guard 'rspec', :spec_paths => "test" do
88
- # ...
89
- end
90
- ```
91
- If you want to set an environment variable, you can configure the `:env` option with a hash:
61
+ Guard::RSpec 4.0 use now a more simple approach with the new `cmd` option that let you precisely define which rspec command will be launched on each run. As example if you want to support Spring with a custom formatter (progress by default) use:
92
62
 
93
63
  ``` ruby
94
- guard 'rspec', :env => {'RAILS_ENV' => 'guard'} do
95
- # ...
96
- end
97
- ```
98
- [Turnip](https://github.com/jnicklas/turnip) is supported (Ruby 1.9.X only), but you must enable it:
99
- ``` ruby
100
- guard 'rspec', :turnip => true do
101
- # ...
102
- end
103
- ```
104
- [Spring](https://github.com/jonleighton/spring) is supported (Ruby 1.9.X / Rails 3.2+ only), but you must enable it:
105
- ``` ruby
106
- guard 'rspec', :spring => true do
107
- # ...
108
- end
109
- ```
110
- [ParallelTests](https://github.com/grosser/parallel_tests) is supported, but you must enable it:
111
- ``` ruby
112
- guard 'rspec', :parallel => true, :parallel_cli => '-n 2' do
64
+ guard :rspec, cdm: 'spring rspec -f doc' do
113
65
  # ...
114
66
  end
115
67
  ```
116
- [Foreman](https://github.com/ddollar/foreman) is supported, but you must enable it:
117
- ``` ruby
118
- guard 'rspec', :foreman => true do
119
- # ...
120
- end
121
- ```
122
-
123
- Former `:color`, `:drb`, `:fail_fast` and `:formatter` options are deprecated and no longer have effect.
124
68
 
125
69
  ### List of available options:
126
70
 
127
71
  ``` ruby
128
- :cli => "-c -f doc" # pass arbitrary RSpec CLI arguments, default: "-f progress"
129
- :bundler => false # use "bundle exec" to run the RSpec command, default: true
130
- :binstubs => true # use "bin/rspec" to run the RSpec command (takes precedence over :bundle), default: false
131
- :rvm => ['1.8.7', '1.9.2'] # directly run your specs on multiple Rubies, default: nil
132
- :notification => false # display Growl (or Libnotify) notification after the specs are done running, default: true
133
- :all_after_pass => true # run all specs after changed specs pass, default: false
134
- :all_on_start => true # run all the specs at startup, default: false
135
- :keep_failed => true # keep failed specs until they pass, default: false
136
- :run_all => { :cli => "-p", :parallel => true, :parallel_cli => '-n 2' } # cli arguments to use when running all specs, default: same as :cli; parallel_rspec arguments, default: same as :parallel_cli
137
- :spec_paths => ["spec"] # specify an array of paths that contain spec files
138
- :exclude => "spec/foo/**/*" # exclude files based on glob
139
- :spring => true # enable spring support; default: false
140
- :turnip => true # enable turnip support; default: false
141
- :zeus => true # enable zeus support; default: false
142
- :foreman => true # enable foreman support; default: false
143
- :focus_on_failed => false # focus on the first 10 failed specs first, rerun till they pass
144
- :parallel => true # run all specs in parallel using [ParallelTests](https://github.com/grosser/parallel_tests) gem, default: false
145
- :parallel_cli => "-n 2" # pass arbitrary Parallel Tests arguments, default: ""
146
- :launchy => nil # pass a path to an rspec results file, e.g. ./tmp/spec_results.html
72
+ cmd: 'zeus rspec' # specify a custom rpsec command to run, default: 'rspec'
73
+ spec_paths: ['spec'] # specify a custom array of paths that contain spec files
74
+ focus_on_failed: false # focus on the first 10 failed specs, rerun till they pass, default: true
75
+ keep_failed: true # keep failed specs until they pass (add them to new ones), default: false
76
+ all_after_pass: true # run all specs after changed specs pass, default: false
77
+ all_on_start: true # run all the specs at startup, default: false
78
+ launchy: nil # pass a path to an rspec results file, e.g. ./tmp/spec_results.html
79
+ notification: false # display notification after the specs are done running, default: true
80
+ run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs.
147
81
  ```
148
82
 
149
- You can also use a custom binstubs directory using `:binstubs => 'some-dir'`.
150
-
151
83
  ### Using Launchy to view rspec results
152
- guard-rspec can be configured to launch a results file in lieu of outputing rspec results to the terminal.
153
- Configure your Guardfile with the launchy option
154
- ``` ruby
155
- guard 'rspec', :cli=>'--color --format html --out ./tmp/spec_results.html' do
156
- :launchy => "./tmp/spec_results.html"
157
- # ...
158
- end
159
- ```
160
-
161
- ### DRb mode
162
-
163
- When you specify `--drb` within `:cli`, guard-rspec will circumvent the `rspec` command line tool by
164
- directly communicating with the RSpec DRb server. This avoids the extra overhead incurred by your
165
- shell, bundler and loading RSpec's environment just to send a DRb message. It shaves off a
166
- second or two before the specs start to run; they should run almost immediately.
167
-
168
- ## Notification
169
-
170
- The notification feature is only available for RSpec < 2, and RSpec >= 2.4 (due to the multiple-formatters feature that was present in RSpec 1, was removed in RSpec 2 and reintroduced in RSpec 2.4). So if you are using a version between 2 and 2.4, you should disable the notification with <tt>:notification => false</tt>. Otherwise, nothing will be displayed in the terminal when your specs will run.
171
84
 
172
- Note that setting the environment variable `SPEC_OPTS` can cause notifications to fail.
173
-
174
- The best solution is still to update RSpec to the latest version!
175
-
176
- ## Formatters
177
-
178
- The `:formatter` option has been removed since CLI arguments can be passed through the `:cli` option. If you want to use the former Instafail formatter, you need to use the [rspec-instafail](http://rubygems.org/gems/rspec-instafail) gem instead:
85
+ guard-rspec can be configured to launch a results file in lieu of outputing rspec results to the terminal.
86
+ Configure your Guardfile with the launchy option:
179
87
 
180
88
  ``` ruby
181
- # in your Gemfile
182
- gem 'rspec-instafail'
183
-
184
- # in your Guardfile
185
- guard 'rspec', :cli => '-r rspec/instafail -f RSpec::Instafail' do
89
+ guard :rspec, cmd: 'rspec -f html -o ./tmp/spec_results.html', launchy: './tmp/spec_results.html' do
186
90
  # ...
187
91
  end
188
92
  ```
189
93
 
190
- Default formatter is the `progress` formatter (same as RSpec default).
191
-
192
- ## Running a subset of all specs
193
-
194
- The `:all_on_start` and `:all_after_pass` options cause all specs located in the `spec` directory to be run. If there
195
- are some specs you want to skip, you can tag them with RSpec metadata (such as `:slow => true`)
196
- and skip them with the cli `--tag` option (i.e. `--tag ~slow`).
197
-
198
- You can also use option :spec_paths to override paths used when running all specs.
199
- You can use this feature to create multiple groups of guarded specs with distinct paths, and execute each in its own process:
200
-
201
- ``` ruby
202
- # in your Guardfile
203
- group 'acceptance-tests' do
204
- guard 'rspec', :spec_paths => ['spec/acceptance'] do
205
- # ...
206
- end
207
- end
208
-
209
- group 'unit-tests' do
210
- guard 'rspec', :spec_paths => ['spec/models', 'spec/controllers', 'spec/routing'] do
211
- # ...
212
- end
213
- end
214
- ```
215
-
216
94
  ## Development
217
95
 
218
96
  * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard-rspec/master/frames).
@@ -228,13 +106,9 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
228
106
  For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
229
107
  `#guard` (irc.freenode.net).
230
108
 
231
- ### Testing
232
-
233
- Please run `rake spec:prepare_fixtures` once before launching specs.
234
-
235
109
  ### Author
236
110
 
237
- [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](http://twitter.com/thibaudgg))
111
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg) ([@thibaudgg](https://twitter.com/thibaudgg))
238
112
 
239
113
  ### Contributors
240
114
 
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/rspec/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'guard-rspec'
8
+ s.version = Guard::RSpecVersion::VERSION
9
+ s.author = 'Thibaud Guillaume-Gentil'
10
+ s.email = 'thibaud@thibaud.me'
11
+ s.summary = 'Guard gem for RSpec'
12
+ s.description = 'Guard::RSpec automatically run your specs (much like autotest).'
13
+ s.homepage = 'https://rubygems.org/gems/guard-rspec'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.test_files = s.files.grep(%r{^spec/})
18
+ s.require_path = 'lib'
19
+
20
+ s.add_dependency 'guard', '~> 2.0'
21
+ s.add_dependency 'rspec', '~> 2.14'
22
+ s.add_development_dependency 'bundler', '>= 1.3.5'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'launchy'
26
+ end
@@ -1,126 +1,45 @@
1
1
  require 'guard'
2
- require 'guard/guard'
2
+ require 'guard/plugin'
3
3
 
4
4
  module Guard
5
- class RSpec < Guard
6
- autoload :Runner, 'guard/rspec/runner'
7
- autoload :Inspector, 'guard/rspec/inspector'
5
+ class RSpec < Plugin
6
+ require 'guard/rspec/deprecator'
7
+ require 'guard/rspec/runner'
8
8
 
9
- attr_accessor :last_failed, :failed_paths, :runner, :inspector
9
+ attr_accessor :options, :runner
10
10
 
11
- def initialize(watchers = [], options = {})
11
+ def initialize(options = {})
12
12
  super
13
13
  @options = {
14
- :focus_on_failed => false,
15
- :all_after_pass => false,
16
- :all_on_start => false,
17
- :keep_failed => false,
18
- :spec_paths => ["spec"],
19
- :run_all => {}
14
+ all_on_start: false
20
15
  }.merge(options)
21
- @last_failed = false
22
- @failed_paths = []
23
16
 
24
- @inspector = Inspector.new(@options)
25
- @runner = Runner.new(@options)
17
+ Deprecator.warns_about_deprecated_options(@options)
18
+ @runner = Runner.new(@options)
26
19
  end
27
20
 
28
- # Call once when guard starts
29
21
  def start
30
22
  UI.info "Guard::RSpec is running"
31
- run_all if @options[:all_on_start]
23
+ run_all if options[:all_on_start]
32
24
  end
33
25
 
34
26
  def run_all
35
- passed = @runner.run(@inspector.spec_paths, @options[:run_all].merge(:message => 'Running all specs', :run_all_specs => true))
36
-
37
- unless @last_failed = !passed
38
- @failed_paths = []
39
- else
40
- throw :task_has_failed
41
- end
27
+ _throw_if_failed { runner.run_all }
42
28
  end
43
29
 
44
30
  def reload
45
- @failed_paths = []
46
- end
47
-
48
- def run_on_changes(paths)
49
-
50
- original_paths = paths.dup
51
-
52
- focused = false
53
- if last_failed && @options[:focus_on_failed]
54
- path = './tmp/rspec_guard_result'
55
- if File.exist?(path)
56
- single_spec = paths && paths.length == 1 && paths[0].include?("_spec") ? paths[0] : nil
57
- failed_specs = File.open(path) { |file| file.read.split("\n") }
58
-
59
- File.delete(path)
60
-
61
- if single_spec && @inspector.clean([single_spec]).length == 1
62
- failed_specs = failed_specs.select{|p| p.include? single_spec}
63
- end
64
-
65
- if failed_specs.any?
66
- # some sane limit, stuff will explode if all tests fail
67
- # ... cap at 10
68
-
69
- paths = failed_specs[0..10]
70
- focused = true
71
- end
72
-
73
- # switch focus to the single spec
74
- if single_spec and failed_specs.length > 0
75
- focused = true
76
- end
77
- end
78
- end
79
-
80
- if focused
81
- add_failed(original_paths)
82
- add_failed(paths.map{|p| p.split(":")[0]})
83
- else
84
- paths += failed_paths if @options[:keep_failed]
85
- paths = @inspector.clean(paths).uniq
86
- end
87
-
88
- if passed = @runner.run(paths)
89
- unless focused
90
- remove_failed(paths)
91
- end
92
-
93
- if last_failed && focused
94
- run_on_changes(failed_paths)
95
- # run all the specs if the run before this one failed
96
- elsif last_failed && @options[:all_after_pass]
97
- @last_failed = false
98
- run_all
99
- end
100
- else
101
- @last_failed = true
102
- unless focused
103
- add_failed(paths)
104
- end
105
-
106
- throw :task_has_failed
107
- end
31
+ runner.reload
108
32
  end
109
33
 
110
- private
111
-
112
- def run(paths)
34
+ def run_on_modifications(paths)
35
+ return false if paths.empty?
36
+ _throw_if_failed { runner.run(paths) }
113
37
  end
114
38
 
115
- def remove_failed(paths)
116
- @failed_paths -= paths if @options[:keep_failed]
117
- end
39
+ private
118
40
 
119
- def add_failed(paths)
120
- if @options[:keep_failed]
121
- @failed_paths += paths
122
- @failed_paths.uniq!
123
- end
41
+ def _throw_if_failed
42
+ throw :task_has_failed unless yield
124
43
  end
125
44
 
126
45
  end