/
keeping_inspector_spec.rb
200 lines (170 loc) · 6.2 KB
/
keeping_inspector_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
require "guard/compat/test/helper"
require "lib/guard/rspec/inspectors/shared_examples"
require "guard/rspec/inspectors/keeping_inspector"
klass = Guard::RSpec::Inspectors::KeepingInspector
RSpec.describe klass do
include_examples "inspector", klass
# Use real paths because BaseInspector#_clean will be used to clean them
let(:other_paths) do
[
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb",
"spec/lib/guard/rspec/runner_spec.rb"
]
end
let(:other_failed_locations) do
[
"./spec/lib/guard/rspec/runner_spec.rb:12",
"./spec/lib/guard/rspec/runner_spec.rb:100",
"./spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb:12"
]
end
it "remembers failed paths and returns them along with new paths" do
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/inspectors/base_inspector_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/runner_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/deprecator_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb").
and_return(false)
allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
and_return(paths + other_paths)
allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*[_.]spec.rb").
and_return([])
allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*.feature").
and_return([])
allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*.feature").
and_return([])
expect(inspector.paths(paths)).to eq(paths)
inspector.failed(failed_locations)
# Line numbers in failed_locations needs to be omitted because of
# https://github.com/rspec/rspec-core/issues/952
expect(inspector.paths(other_paths)).to match_array(
[
"spec/lib/guard/rspec/deprecator_spec.rb",
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb"
]
)
inspector.failed(other_failed_locations)
# Now it returns other failed locations
expect(
inspector.paths(
%w(spec/lib/guard/rspec/inspectors/base_inspector_spec.rb)
)
).to match_array(
[
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb",
"spec/lib/guard/rspec/inspectors/base_inspector_spec.rb"
]
)
inspector.failed(other_failed_locations)
expect(
inspector.paths(%w(spec/lib/guard/rspec/runner_spec.rb))
).to match_array(
[
"spec/lib/guard/rspec/runner_spec.rb",
"spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb"
]
)
inspector.failed([])
# Now there is no failed locations
expect(inspector.paths(paths)).to match_array(paths)
end
describe "#reload" do
it "force to forget about failed locations" do
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/inspectors/base_inspector_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/runner_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/deprecator_spec.rb").
and_return(false)
allow(File).to receive(:directory?).
with("spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb").
and_return(false)
allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*[_.]spec.rb").
and_return(paths + other_paths)
allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*[_.]spec.rb").
and_return([])
allow(Dir).to receive(:[]).with("myspec/**{,/*/**}/*.feature").
and_return([])
allow(Dir).to receive(:[]).with("spec/**{,/*/**}/*.feature").
and_return([])
expect(inspector.paths(paths)).to eq(paths)
inspector.failed(failed_locations)
inspector.reload
expect(inspector.paths(other_paths)).to match_array(other_paths)
end
end
end
#
# FIXME uncomment when RSpec #952 will be resolved
#
# This is correct spec for KeepingInspector class,
# bit it doesn't work because of bug with RSpec
# https://github.com/rspec/rspec-core/issues/952
#
# describe klass do
# include_examples 'inspector', klass
#
# # Use real paths because BaseInspector#_clean will be used to clean them
# let(:other_paths) { [
# 'spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb',
# 'spec/lib/guard/rspec/runner_spec.rb'
# ] }
# let(:other_failed_locations) { [
# './spec/lib/guard/rspec/runner_spec.rb:12',
# './spec/lib/guard/rspec/runner_spec.rb:100',
# './spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb:12'
# ] }
#
# it 'remembers failed paths and returns them along with new paths' do
# expect(inspector.paths(paths)).to eq(paths)
# inspector.failed(failed_locations)
#
# # other_paths and failed_locations contain the same spec (runner_spec.rb)
# # so #paths should return that spec only once (omit location)
# expect(inspector.paths(other_paths)).to match_array(
# other_paths +
# %w[./spec/lib/guard/rspec/deprecator_spec.rb:55]
# )
# inspector.failed(other_failed_locations)
#
# # Now it returns other failed locations
# expect(inspector.paths(%w[spec/lib/guard/rspec/deprecator_spec.rb])).to
# match_array(
# other_failed_locations +
# %w[spec/lib/guard/rspec/deprecator_spec.rb]
# )
# inspector.failed(other_failed_locations)
#
# # It returns runner_spec.rb without locations in that spec
# expect(inspector.paths(%w[spec/lib/guard/rspec/runner_spec.rb])).
# to match_array([
# './spec/lib/guard/rspec/inspectors/simple_inspector_spec.rb:12',
# 'spec/lib/guard/rspec/runner_spec.rb'
# ])
# inspector.failed([])
#
# # Now there is no failed locations
# expect(inspector.paths(paths)).to match_array(paths)
# end
#
# describe '#reload' do
# it 'force to forget about failed locations' do
# expect(inspector.paths(paths)).to eq(paths)
# inspector.failed(failed_locations)
#
# inspector.reload
# expect(inspector.paths(other_paths)).to match_array(other_paths)
# end
# end
# end