guard-rspec 4.0.4 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +5 -1
  4. data/README.md +12 -9
  5. data/lib/guard/rspec.rb +3 -6
  6. data/lib/guard/rspec/command.rb +6 -19
  7. data/lib/guard/rspec/deprecator.rb +13 -1
  8. data/lib/guard/rspec/formatter.rb +36 -0
  9. data/lib/guard/rspec/inspectors/base_inspector.rb +52 -0
  10. data/lib/guard/rspec/inspectors/factory.rb +24 -0
  11. data/lib/guard/rspec/inspectors/focused_inspector.rb +39 -0
  12. data/lib/guard/rspec/inspectors/keeping_inspector.rb +96 -0
  13. data/lib/guard/rspec/inspectors/simple_inspector.rb +21 -0
  14. data/lib/guard/rspec/notifier.rb +52 -0
  15. data/lib/guard/rspec/options.rb +34 -0
  16. data/lib/guard/rspec/runner.rb +40 -31
  17. data/lib/guard/rspec/version.rb +1 -1
  18. data/spec/lib/guard/rspec/command_spec.rb +2 -6
  19. data/spec/lib/guard/rspec/deprecator_spec.rb +21 -2
  20. data/spec/lib/guard/rspec/formatter_spec.rb +42 -0
  21. data/spec/lib/guard/rspec/inspectors/base_inspector_spec.rb +34 -0
  22. data/spec/lib/guard/rspec/inspectors/factory_spec.rb +40 -0
  23. data/spec/lib/guard/rspec/inspectors/focused_inspector_spec.rb +74 -0
  24. data/spec/lib/guard/rspec/inspectors/keeping_inspector_spec.rb +122 -0
  25. data/spec/lib/guard/rspec/inspectors/shared_examples.rb +59 -0
  26. data/spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb +23 -0
  27. data/spec/lib/guard/rspec/notifier_spec.rb +69 -0
  28. data/spec/lib/guard/rspec/runner_spec.rb +75 -66
  29. data/spec/lib/guard/rspec_spec.rb +8 -3
  30. metadata +25 -12
  31. data/lib/guard/rspec/formatters/focuser.rb +0 -29
  32. data/lib/guard/rspec/formatters/notifier.rb +0 -48
  33. data/lib/guard/rspec/inspector.rb +0 -78
  34. data/spec/lib/guard/rspec/formatters/focuser_spec.rb +0 -25
  35. data/spec/lib/guard/rspec/formatters/notifier_spec.rb +0 -44
  36. data/spec/lib/guard/rspec/inspector_spec.rb +0 -107
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5d1eeb4a0d8baf1b0f82b447f0bc4e08fe30d86
4
- data.tar.gz: af29a93959847c6076ac203a22570cef35cf5f61
3
+ metadata.gz: acd119aa512362402fccfa51caf2168e627a5a6c
4
+ data.tar.gz: 3a79c88569a0726cd24ed0dd0e731312998772f2
5
5
  SHA512:
6
- metadata.gz: ca4ff200acd14bf0e93f38f4a13aa55ccb50bb55ddda39535f84f8b449b5c2b907fc08f0c101a17abdc117c41a28d6588759aa106eda15b837eb86a9951dbc4a
7
- data.tar.gz: e9300fb45717bb537fd2874e93e5f25d72bef1e5d14db0a53346fa3c8b0258468c448bb7e1518b23451840d370db803b6d5d47720926ce36a8de9ca351564e63
6
+ metadata.gz: a2ad3248d30ef9030f6841f54d85b6a0807bf9f5a3be094137fb1903d6e22e636cfbf8ddca811d96dcfba152ab43809b2785ed35e6d26278b0477d23f7e90582
7
+ data.tar.gz: b15e378838881ab59220bcf55404f88dcb52b93ef9a068df2ac56717741d7970c196b1a95b82b4ff69b5c467ada30c8192c8bc592b4bf5ec3eee96814b81db80
data/.gitignore CHANGED
@@ -6,3 +6,5 @@ pkg/*
6
6
  .rbx/*
7
7
  Gemfile.lock
8
8
  coverage/
9
+ .ruby-version
10
+ .ruby-gemset
data/.travis.yml CHANGED
@@ -4,4 +4,8 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - jruby-19mode
7
- - rbx-19mode
7
+ - rbx
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: jruby-19mode
11
+ - rvm: rbx
data/README.md CHANGED
@@ -69,15 +69,18 @@ end
69
69
  ### List of available options:
70
70
 
71
71
  ``` ruby
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.
72
+ cmd: 'zeus rspec' # Specify a custom rspec command to run, default: 'rspec'
73
+ spec_paths: ['spec'] # Specify a custom array of paths that contain spec files
74
+ failed_mode: :focus # What to do with failed specs
75
+ # Available values:
76
+ # :focus (default) - focus on the first 10 failed specs, rerun till they pass
77
+ # :keep - keep failed specs until they pass (add them to new ones)
78
+ # :none - just report
79
+ all_after_pass: true # Run all specs after changed specs pass, default: false
80
+ all_on_start: true # Run all the specs at startup, default: false
81
+ launchy: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.html
82
+ notification: false # Display notification after the specs are done running, default: true
83
+ run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs
81
84
  ```
82
85
 
83
86
  ### Using Launchy to view rspec results
data/lib/guard/rspec.rb CHANGED
@@ -3,6 +3,7 @@ require 'guard/plugin'
3
3
 
4
4
  module Guard
5
5
  class RSpec < Plugin
6
+ require 'guard/rspec/options'
6
7
  require 'guard/rspec/deprecator'
7
8
  require 'guard/rspec/runner'
8
9
 
@@ -10,16 +11,13 @@ module Guard
10
11
 
11
12
  def initialize(options = {})
12
13
  super
13
- @options = {
14
- all_on_start: false
15
- }.merge(options)
16
-
14
+ @options = Options.with_defaults(options)
17
15
  Deprecator.warns_about_deprecated_options(@options)
18
16
  @runner = Runner.new(@options)
19
17
  end
20
18
 
21
19
  def start
22
- ::Guard::UI.info "Guard::RSpec is running"
20
+ ::Guard::UI.info 'Guard::RSpec is running'
23
21
  run_all if options[:all_on_start]
24
22
  end
25
23
 
@@ -41,7 +39,6 @@ module Guard
41
39
  def _throw_if_failed
42
40
  throw :task_has_failed unless yield
43
41
  end
44
-
45
42
  end
46
43
  end
47
44
 
@@ -10,12 +10,7 @@ module Guard
10
10
 
11
11
  def initialize(paths, options = {})
12
12
  @paths = paths
13
- @options = {
14
- focus_on_failed: true,
15
- notification: true,
16
- cmd: 'rspec'
17
- }.merge(options)
18
-
13
+ @options = options
19
14
  super(_parts.join(' '))
20
15
  end
21
16
 
@@ -23,14 +18,13 @@ module Guard
23
18
 
24
19
  def _parts
25
20
  parts = [options[:cmd]]
26
- parts << _formatter
27
- parts << _notifier
28
- parts << _focuser
21
+ parts << _visual_formatter
22
+ parts << _guard_formatter
29
23
  parts << "--failure-exit-code #{FAILURE_EXIT_CODE}"
30
24
  parts << paths.join(' ')
31
25
  end
32
26
 
33
- def _formatter
27
+ def _visual_formatter
34
28
  return if _cmd_include_formatter?
35
29
  _rspec_formatters || '-f progress'
36
30
  end
@@ -46,16 +40,9 @@ module Guard
46
40
  options[:cmd] =~ /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
47
41
  end
48
42
 
49
- def _notifier
50
- return unless options[:notification]
51
- "-r #{File.dirname(__FILE__)}/formatters/notifier.rb -f Guard::RSpec::Formatters::Notifier"
52
- end
53
-
54
- def _focuser
55
- return unless options[:focus_on_failed]
56
- "-r #{File.dirname(__FILE__)}/formatters/focuser.rb -f Guard::RSpec::Formatters::Focuser"
43
+ def _guard_formatter
44
+ "-r #{File.dirname(__FILE__)}/formatter.rb -f Guard::RSpec::Formatter"
57
45
  end
58
-
59
46
  end
60
47
  end
61
48
  end
@@ -16,13 +16,15 @@ module Guard
16
16
  _version_option
17
17
  _exclude_option
18
18
  _use_cmd_option
19
+ _keep_failed_option
20
+ _focus_on_failed_option
19
21
  end
20
22
 
21
23
  private
22
24
 
23
25
  def _spec_opts_env
24
26
  return if ENV['SPEC_OPTS'].nil?
25
- UI.warning "The SPEC_OPTS environment variable is present. This can conflict with guard-rspec, particularly notifications."
27
+ UI.warning "The SPEC_OPTS environment variable is present. This can conflict with guard-rspec."
26
28
  end
27
29
 
28
30
  def _version_option
@@ -42,6 +44,16 @@ module Guard
42
44
  end
43
45
  end
44
46
 
47
+ def _keep_failed_option
48
+ return unless options.key?(:keep_failed)
49
+ _deprectated('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')
50
+ end
51
+
52
+ def _focus_on_failed_option
53
+ return unless options.key?(:focus_on_failed)
54
+ _deprectated('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')
55
+ end
56
+
45
57
  def _deprectated(message)
46
58
  UI.warning %{Guard::RSpec DEPRECATION WARNING: #{message}}
47
59
  end
@@ -0,0 +1,36 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+
3
+ module Guard
4
+ class RSpec
5
+ class Formatter < ::RSpec::Core::Formatters::BaseFormatter
6
+ TEMPORARY_FILE_PATH = './tmp/rspec_guard_result'
7
+
8
+ # Write summary to temporary file for runner
9
+ def dump_summary(duration, total, failures, pending)
10
+ FileUtils.mkdir_p('tmp')
11
+ File.open(TEMPORARY_FILE_PATH, 'w') do |f|
12
+ f.puts _message(total, failures, pending, duration)
13
+ f.puts _failed_paths.join("\n") if failures > 0
14
+ end
15
+ rescue
16
+ # nothing really we can do, at least don't kill the test runner
17
+ end
18
+
19
+ private
20
+
21
+ def _failed_paths
22
+ failed = examples.select { |e| e.execution_result[:status] == 'failed' }
23
+ failed.map { |e| e.metadata[:location] }
24
+ end
25
+
26
+ def _message(example_count, failure_count, pending_count, duration)
27
+ message = "#{example_count} examples, #{failure_count} failures"
28
+ if pending_count > 0
29
+ message << " (#{pending_count} pending)"
30
+ end
31
+ message << " in #{duration.round(4)} seconds"
32
+ message
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module Guard
2
+ class RSpec
3
+ module Inspectors
4
+ class BaseInspector
5
+ attr_accessor :options, :spec_paths
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ @spec_paths = @options[:spec_paths]
10
+ end
11
+
12
+ def paths(paths)
13
+ raise _abstract
14
+ end
15
+
16
+ def failed(locations)
17
+ raise _abstract
18
+ end
19
+
20
+ def reload
21
+ raise _abstract
22
+ end
23
+
24
+ private
25
+
26
+ def _abstract
27
+ 'Must be implemented in subclass'
28
+ end
29
+
30
+ # Leave only spec/feature files from spec_paths, remove others
31
+ def _clean(paths)
32
+ paths.uniq!
33
+ paths.compact!
34
+ spec_dirs = _select_only_spec_dirs(paths)
35
+ spec_files = _select_only_spec_files(paths)
36
+ spec_dirs + spec_files
37
+ end
38
+
39
+ def _select_only_spec_dirs(paths)
40
+ paths.select { |p| File.directory?(p) || spec_paths.include?(p) }
41
+ end
42
+
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")] }
46
+ files = (spec_files + feature_files).flatten
47
+ paths.select { |p| files.include?(p) }
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,24 @@
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
+
5
+ module Guard
6
+ class RSpec
7
+ module Inspectors
8
+ class Factory
9
+ class << self
10
+ def create(options = {})
11
+ case options[:failed_mode]
12
+ when :focus ; FocusedInspector.new(options)
13
+ when :keep ; KeepingInspector.new(options)
14
+ else ; SimpleInspector.new(options)
15
+ end
16
+ end
17
+
18
+ private :new
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,39 @@
1
+ require 'guard/rspec/inspectors/base_inspector.rb'
2
+
3
+ module Guard
4
+ class RSpec
5
+ module Inspectors
6
+ # Inspector that focuses on set of paths if any of them is failing.
7
+ # Returns only that set of paths on all future calls to #paths
8
+ # until they all pass
9
+ class FocusedInspector < BaseInspector
10
+ attr_accessor :focused_locations
11
+
12
+ def initialize(options = {})
13
+ super
14
+ @focused_locations = []
15
+ end
16
+
17
+ def paths(paths)
18
+ if focused_locations.any?
19
+ focused_locations
20
+ else
21
+ _clean(paths)
22
+ end
23
+ end
24
+
25
+ def failed(locations)
26
+ if locations.empty?
27
+ @focused_locations = []
28
+ else
29
+ @focused_locations = locations if focused_locations.empty?
30
+ end
31
+ end
32
+
33
+ def reload
34
+ @focused_locations = []
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,96 @@
1
+ require 'guard/rspec/inspectors/base_inspector.rb'
2
+
3
+ module Guard
4
+ class RSpec
5
+ module Inspectors
6
+ # Inspector that remembers all failed paths and
7
+ # returns that paths in future calls to #paths method
8
+ # along with any new paths passed as parameter to #paths
9
+ class KeepingInspector < BaseInspector
10
+ attr_accessor :failed_locations
11
+
12
+ def initialize(options = {})
13
+ super
14
+ @failed_locations = []
15
+ end
16
+
17
+ def paths(paths)
18
+ _with_failed_locations(_clean(paths))
19
+ end
20
+
21
+ def failed(locations)
22
+ @failed_locations = locations
23
+ end
24
+
25
+ def reload
26
+ @failed_locations = []
27
+ end
28
+
29
+ private
30
+
31
+ # Return paths + failed locations.
32
+ # Do not include location in result if its path is already included.
33
+ def _with_failed_locations(paths)
34
+ failed_paths = failed_locations.map { |l| _location_path(l) }
35
+ (paths | failed_paths).uniq
36
+ end
37
+
38
+ # Extract file path from location
39
+ def _location_path(location)
40
+ location.match(/^(\.\/)?(.*?)(:\d+)?$/)[2]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ #
48
+ # FIXME uncomment when RSpec #952 will be resolved
49
+ #
50
+ # This is correct version of KeepingInspector class,
51
+ # bit it doesn't work because of bug with RSpec
52
+ # https://github.com/rspec/rspec-core/issues/952
53
+ #
54
+ #module Guard
55
+ # class RSpec
56
+ # module Inspectors
57
+ # # Inspector that remembers all failed paths and
58
+ # # returns that paths in future calls to #paths method
59
+ # # along with any new paths passed as parameter to #paths
60
+ # class KeepingInspector < BaseInspector
61
+ # attr_accessor :failed_locations
62
+ #
63
+ # def initialize(options = {})
64
+ # super
65
+ # @failed_locations = []
66
+ # end
67
+ #
68
+ # def paths(paths)
69
+ # _with_failed_locations(_clean(paths))
70
+ # end
71
+ #
72
+ # def failed(locations)
73
+ # @failed_locations = locations
74
+ # end
75
+ #
76
+ # def reload
77
+ # @failed_locations = []
78
+ # end
79
+ #
80
+ # private
81
+ #
82
+ # # Return paths + failed locations.
83
+ # # Do not include location in result if its path is already included.
84
+ # def _with_failed_locations(paths)
85
+ # locations = failed_locations.select { |l| !paths.include?(_location_path(l)) }
86
+ # paths | locations
87
+ # end
88
+ #
89
+ # # Extract file path from location
90
+ # def _location_path(location)
91
+ # location.match(/^(\.\/)?(.*?)(:\d+)?$/)[2]
92
+ # end
93
+ # end
94
+ # end
95
+ # end
96
+ #end
@@ -0,0 +1,21 @@
1
+ require 'guard/rspec/inspectors/base_inspector.rb'
2
+
3
+ module Guard
4
+ class RSpec
5
+ module Inspectors
6
+ class SimpleInspector < BaseInspector
7
+ def paths(paths)
8
+ _clean(paths)
9
+ end
10
+
11
+ def failed(locations)
12
+ # Don't care
13
+ end
14
+
15
+ def reload
16
+ # Nothing to reload
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end