guard-rspec 4.3.1 → 4.4.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +262 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +2 -0
  5. data/.rubocop_todo.yml +10 -0
  6. data/.travis.yml +2 -3
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +9 -2
  9. data/Guardfile +11 -4
  10. data/README.md +8 -4
  11. data/Rakefile +23 -2
  12. data/gemfiles/Gemfile.rspec-2.14 +1 -0
  13. data/gemfiles/Gemfile.rspec-2.99 +14 -0
  14. data/gemfiles/Gemfile.rspec-3.0 +1 -0
  15. data/guard-rspec.gemspec +18 -16
  16. data/lib/guard/rspec.rb +13 -8
  17. data/lib/guard/rspec/command.rb +30 -12
  18. data/lib/guard/rspec/deprecator.rb +32 -11
  19. data/lib/guard/rspec/inspectors/base_inspector.rb +36 -15
  20. data/lib/guard/rspec/inspectors/factory.rb +7 -8
  21. data/lib/guard/rspec/inspectors/focused_inspector.rb +2 -2
  22. data/lib/guard/rspec/inspectors/keeping_inspector.rb +7 -6
  23. data/lib/guard/rspec/inspectors/simple_inspector.rb +3 -3
  24. data/lib/guard/rspec/notifier.rb +9 -5
  25. data/lib/guard/rspec/options.rb +12 -10
  26. data/lib/guard/rspec/runner.rb +41 -25
  27. data/lib/guard/rspec/templates/Guardfile +43 -15
  28. data/lib/guard/rspec/version.rb +1 -1
  29. data/lib/guard/rspec_formatter.rb +111 -0
  30. data/spec/lib/guard/rspec/command_spec.rb +48 -12
  31. data/spec/lib/guard/rspec/deprecator_spec.rb +37 -18
  32. data/spec/lib/guard/rspec/inspectors/base_inspector_spec.rb +129 -18
  33. data/spec/lib/guard/rspec/inspectors/factory_spec.rb +20 -15
  34. data/spec/lib/guard/rspec/inspectors/focused_inspector_spec.rb +79 -13
  35. data/spec/lib/guard/rspec/inspectors/keeping_inspector_spec.rb +103 -33
  36. data/spec/lib/guard/rspec/inspectors/shared_examples.rb +93 -31
  37. data/spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb +52 -16
  38. data/spec/lib/guard/rspec/notifier_spec.rb +49 -27
  39. data/spec/lib/guard/rspec/runner_spec.rb +120 -77
  40. data/spec/lib/guard/rspec_formatter_spec.rb +144 -0
  41. data/spec/lib/guard/rspec_spec.rb +23 -18
  42. data/spec/spec_helper.rb +99 -14
  43. metadata +12 -7
  44. data/lib/guard/rspec/formatter.rb +0 -99
  45. data/spec/lib/guard/rspec/formatter_spec.rb +0 -122
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'rspec', '~> 2.99'
6
+
7
+ group :test do
8
+ gem 'coveralls', require: false
9
+ gem "guard-compat", ">= 0.0.2", require: false
10
+ end
11
+
12
+ group :tool do
13
+ gem 'ruby_gntp', require: false
14
+ end
@@ -6,6 +6,7 @@ gem 'rspec', '~> 3.0.0'
6
6
 
7
7
  group :test do
8
8
  gem 'coveralls', require: false
9
+ gem "guard-compat", ">= 0.0.2", require: false
9
10
  end
10
11
 
11
12
  group :tool do
data/guard-rspec.gemspec CHANGED
@@ -1,26 +1,28 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'guard/rspec/version'
4
+ require "guard/rspec/version"
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = 'guard-rspec'
7
+ s.name = "guard-rspec"
8
8
  s.version = Guard::RSpecVersion::VERSION
9
- s.author = 'Thibaud Guillaume-Gentil'
10
- s.email = 'thibaud@thibaud.gg'
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'
9
+ s.author = "Thibaud Guillaume-Gentil"
10
+ s.email = "thibaud@thibaud.gg"
11
+ s.summary = "Guard gem for RSpec"
12
+ s.description = "Guard::RSpec automatically run your specs" +
13
+ " (much like autotest)."
15
14
 
16
- s.files = `git ls-files`.split($/)
15
+ s.homepage = "https://rubygems.org/gems/guard-rspec"
16
+ s.license = "MIT"
17
+
18
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
19
  s.test_files = s.files.grep(%r{^spec/})
18
- s.require_path = 'lib'
20
+ s.require_path = "lib"
19
21
 
20
- s.add_dependency 'guard', '~> 2.1'
21
- s.add_dependency 'rspec', '>= 2.14', '< 4.0'
22
+ s.add_dependency "guard", "~> 2.1"
23
+ s.add_dependency "rspec", ">= 2.99.0", "< 4.0"
22
24
 
23
- s.add_development_dependency 'bundler', '>= 1.3.5', '< 2.0'
24
- s.add_development_dependency 'rake', '~> 10.1'
25
- s.add_development_dependency 'launchy', '~> 2.4'
25
+ s.add_development_dependency "bundler", ">= 1.3.5", "< 2.0"
26
+ s.add_development_dependency "rake", "~> 10.1"
27
+ s.add_development_dependency "launchy", "~> 2.4"
26
28
  end
data/lib/guard/rspec.rb CHANGED
@@ -1,12 +1,18 @@
1
- require 'guard'
2
- require 'guard/plugin'
1
+ require "guard/rspec/options"
2
+ require "guard/rspec/deprecator"
3
+ require "guard/rspec/runner"
4
+
5
+ # NOTE: To avoid 'superclass mismatch for class RSpec' errors,
6
+ # every file has to have
7
+ #
8
+ # class RSpec < Plugin
9
+ #
10
+ # and not just
11
+ #
12
+ # class RSpec
3
13
 
4
14
  module Guard
5
15
  class RSpec < Plugin
6
- require 'guard/rspec/options'
7
- require 'guard/rspec/deprecator'
8
- require 'guard/rspec/runner'
9
-
10
16
  attr_accessor :options, :runner
11
17
 
12
18
  def initialize(options = {})
@@ -17,7 +23,7 @@ module Guard
17
23
  end
18
24
 
19
25
  def start
20
- ::Guard::UI.info 'Guard::RSpec is running'
26
+ ::Guard::UI.info "Guard::RSpec is running"
21
27
  run_all if options[:all_on_start]
22
28
  end
23
29
 
@@ -41,4 +47,3 @@ module Guard
41
47
  end
42
48
  end
43
49
  end
44
-
@@ -1,8 +1,10 @@
1
- require 'rspec/core'
2
- require 'pathname'
1
+ require "rspec/core"
2
+ require "pathname"
3
+
4
+ require "guard/rspec"
3
5
 
4
6
  module Guard
5
- class RSpec
7
+ class RSpec < Plugin
6
8
  class Command < String
7
9
  FAILURE_EXIT_CODE = 2
8
10
 
@@ -11,7 +13,7 @@ module Guard
11
13
  def initialize(paths, options = {})
12
14
  @paths = paths
13
15
  @options = options
14
- super(_parts.join(' '))
16
+ super(_parts.join(" "))
15
17
  end
16
18
 
17
19
  private
@@ -21,23 +23,38 @@ module Guard
21
23
  parts << _visual_formatter
22
24
  parts << _guard_formatter
23
25
  parts << "--failure-exit-code #{FAILURE_EXIT_CODE}"
24
- parts << paths.join(' ')
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, "/"), "") }
25
34
  end
26
35
 
27
36
  def _visual_formatter
28
37
  return if _cmd_include_formatter?
29
- _rspec_formatters || '-f progress'
38
+ _rspec_formatters || "-f progress"
30
39
  end
31
40
 
32
41
  def _rspec_formatters
33
- # RSpec::Core::ConfigurationOptions#parse_options method was renamed to #options
34
- # in rspec-core v3.0.0.beta2 so call the first one if available. Fixes #249
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
35
45
  config = ::RSpec::Core::ConfigurationOptions.new([])
36
46
  config.parse_options if config.respond_to?(:parse_options)
37
47
  formatters = config.options[:formatters] || nil
38
- # RSpec's parser returns an array in the format [[formatter, output], ...], so match their format
39
- # Construct a matching command line option, including output target
40
- formatters && formatters.map { |formatter| "-f #{formatter.join ' -o '}" }.join(' ')
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(" ")
41
58
  end
42
59
 
43
60
  def _cmd_include_formatter?
@@ -45,7 +62,8 @@ module Guard
45
62
  end
46
63
 
47
64
  def _guard_formatter
48
- "-r #{File.dirname(__FILE__)}/formatter.rb -f Guard::RSpec::Formatter"
65
+ dir = Pathname.new(__FILE__).dirname.dirname
66
+ "-r #{dir + "rspec_formatter.rb"} -f Guard::RSpecFormatter"
49
67
  end
50
68
  end
51
69
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
- class RSpec
2
+ class RSpec < Plugin
3
3
  class Deprecator
4
4
  attr_accessor :options
5
5
 
@@ -23,41 +23,62 @@ module Guard
23
23
  private
24
24
 
25
25
  def _spec_opts_env
26
- return if ENV['SPEC_OPTS'].nil?
27
- UI.warning "The SPEC_OPTS environment variable is present. This can conflict with guard-rspec."
26
+ return if ENV["SPEC_OPTS"].nil?
27
+ UI.warning(
28
+ "The SPEC_OPTS environment variable is present." +
29
+ " This can conflict with guard-rspec."
30
+ )
28
31
  end
29
32
 
30
33
  def _version_option
31
34
  return unless options.key?(:version)
32
- _deprecated('The :version option is deprecated. Only RSpec ~> 2.14 is now supported.')
35
+ _deprecated(
36
+ "The :version option is deprecated." +
37
+ " Only RSpec ~> 2.14 is now supported."
38
+ )
33
39
  end
34
40
 
35
41
  def _exclude_option
36
42
  return unless options.key?(:exclude)
37
- _deprecated('The :exclude option is deprecated. Please Guard ignore method instead. https://github.com/guard/guard#ignore')
43
+ _deprecated(
44
+ "The :exclude option is deprecated." +
45
+ " Please Guard ignore method instead." +
46
+ " https://github.com/guard/guard#ignore"
47
+ )
38
48
  end
39
49
 
40
50
  def _use_cmd_option
41
- %w[color drb fail_fast formatter env bundler binstubs rvm cli spring turnip zeus foreman].each do |option|
51
+ %w(color drb fail_fast formatter env bundler
52
+ binstubs rvm cli spring turnip zeus foreman).each do |option|
42
53
  next unless options.key?(option.to_sym)
43
- _deprecated("The :#{option} option is deprecated. Please customize the new :cmd option to fit your need.")
54
+ _deprecated(
55
+ "The :#{option} option is deprecated." +
56
+ " Please customize the new :cmd option to fit your need."
57
+ )
44
58
  end
45
59
  end
46
60
 
47
61
  def _keep_failed_option
48
62
  return unless options.key?(:keep_failed)
49
- _deprecated('The :keep_failed option is deprecated. Please set new :failed_mode option value to :keep instead. https://github.com/guard/guard-rspec#list-of-available-options')
63
+ _deprecated(
64
+ "The :keep_failed option is deprecated." +
65
+ " Please set new :failed_mode option value to" +
66
+ " :keep instead." +
67
+ " https://github.com/guard/guard-rspec#list-of-available-options")
50
68
  end
51
69
 
52
70
  def _focus_on_failed_option
53
71
  return unless options.key?(:focus_on_failed)
54
- _deprecated('The :focus_on_failed option is deprecated. Focus mode is the default and can be changed using new :failed_mode option. https://github.com/guard/guard-rspec#list-of-available-options')
72
+ _deprecated(
73
+ "The :focus_on_failed option is deprecated." +
74
+ " Focus mode is the default and can be changed using new" +
75
+ " :failed_mode option." +
76
+ " https://github.com/guard/guard-rspec#list-of-available-options")
55
77
  end
56
78
 
57
79
  def _deprecated(message)
58
- UI.warning %{Guard::RSpec DEPRECATION WARNING: #{message}}
80
+ UI.warning %(Guard::RSpec DEPRECATION WARNING: #{message})
59
81
  end
60
-
61
82
  end
62
83
  end
63
84
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
- class RSpec
2
+ class RSpec < Plugin
3
3
  module Inspectors
4
4
  class BaseInspector
5
5
  attr_accessor :options, :spec_paths
@@ -7,44 +7,65 @@ module Guard
7
7
  def initialize(options = {})
8
8
  @options = options
9
9
  @spec_paths = @options[:spec_paths]
10
+ @chdir = @options[:chdir]
10
11
  end
11
12
 
12
- def paths(paths)
13
- raise _abstract
13
+ def paths(_paths)
14
+ fail NotImplementedError
14
15
  end
15
16
 
16
- def failed(locations)
17
- raise _abstract
17
+ def failed(_locations)
18
+ fail NotImplementedError
18
19
  end
19
20
 
20
21
  def reload
21
- raise _abstract
22
+ fail NotImplementedError
22
23
  end
23
24
 
24
25
  private
25
26
 
26
- def _abstract
27
- 'Must be implemented in subclass'
28
- end
29
-
30
27
  # Leave only spec/feature files from spec_paths, remove others
31
28
  def _clean(paths)
32
29
  paths.uniq!
33
30
  paths.compact!
34
31
  spec_dirs = _select_only_spec_dirs(paths)
35
32
  spec_files = _select_only_spec_files(paths)
36
- spec_dirs + spec_files
33
+ (spec_dirs + spec_files).uniq
37
34
  end
38
35
 
39
36
  def _select_only_spec_dirs(paths)
40
- paths.select { |p| File.directory?(p) || spec_paths.include?(p) }
37
+ chdir_paths = _spec_paths_with_chdir
38
+ paths.select do |path|
39
+ File.directory?(path) || chdir_paths.include?(path)
40
+ end
41
41
  end
42
42
 
43
43
  def _select_only_spec_files(paths)
44
- spec_files = spec_paths.collect { |path| Dir[File.join(path, "**{,/*/**}", "*[_.]spec.rb")] }
45
- feature_files = spec_paths.collect { |path| Dir[File.join(path, "**{,/*/**}", "*.feature")] }
44
+ spec_files = _collect_files("*[_.]spec.rb")
45
+ feature_files = _collect_files("*.feature")
46
46
  files = (spec_files + feature_files).flatten
47
- paths.select { |p| files.include?(p) }
47
+
48
+ paths.select do |path|
49
+ (files & [@chdir ? File.join(@chdir, path) : path]).any?
50
+ end
51
+ end
52
+
53
+ def _spec_paths_with_chdir
54
+ _paths_with_chdir(spec_paths, @chdir)
55
+ end
56
+
57
+ def _collect_files(pattern)
58
+ base_paths = _spec_paths_with_chdir
59
+ base_paths.map do |path|
60
+ # TODO: not tested properly
61
+ Dir[File.join(path, "**{,/*/**}", pattern)]
62
+ end
63
+ end
64
+
65
+ def _paths_with_chdir(paths, chdir)
66
+ paths.map do |path|
67
+ chdir ? File.join(chdir, path) : path
68
+ end
48
69
  end
49
70
  end
50
71
  end
@@ -1,17 +1,17 @@
1
- require 'guard/rspec/inspectors/simple_inspector.rb'
2
- require 'guard/rspec/inspectors/keeping_inspector.rb'
3
- require 'guard/rspec/inspectors/focused_inspector.rb'
1
+ require "guard/rspec/inspectors/simple_inspector.rb"
2
+ require "guard/rspec/inspectors/keeping_inspector.rb"
3
+ require "guard/rspec/inspectors/focused_inspector.rb"
4
4
 
5
5
  module Guard
6
- class RSpec
6
+ class RSpec < Plugin
7
7
  module Inspectors
8
8
  class Factory
9
9
  class << self
10
10
  def create(options = {})
11
11
  case options[:failed_mode]
12
- when :focus ; FocusedInspector.new(options)
13
- when :keep ; KeepingInspector.new(options)
14
- else ; SimpleInspector.new(options)
12
+ when :focus then FocusedInspector.new(options)
13
+ when :keep then KeepingInspector.new(options)
14
+ else; SimpleInspector.new(options)
15
15
  end
16
16
  end
17
17
 
@@ -21,4 +21,3 @@ module Guard
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -1,7 +1,7 @@
1
- require 'guard/rspec/inspectors/base_inspector.rb'
1
+ require "guard/rspec/inspectors/base_inspector.rb"
2
2
 
3
3
  module Guard
4
- class RSpec
4
+ class RSpec < Plugin
5
5
  module Inspectors
6
6
  # Inspector that focuses on set of paths if any of them is failing.
7
7
  # Returns only that set of paths on all future calls to #paths
@@ -1,7 +1,7 @@
1
- require 'guard/rspec/inspectors/base_inspector.rb'
1
+ require "guard/rspec/inspectors/base_inspector.rb"
2
2
 
3
3
  module Guard
4
- class RSpec
4
+ class RSpec < Plugin
5
5
  module Inspectors
6
6
  # Inspector that remembers all failed paths and
7
7
  # returns that paths in future calls to #paths method
@@ -51,8 +51,8 @@ end
51
51
  # bit it doesn't work because of bug with RSpec
52
52
  # https://github.com/rspec/rspec-core/issues/952
53
53
  #
54
- #module Guard
55
- # class RSpec
54
+ # module Guard
55
+ # class RSpec < Plugin
56
56
  # module Inspectors
57
57
  # # Inspector that remembers all failed paths and
58
58
  # # returns that paths in future calls to #paths method
@@ -82,7 +82,8 @@ end
82
82
  # # Return paths + failed locations.
83
83
  # # Do not include location in result if its path is already included.
84
84
  # def _with_failed_locations(paths)
85
- # locations = failed_locations.select { |l| !paths.include?(_location_path(l)) }
85
+ # locations = failed_locations.select { |l|
86
+ # !paths.include?(_location_path(l)) }
86
87
  # paths | locations
87
88
  # end
88
89
  #
@@ -93,4 +94,4 @@ end
93
94
  # end
94
95
  # end
95
96
  # end
96
- #end
97
+ # end
@@ -1,14 +1,14 @@
1
- require 'guard/rspec/inspectors/base_inspector.rb'
1
+ require "guard/rspec/inspectors/base_inspector"
2
2
 
3
3
  module Guard
4
- class RSpec
4
+ class RSpec < Plugin
5
5
  module Inspectors
6
6
  class SimpleInspector < BaseInspector
7
7
  def paths(paths)
8
8
  _clean(paths)
9
9
  end
10
10
 
11
- def failed(locations)
11
+ def failed(_locations)
12
12
  # Don't care
13
13
  end
14
14