guard-rspec 4.6.5 → 4.7.0

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.
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RSpecVersion
3
- VERSION = "4.6.5".freeze
3
+ VERSION = "4.7.0".freeze
4
4
  end
5
5
  end
@@ -7,19 +7,12 @@ require "fileutils"
7
7
  require "rspec"
8
8
  require "rspec/core/formatters/base_formatter"
9
9
 
10
- require_relative "rspec_defaults"
10
+ require_relative "rspec_formatter_results_path"
11
+
12
+ require "guard/ui"
11
13
 
12
14
  module Guard
13
15
  class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
14
- WIKI_ENV_WARN_URL =
15
- "https://github.com/guard/guard-rspec/wiki/Warning:-no-environment".freeze
16
-
17
- NO_ENV_WARNING_MSG =
18
- "no environment passed - see #{WIKI_ENV_WARN_URL}".freeze
19
-
20
- NO_RESULTS_VALUE_MSG =
21
- ":results_file value unknown (using defaults)".freeze
22
-
23
16
  UNSUPPORTED_PATTERN =
24
17
  "Your RSpec.configuration.pattern uses characters "\
25
18
  "unsupported by your Ruby version (File::FNM_EXTGLOB is undefined)".freeze
@@ -55,9 +48,7 @@ module Guard
55
48
  location = metadata[:location]
56
49
 
57
50
  until spec_path?(location)
58
- metadata = metadata[:parent_example_group] || metadata[:example_group]
59
-
60
- unless metadata
51
+ unless (metadata = _extract_group(metadata))
61
52
  STDERR.puts "no spec file location in #{root_metadata.inspect}"
62
53
  return root_metadata[:location]
63
54
  end
@@ -92,10 +83,14 @@ module Guard
92
83
  # ruby >= 2
93
84
  return flags |= File::FNM_EXTGLOB if File.const_defined?(:FNM_EXTGLOB)
94
85
 
95
- fail Error::UnsupportedPattern if pattern =~ /[{}]/
86
+ raise Error::UnsupportedPattern if pattern =~ /[{}]/
96
87
 
97
88
  flags
98
89
  end
90
+
91
+ def _extract_group(metadata)
92
+ metadata[:parent_example_group] || metadata[:example_group]
93
+ end
99
94
  end
100
95
 
101
96
  def dump_summary(*args)
@@ -121,7 +116,11 @@ module Guard
121
116
  end
122
117
 
123
118
  def _write(&block)
124
- file = _results_file
119
+ file = RSpecFormatterResultsPath.new.path
120
+ if Guard.const_defined?(:Compat)
121
+ msg = "Guard::RSpec: using results file: #{file.inspect}"
122
+ Guard::Compat::UI.debug(format(msg, file))
123
+ end
125
124
  FileUtils.mkdir_p(File.dirname(file))
126
125
  File.open(file, "w", &block)
127
126
  end
@@ -134,9 +133,7 @@ module Guard
134
133
 
135
134
  def _message(example_count, failure_count, pending_count, duration)
136
135
  message = "#{example_count} examples, #{failure_count} failures"
137
- if pending_count > 0
138
- message << " (#{pending_count} pending)"
139
- end
136
+ message << " (#{pending_count} pending)" if pending_count > 0
140
137
  message << " in #{duration.round(4)} seconds"
141
138
  message
142
139
  end
@@ -148,16 +145,5 @@ module Guard
148
145
  example.execution_result[:status].to_s == "failed"
149
146
  end
150
147
  end
151
-
152
- def _results_file
153
- path = ENV["GUARD_RSPEC_RESULTS_FILE"]
154
- if path.nil?
155
- STDERR.puts("Guard::RSpec: Warning: #{NO_ENV_WARNING_MSG}\n" \
156
- "Guard::RSpec: Warning: #{NO_RESULTS_VALUE_MSG}")
157
- path = RSpecDefaults::TEMPORARY_FILE_PATH
158
- end
159
-
160
- File.expand_path(path)
161
- end
162
148
  end
163
149
  end
@@ -0,0 +1,29 @@
1
+ require_relative "rspec_defaults"
2
+
3
+ module Guard
4
+ # Just a wrapper class for the results file filename
5
+ class RSpecFormatterResultsPath
6
+ WIKI_ENV_WARN_URL =
7
+ "https://github.com/guard/guard-rspec/wiki/Warning:-no-environment".
8
+ freeze
9
+
10
+ NO_ENV_WARNING_MSG =
11
+ "no environment passed - see #{WIKI_ENV_WARN_URL}".freeze
12
+
13
+ NO_RESULTS_VALUE_MSG =
14
+ ":results_file value unknown (using defaults)".freeze
15
+
16
+ attr_reader :path
17
+
18
+ def initialize
19
+ path = ENV["GUARD_RSPEC_RESULTS_FILE"]
20
+ if path.nil?
21
+ STDERR.puts("Guard::RSpec: Warning: #{NO_ENV_WARNING_MSG}\n" \
22
+ "Guard::RSpec: Warning: #{NO_RESULTS_VALUE_MSG}")
23
+ path = RSpecDefaults::TEMPORARY_FILE_PATH
24
+ end
25
+
26
+ @path = File.expand_path(path)
27
+ end
28
+ end
29
+ end
@@ -10,11 +10,11 @@ RSpec.describe Guard::RSpec::Command do
10
10
 
11
11
  describe ".initialize" do
12
12
  it "sets paths at the end" do
13
- expect(command).to match /path1 path2$/
13
+ expect(command).to match(/path1 path2$/)
14
14
  end
15
15
 
16
16
  it "sets custom failure exit code" do
17
- expect(command).to match /--failure-exit-code 2/
17
+ expect(command).to match(/--failure-exit-code 2/)
18
18
  end
19
19
 
20
20
  it "sets formatter" do
@@ -26,7 +26,7 @@ RSpec.describe Guard::RSpec::Command do
26
26
  let(:options) { { cmd: "rspec -t ~slow" } }
27
27
 
28
28
  it "uses custom cmd" do
29
- expect(command).to match /^rspec -t ~slow/
29
+ expect(command).to match(/^rspec -t ~slow/)
30
30
  end
31
31
  end
32
32
 
@@ -41,7 +41,7 @@ RSpec.describe Guard::RSpec::Command do
41
41
  end
42
42
 
43
43
  it "uses them" do
44
- expect(command).to match %r{-f doc -o output}
44
+ expect(command).to match(/-f doc -o output/)
45
45
  end
46
46
  end
47
47
 
@@ -54,7 +54,7 @@ RSpec.describe Guard::RSpec::Command do
54
54
  end
55
55
 
56
56
  it "sets default progress formatter" do
57
- expect(command).to match %r{-f progress}
57
+ expect(command).to match(/-f progress/)
58
58
  end
59
59
  end
60
60
 
@@ -62,7 +62,7 @@ RSpec.describe Guard::RSpec::Command do
62
62
  let(:options) { { cmd: "rspec -f doc" } }
63
63
 
64
64
  it "sets no other formatters" do
65
- expect(command).to match %r{-f doc}
65
+ expect(command).to match(/-f doc/)
66
66
  end
67
67
  end
68
68
 
@@ -70,14 +70,14 @@ RSpec.describe Guard::RSpec::Command do
70
70
  let(:options) { { cmd: "rspec", cmd_additional_args: "-f progress" } }
71
71
 
72
72
  it "uses them" do
73
- expect(command).to match %r{-f progress}
73
+ expect(command).to match(/-f progress/)
74
74
  end
75
75
  end
76
76
 
77
77
  context ":chdir option present" do
78
78
  let(:chdir) { "moduleA" }
79
79
  let(:paths) do
80
- %w[path1 path2].map { |p| "#{chdir}#{File::Separator}#{p}" }
80
+ %w(path1 path2).map { |p| "#{chdir}#{File::Separator}#{p}" }
81
81
  end
82
82
 
83
83
  let(:options) do
@@ -88,7 +88,7 @@ RSpec.describe Guard::RSpec::Command do
88
88
  end
89
89
 
90
90
  it "strips path of chdir" do
91
- expect(command).to match %r{path1 path2}
91
+ expect(command).to match(/path1 path2/)
92
92
  end
93
93
  end
94
94
  end
@@ -10,15 +10,17 @@ RSpec.describe Guard::RSpec::Deprecator do
10
10
  it "shows warning if SPEC_OPTS is set" do
11
11
  ENV["SPEC_OPTS"] = "-f p"
12
12
  expect(Guard::Compat::UI).to receive(:warning).with(
13
- "The SPEC_OPTS environment variable is present." +
14
- " This can conflict with guard-rspec.")
13
+ "The SPEC_OPTS environment variable is present." \
14
+ " This can conflict with guard-rspec."
15
+ )
15
16
  deprecator.warns_about_deprecated_options
16
17
  ENV["SPEC_OPTS"] = nil # otherwise other specs pick it up and fail
17
18
  end
18
19
  it "does not show warning if SPEC_OPTS is unset" do
19
20
  expect(Guard::Compat::UI).to_not receive(:warning).with(
20
- "The SPEC_OPTS environment variable is present." +
21
- " This can conflict with guard-rspec.")
21
+ "The SPEC_OPTS environment variable is present." \
22
+ " This can conflict with guard-rspec."
23
+ )
22
24
  deprecator.warns_about_deprecated_options
23
25
  end
24
26
  end
@@ -28,9 +30,10 @@ RSpec.describe Guard::RSpec::Deprecator do
28
30
 
29
31
  it "shows deprecation warning" do
30
32
  expect(Guard::Compat::UI).to receive(:warning).with(
31
- "Guard::RSpec DEPRECATION WARNING:" +
32
- " The :version option is deprecated." +
33
- " Only RSpec ~> 2.14 is now supported.")
33
+ "Guard::RSpec DEPRECATION WARNING:" \
34
+ " The :version option is deprecated." \
35
+ " Only RSpec ~> 2.14 is now supported."
36
+ )
34
37
  deprecator.warns_about_deprecated_options
35
38
  end
36
39
  end
@@ -40,10 +43,11 @@ RSpec.describe Guard::RSpec::Deprecator do
40
43
 
41
44
  it "shows deprecation warning" do
42
45
  expect(Guard::Compat::UI).to receive(:warning).with(
43
- "Guard::RSpec DEPRECATION WARNING:" +
44
- " The :exclude option is deprecated." +
45
- " Please Guard ignore method instead." +
46
- " https://github.com/guard/guard#ignore")
46
+ "Guard::RSpec DEPRECATION WARNING:" \
47
+ " The :exclude option is deprecated." \
48
+ " Please Guard ignore method instead." \
49
+ " https://github.com/guard/guard#ignore"
50
+ )
47
51
  deprecator.warns_about_deprecated_options
48
52
  end
49
53
  end
@@ -55,9 +59,10 @@ RSpec.describe Guard::RSpec::Deprecator do
55
59
 
56
60
  it "shows deprecation warning" do
57
61
  expect(Guard::Compat::UI).to receive(:warning).with(
58
- "Guard::RSpec DEPRECATION WARNING: The :#{option} option is" +
59
- " deprecated. Please customize the new :cmd option to" +
60
- " fit your need.")
62
+ "Guard::RSpec DEPRECATION WARNING: The :#{option} option is" \
63
+ " deprecated. Please customize the new :cmd option to" \
64
+ " fit your need."
65
+ )
61
66
  deprecator.warns_about_deprecated_options
62
67
  end
63
68
  end
@@ -68,11 +73,12 @@ RSpec.describe Guard::RSpec::Deprecator do
68
73
 
69
74
  it "shows deprecation warning" do
70
75
  expect(Guard::Compat::UI).to receive(:warning).with(
71
- "Guard::RSpec DEPRECATION WARNING:" +
72
- " The :keep_failed option is deprecated." +
73
- " Please set new :failed_mode option value to" +
74
- " :keep instead." +
75
- " https://github.com/guard/guard-rspec#list-of-available-options")
76
+ "Guard::RSpec DEPRECATION WARNING:" \
77
+ " The :keep_failed option is deprecated." \
78
+ " Please set new :failed_mode option value to" \
79
+ " :keep instead." \
80
+ " https://github.com/guard/guard-rspec#list-of-available-options"
81
+ )
76
82
  deprecator.warns_about_deprecated_options
77
83
  end
78
84
  end
@@ -82,11 +88,12 @@ RSpec.describe Guard::RSpec::Deprecator do
82
88
 
83
89
  it "shows deprecation warning" do
84
90
  expect(Guard::Compat::UI).to receive(:warning).with(
85
- "Guard::RSpec DEPRECATION WARNING:" +
86
- " The :focus_on_failed option is deprecated." +
87
- " Please set new :failed_mode option value to" +
88
- " :focus instead." +
89
- " https://github.com/guard/guard-rspec#list-of-available-options")
91
+ "Guard::RSpec DEPRECATION WARNING:" \
92
+ " The :focus_on_failed option is deprecated." \
93
+ " Please set new :failed_mode option value to" \
94
+ " :focus instead." \
95
+ " https://github.com/guard/guard-rspec#list-of-available-options"
96
+ )
90
97
  deprecator.warns_about_deprecated_options
91
98
  end
92
99
  end
@@ -44,7 +44,8 @@ RSpec.describe Guard::RSpec::Results do
44
44
  subject.load
45
45
  end.to raise_error(
46
46
  Guard::RSpec::Results::InvalidData,
47
- "Invalid results in: foo/bar.txt, lines:\n[]\n")
47
+ "Invalid results in: foo/bar.txt, lines:\n[]\n"
48
+ )
48
49
  end
49
50
  end
50
51
 
@@ -58,7 +59,8 @@ RSpec.describe Guard::RSpec::Results do
58
59
  subject.load
59
60
  end.to raise_error(
60
61
  Guard::RSpec::Results::InvalidData,
61
- "Invalid results in: foo/bar.txt, lines:\n[\"\"]\n")
62
+ "Invalid results in: foo/bar.txt, lines:\n[\"\"]\n"
63
+ )
62
64
  end
63
65
  end
64
66
  end
@@ -5,14 +5,14 @@ require "guard/rspec/rspec_process"
5
5
  RSpec.describe Guard::RSpec::RSpecProcess do
6
6
  before do
7
7
  allow(Kernel).to receive(:spawn) do |*args|
8
- fail "Not stubbed: Kernel.spawn(#{args.map(&:inspect) * ','})"
8
+ raise "Not stubbed: Kernel.spawn(#{args.map(&:inspect) * ','})"
9
9
  end
10
10
  end
11
11
 
12
12
  let(:results) { instance_double(Guard::RSpec::Results) }
13
13
 
14
14
  let(:cmd) { "foo" }
15
- let(:file) { "foobar.txt" }
15
+ let(:file) { "/tmp/foobar.txt" }
16
16
  let(:pid) { 1234 }
17
17
  let(:exit_code) { 0 }
18
18
  let(:status) { instance_double(Process::Status, exitstatus: exit_code) }
@@ -28,6 +28,8 @@ RSpec.describe Guard::RSpec::RSpecProcess do
28
28
 
29
29
  allow(Guard::RSpec::Results).to receive(:new).
30
30
  with(file).and_return(results)
31
+
32
+ allow(Guard::Compat::UI).to receive(:debug)
31
33
  end
32
34
 
33
35
  context "with an non-existing command" do
@@ -73,6 +75,47 @@ RSpec.describe Guard::RSpec::RSpecProcess do
73
75
  end
74
76
 
75
77
  it { is_expected.to be_all_green }
78
+
79
+ context "with a relative results file path" do
80
+ before do
81
+ allow(Guard::Compat::UI).to receive(:warning)
82
+ end
83
+ let(:file) { "foobar.txt" }
84
+
85
+ it "shows a warning" do
86
+ expect(Guard::Compat::UI).to receive(:warning).
87
+ with(/is not an absolute path/)
88
+ subject
89
+ end
90
+ end
91
+
92
+ context "with a missing results file" do
93
+ before do
94
+ allow(Guard::Compat::UI).to receive(:error)
95
+ end
96
+ before do
97
+ allow(Guard::RSpec::Results).to receive(:new).
98
+ with(file).and_raise(Errno::ENOENT, "foobar.txt")
99
+ end
100
+
101
+ it "shows a message" do
102
+ expect(Guard::Compat::UI).to receive(:error).
103
+ with(/cannot open results file/)
104
+
105
+ begin
106
+ subject
107
+ rescue Errno::ENOENT
108
+ nil
109
+ end
110
+ end
111
+
112
+ it "fails with an error" do
113
+ expect { subject }.to raise_error(
114
+ Errno::ENOENT,
115
+ /No such file or directory - foobar/
116
+ )
117
+ end
118
+ end
76
119
  end
77
120
  end
78
121
  end
@@ -14,6 +14,7 @@ RSpec.describe Guard::RSpec::Runner do
14
14
 
15
15
  before do
16
16
  allow(Guard::Compat::UI).to receive(:info)
17
+ allow(Guard::Compat::UI).to receive(:warning)
17
18
  allow(Guard::Compat::UI).to receive(:error)
18
19
  allow(Guard::RSpec::Inspectors::Factory).to receive(:create) { inspector }
19
20
  allow(Guard::RSpec::Notifier).to receive(:new) { notifier }
@@ -214,7 +215,7 @@ RSpec.describe Guard::RSpec::Runner do
214
215
  let(:chdir_options) { {} }
215
216
 
216
217
  context "when the path is relative" do
217
- let(:results_file) { "foobar.txt" }
218
+ let(:results_file) { File.join(Dir.pwd, "foobar.txt") }
218
219
  it "uses the given file" do
219
220
  expect(Guard::RSpec::RSpecProcess).to receive(:new).
220
221
  with(anything, results_file).and_return(process)
@@ -233,24 +234,60 @@ RSpec.describe Guard::RSpec::Runner do
233
234
  end
234
235
 
235
236
  context "with chdir option" do
236
- let(:chdir_options) { { chdir: "moduleA" } }
237
-
238
- context "when the path is relative" do
239
- let(:results_file) { "foobar.txt" }
237
+ context "when chdir option is absolute" do
238
+ let(:chdir_options) { { chdir: "/foo/bar/moduleA" } }
239
+
240
+ context "when the path is relative" do
241
+ let(:results_file) { "foobar.txt" }
242
+
243
+ it "uses a path relative to chdir" do
244
+ expected = "/foo/bar/moduleA/foobar.txt"
245
+ expect(Guard::RSpec::RSpecProcess).to receive(:new).
246
+ with(anything, expected).and_return(process)
247
+ runner.run(paths)
248
+ end
249
+ end
240
250
 
241
- it "uses a path relative to chdir" do
242
- expect(Guard::RSpec::RSpecProcess).to receive(:new).
243
- with(anything, "moduleA/foobar.txt").and_return(process)
244
- runner.run(paths)
251
+ context "when the path is absolute" do
252
+ let(:results_file) { "/foo/foobar.txt" }
253
+ it "uses the full given path anyway" do
254
+ expect(Guard::RSpec::RSpecProcess).to receive(:new).
255
+ with(anything, results_file).and_return(process)
256
+ runner.run(paths)
257
+ end
245
258
  end
246
259
  end
247
260
 
248
- context "when the path is absolute" do
249
- let(:results_file) { "/foo/foobar.txt" }
250
- it "uses the full given path anyway" do
251
- expect(Guard::RSpec::RSpecProcess).to receive(:new).
252
- with(anything, results_file).and_return(process)
253
- runner.run(paths)
261
+ context "when chdir option is relative" do
262
+ let(:chdir_options) { { chdir: "moduleA" } }
263
+ before do
264
+ allow(Guard::Compat::UI).to receive(:warning)
265
+ end
266
+
267
+ context "when the path is relative" do
268
+ let(:results_file) { "foobar.txt" }
269
+
270
+ it "uses a path relative to chdir" do
271
+ expected = File.join(Dir.pwd, "moduleA/foobar.txt")
272
+ expect(Guard::RSpec::RSpecProcess).to receive(:new).
273
+ with(anything, expected).and_return(process)
274
+ runner.run(paths)
275
+ end
276
+
277
+ it "shows a warning" do
278
+ expect(Guard::Compat::UI).to receive(:warning).
279
+ with(/is not an absolute path/)
280
+ runner.run(paths)
281
+ end
282
+ end
283
+
284
+ context "when the path is absolute" do
285
+ let(:results_file) { "/foo/foobar.txt" }
286
+ it "uses the full given path anyway" do
287
+ expect(Guard::RSpec::RSpecProcess).to receive(:new).
288
+ with(anything, results_file).and_return(process)
289
+ runner.run(paths)
290
+ end
254
291
  end
255
292
  end
256
293
  end
@@ -260,7 +297,7 @@ RSpec.describe Guard::RSpec::Runner do
260
297
  let(:options) { { cmd: "rspec" } }
261
298
  it "uses the default" do
262
299
  expect(Guard::RSpec::RSpecProcess).to receive(:new).
263
- with(anything, "tmp/rspec_guard_result").and_return(process)
300
+ with(anything, %r{/tmp/rspec_guard_result$}).and_return(process)
264
301
  runner.run(paths)
265
302
  end
266
303
  end