guard-rspec 4.5.1 → 4.5.2
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.
- checksums.yaml +4 -4
- data/lib/guard/rspec/dsl.rb +13 -1
- data/lib/guard/rspec/results.rb +23 -0
- data/lib/guard/rspec/runner.rb +11 -22
- data/lib/guard/rspec/version.rb +1 -1
- data/spec/lib/guard/rspec/command_spec.rb +2 -1
- data/spec/lib/guard/rspec/results_spec.rb +64 -0
- data/spec/lib/guard/rspec/runner_spec.rb +13 -14
- data/spec/lib/guard/rspec/template_spec.rb +18 -2
- data/spec/lib/guard/rspec_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b73f6aa6d19416f25c3e8676cc9e86c55a90a7b
|
4
|
+
data.tar.gz: 9644dbe8c3990614582c08a94ab777e65be380c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e9c1fc933b6de01ceb7ee36fa3cee4a22c820b219447a4777e105980d0e583434861059fadd3ebb6a25954e2a801471c1a9a8138a8d54bfcb1ff90d1e5d0c9
|
7
|
+
data.tar.gz: 7171db95c19c8a42488fb4d384819aeb5305e9f65821c352d11aa1ac4775448ed672f031bf6887d8427378bf97b99217712f5a9ace4d3ed6d5bef82811c18bb6
|
data/lib/guard/rspec/dsl.rb
CHANGED
@@ -13,10 +13,22 @@ module Guard
|
|
13
13
|
@dsl.send(:watch, expr) { |m| rspec.spec.(m[1]) }
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.detect_spec_file_for(rspec, file)
|
17
|
+
# TODO: when spec not found ... run specs in topmost found path?
|
18
|
+
# Or show warning?
|
19
|
+
|
20
|
+
path = "#{rspec.spec_dir}/#{file}_spec.rb"
|
21
|
+
return path unless file.start_with?("lib/")
|
22
|
+
return path if Dir.exist?("#{rspec.spec_dir}/lib")
|
23
|
+
|
24
|
+
without_lib = file.sub(/^lib\//, "")
|
25
|
+
"#{rspec.spec_dir}/#{without_lib}_spec.rb"
|
26
|
+
end
|
27
|
+
|
16
28
|
def rspec
|
17
29
|
@rspec ||= OpenStruct.new(to_s: "spec").tap do |rspec|
|
18
30
|
rspec.spec_dir = "spec"
|
19
|
-
rspec.spec = ->(m) {
|
31
|
+
rspec.spec = ->(m) { Dsl.detect_spec_file_for(rspec, m) }
|
20
32
|
rspec.spec_helper = "#{rspec.spec_dir}/spec_helper.rb"
|
21
33
|
rspec.spec_files = %r{^#{rspec.spec_dir}/.+_spec\.rb$}
|
22
34
|
rspec.spec_support = %r{^#{rspec.spec_dir}/support/(.+)\.rb$}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Guard
|
2
|
+
class RSpec < Plugin
|
3
|
+
class Results
|
4
|
+
class InvalidData < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :summary
|
8
|
+
attr_reader :failed_paths
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
lines = File.readlines(filename)
|
12
|
+
if lines.empty? || lines.first.empty?
|
13
|
+
dump = lines.inspect
|
14
|
+
fail InvalidData, "Invalid results in: #{filename},"\
|
15
|
+
" lines:\n#{dump}\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
@summary = lines.first.chomp
|
19
|
+
@failed_paths = lines[1..11].map(&:chomp).compact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/guard/rspec/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "guard/rspec/inspectors/factory"
|
2
2
|
require "guard/rspec/command"
|
3
3
|
require "guard/rspec/notifier"
|
4
|
+
require "guard/rspec/results"
|
4
5
|
|
5
6
|
module Guard
|
6
7
|
class RSpec < Plugin
|
@@ -41,8 +42,12 @@ module Guard
|
|
41
42
|
return unless _cmd_option_present(options)
|
42
43
|
command = Command.new(paths, options)
|
43
44
|
|
44
|
-
_without_bundler_env { Kernel.system(command) }.tap do |
|
45
|
-
|
45
|
+
_without_bundler_env { Kernel.system(command) }.tap do |result|
|
46
|
+
if _command_success?(result)
|
47
|
+
_process_run_result(result, all)
|
48
|
+
else
|
49
|
+
notifier.notify_failure
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
@@ -68,13 +73,7 @@ module Guard
|
|
68
73
|
|
69
74
|
def _command_output
|
70
75
|
formatter_tmp_file = _tmp_file(options[:chdir])
|
71
|
-
|
72
|
-
summary = lines.first.strip
|
73
|
-
failed_paths = lines[1..11].map(&:strip).compact
|
74
|
-
|
75
|
-
[summary, failed_paths]
|
76
|
-
rescue
|
77
|
-
[nil, nil]
|
76
|
+
Results.new(formatter_tmp_file)
|
78
77
|
ensure
|
79
78
|
File.delete(formatter_tmp_file) if File.exist?(formatter_tmp_file)
|
80
79
|
end
|
@@ -92,19 +91,9 @@ module Guard
|
|
92
91
|
end
|
93
92
|
|
94
93
|
def _process_run_result(result, all)
|
95
|
-
|
96
|
-
|
97
|
-
|
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)
|
94
|
+
results = _command_output
|
95
|
+
inspector.failed(results.failed_paths)
|
96
|
+
notifier.notify(results.summary)
|
108
97
|
_open_launchy
|
109
98
|
|
110
99
|
_run_all_after_pass if !all && result
|
data/lib/guard/rspec/version.rb
CHANGED
@@ -35,7 +35,8 @@ RSpec.describe Guard::RSpec::Command do
|
|
35
35
|
|
36
36
|
before do
|
37
37
|
allow(RSpec::Core::ConfigurationOptions).to receive(:new) do
|
38
|
-
|
38
|
+
instance_double(RSpec::Core::ConfigurationOptions,
|
39
|
+
options: { formatters: formatters })
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "guard/compat/test/helper"
|
2
|
+
|
3
|
+
require "guard/rspec/results"
|
4
|
+
|
5
|
+
RSpec.describe Guard::RSpec::Results do
|
6
|
+
subject do
|
7
|
+
described_class.new("foo/bar.txt")
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(File).to receive(:readlines).with("foo/bar.txt").and_return(data)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with valid data" do
|
15
|
+
let(:data) do
|
16
|
+
[
|
17
|
+
"5 examples, 2 failures (3 pending)\n",
|
18
|
+
"foo1/bar1_spec.rb\n",
|
19
|
+
"foo1/bar2_spec.rb\n",
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#summary" do
|
24
|
+
it "sets a summary" do
|
25
|
+
expect(subject.summary).to eq("5 examples, 2 failures (3 pending)")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#failures" do
|
30
|
+
it "sets a list of failures" do
|
31
|
+
expect(subject.failed_paths).
|
32
|
+
to eq(%w(foo1/bar1_spec.rb foo1/bar2_spec.rb))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with no data" do
|
38
|
+
let(:data) do
|
39
|
+
[]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "crashes" do
|
43
|
+
expect do
|
44
|
+
subject.load
|
45
|
+
end.to raise_error(
|
46
|
+
Guard::RSpec::Results::InvalidData,
|
47
|
+
"Invalid results in: foo/bar.txt, lines:\n[]\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with invalid data" do
|
52
|
+
let(:data) do
|
53
|
+
[""]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "crashes" do
|
57
|
+
expect do
|
58
|
+
subject.load
|
59
|
+
end.to raise_error(
|
60
|
+
Guard::RSpec::Results::InvalidData,
|
61
|
+
"Invalid results in: foo/bar.txt, lines:\n[\"\"]\n")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -7,8 +7,9 @@ require "guard/rspec/runner"
|
|
7
7
|
RSpec.describe Guard::RSpec::Runner do
|
8
8
|
let(:options) { { cmd: "rspec" } }
|
9
9
|
let(:runner) { Guard::RSpec::Runner.new(options) }
|
10
|
-
let(:inspector) {
|
11
|
-
let(:notifier) {
|
10
|
+
let(:inspector) { instance_double(Guard::RSpec::Inspectors::SimpleInspector) }
|
11
|
+
let(:notifier) { instance_double(Guard::RSpec::Notifier) }
|
12
|
+
let(:results) { instance_double(Guard::RSpec::Results) }
|
12
13
|
|
13
14
|
before do
|
14
15
|
allow(Guard::Compat::UI).to receive(:info)
|
@@ -19,6 +20,11 @@ RSpec.describe Guard::RSpec::Runner do
|
|
19
20
|
allow(notifier).to receive(:notify)
|
20
21
|
allow(notifier).to receive(:notify_failure)
|
21
22
|
|
23
|
+
allow(Guard::RSpec::Results).to receive(:new).
|
24
|
+
with("tmp/rspec_guard_result").and_return(results)
|
25
|
+
allow(results).to receive(:summary).and_return("Summary")
|
26
|
+
allow(results).to receive(:failed_paths).and_return([])
|
27
|
+
|
22
28
|
$CHILD_STATUS = double("exitstatus", exitstatus: 0)
|
23
29
|
end
|
24
30
|
|
@@ -68,7 +74,6 @@ RSpec.describe Guard::RSpec::Runner do
|
|
68
74
|
|
69
75
|
before do
|
70
76
|
allow(inspector).to receive(:failed)
|
71
|
-
allow(File).to receive(:readlines).and_return([])
|
72
77
|
end
|
73
78
|
|
74
79
|
it "builds commands with spec paths" do
|
@@ -136,10 +141,7 @@ RSpec.describe Guard::RSpec::Runner do
|
|
136
141
|
describe "#run" do
|
137
142
|
let(:paths) { %w(spec_path1 spec_path2) }
|
138
143
|
before do
|
139
|
-
tmp_file = "tmp/rspec_guard_result"
|
140
|
-
allow(File).to receive(:readlines).with(tmp_file) { ["Summary\n"] }
|
141
144
|
allow(inspector).to receive(:paths) { paths }
|
142
|
-
allow(inspector).to receive(:clear_paths) { true }
|
143
145
|
allow(inspector).to receive(:failed)
|
144
146
|
end
|
145
147
|
|
@@ -195,15 +197,12 @@ RSpec.describe Guard::RSpec::Runner do
|
|
195
197
|
|
196
198
|
context "with failed paths" do
|
197
199
|
before do
|
198
|
-
allow(
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
"./failed_spec.rb:123\n",
|
203
|
-
"./other/failed_spec.rb:77\n"
|
204
|
-
]
|
205
|
-
end
|
200
|
+
allow(results).to receive(:failed_paths).and_return([
|
201
|
+
"./failed_spec.rb:123",
|
202
|
+
"./other/failed_spec.rb:77"
|
203
|
+
])
|
206
204
|
end
|
205
|
+
|
207
206
|
it "notifies inspector about failed paths" do
|
208
207
|
expect(inspector).to receive(:failed).
|
209
208
|
with(["./failed_spec.rb:123", "./other/failed_spec.rb:77"])
|
@@ -14,8 +14,24 @@ RSpec.describe "Guard::RSpec" do
|
|
14
14
|
expect(subject.changed("spec/spec_helper.rb")).to eq(%w(spec))
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
describe "mapping files to specs" do
|
18
|
+
before do
|
19
|
+
allow(Dir).to receive(:exist?).with("spec/lib").and_return(has_spec_lib)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when spec/lib exists" do
|
23
|
+
let(:has_spec_lib) { true }
|
24
|
+
it "matches Ruby files with files in spec/lib" do
|
25
|
+
expect(subject.changed("lib/foo.rb")).to eq(%w(spec/lib/foo_spec.rb))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when spec/lib does not exist" do
|
30
|
+
let(:has_spec_lib) { false }
|
31
|
+
it "matches Ruby files with files in spec/lib" do
|
32
|
+
expect(subject.changed("lib/foo.rb")).to eq(%w(spec/foo_spec.rb))
|
33
|
+
end
|
34
|
+
end
|
19
35
|
end
|
20
36
|
|
21
37
|
it "matches Rails files by default" do
|
@@ -5,7 +5,7 @@ RSpec.describe Guard::RSpec do
|
|
5
5
|
let(:default_options) { Guard::RSpec::Options::DEFAULTS }
|
6
6
|
let(:options) { {} }
|
7
7
|
let(:plugin) { Guard::RSpec.new(options) }
|
8
|
-
let(:runner) {
|
8
|
+
let(:runner) { instance_double(Guard::RSpec::Runner) }
|
9
9
|
|
10
10
|
before do
|
11
11
|
allow(Guard::Compat::UI).to receive(:info)
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,14 @@ end
|
|
8
8
|
rspec_version = ::RSpec::Version::STRING.to_f
|
9
9
|
old_rspec = (rspec_version < 3)
|
10
10
|
|
11
|
+
if old_rspec
|
12
|
+
class RSpec::Core::ExampleGroup
|
13
|
+
def instance_double(*args)
|
14
|
+
double(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
20
|
RSpec.configure do |config|
|
13
21
|
config.expect_with :rspec do |expectations|
|
@@ -89,6 +97,12 @@ RSpec.configure do |config|
|
|
89
97
|
config.raise_errors_for_deprecations!
|
90
98
|
|
91
99
|
config.before do
|
100
|
+
%w(exist?).each do |meth|
|
101
|
+
allow(Dir).to receive(meth.to_sym) do |*args|
|
102
|
+
abort "stub me: Dir.#{meth}(#{args.map(&:inspect) * ','})!"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
92
106
|
allow(Dir).to receive(:[]) do |*args|
|
93
107
|
abort "stub me: Dir[#{args.first}]!"
|
94
108
|
end
|
@@ -99,7 +113,7 @@ RSpec.configure do |config|
|
|
99
113
|
end
|
100
114
|
end
|
101
115
|
|
102
|
-
%w(mkdir).each do |meth|
|
116
|
+
%w(mkdir mkdir_p).each do |meth|
|
103
117
|
allow(FileUtils).to receive(meth.to_sym) do |*args|
|
104
118
|
abort "stub me: FileUtils.#{meth}(#{args.map(&:inspect) * ','})!"
|
105
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/guard/rspec/inspectors/simple_inspector.rb
|
141
141
|
- lib/guard/rspec/notifier.rb
|
142
142
|
- lib/guard/rspec/options.rb
|
143
|
+
- lib/guard/rspec/results.rb
|
143
144
|
- lib/guard/rspec/runner.rb
|
144
145
|
- lib/guard/rspec/templates/Guardfile
|
145
146
|
- lib/guard/rspec/version.rb
|
@@ -153,6 +154,7 @@ files:
|
|
153
154
|
- spec/lib/guard/rspec/inspectors/shared_examples.rb
|
154
155
|
- spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb
|
155
156
|
- spec/lib/guard/rspec/notifier_spec.rb
|
157
|
+
- spec/lib/guard/rspec/results_spec.rb
|
156
158
|
- spec/lib/guard/rspec/runner_spec.rb
|
157
159
|
- spec/lib/guard/rspec/template_spec.rb
|
158
160
|
- spec/lib/guard/rspec_formatter_spec.rb
|
@@ -192,6 +194,7 @@ test_files:
|
|
192
194
|
- spec/lib/guard/rspec/inspectors/shared_examples.rb
|
193
195
|
- spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb
|
194
196
|
- spec/lib/guard/rspec/notifier_spec.rb
|
197
|
+
- spec/lib/guard/rspec/results_spec.rb
|
195
198
|
- spec/lib/guard/rspec/runner_spec.rb
|
196
199
|
- spec/lib/guard/rspec/template_spec.rb
|
197
200
|
- spec/lib/guard/rspec_formatter_spec.rb
|