Skip to content

Commit 0e34593

Browse files
committed
prefer :parent_example_group metadata (>= RSpec 3)
- :example_group is deprecated since RSpec 3.0.0 - missing spec was added (for nested shared groups)
1 parent 1e71c21 commit 0e34593

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/guard/rspec_formatter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def self.extract_spec_location(metadata)
3333
location = metadata[:location]
3434

3535
until spec_path?(location)
36-
metadata = metadata[:example_group]
36+
metadata = metadata[:parent_example_group] || metadata[:example_group]
3737

3838
unless metadata
39-
STDERR.puts "no spec file found for #{root_metadata[:location]}"
39+
STDERR.puts "no spec file location in #{root_metadata.inspect}"
4040
return root_metadata[:location]
4141
end
4242

spec/lib/guard/rspec_formatter_spec.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,43 @@ def expected_output(spec_filename)
145145
}
146146

147147
expect(STDERR).to receive(:puts).
148-
with("no spec file found for #{metadata[:location]}") {}
148+
with("no spec file location in #{metadata.inspect}")
149149

150150
expect(described_class.extract_spec_location(metadata)).
151151
to eq metadata[:location]
152152
end
153153
end
154154

155+
context "when a shared examples are nested" do
156+
it "should return location of the root spec" do
157+
metadata = {
158+
location: "./spec/support/breadcrumbs.rb:75",
159+
example_group: {
160+
example_group: {
161+
location: "./spec/requests/breadcrumbs_spec.rb:218"
162+
}
163+
}
164+
}
165+
166+
expect(described_class.extract_spec_location(metadata)).
167+
to eq "./spec/requests/breadcrumbs_spec.rb"
168+
end
169+
end
170+
171+
context "when RSpec 3.0 metadata is present" do
172+
it "should return location of the root spec" do
173+
metadata = {
174+
location: "./spec/support/breadcrumbs.rb:75",
175+
parent_example_group: {
176+
location: "./spec/requests/breadcrumbs_spec.rb:218"
177+
}
178+
}
179+
180+
expect(described_class.extract_spec_location(metadata)).
181+
to eq "./spec/requests/breadcrumbs_spec.rb"
182+
end
183+
end
184+
155185
context "with only success" do
156186
it "notifies success" do
157187
formatter.dump_summary(*summary_with_no_failures)

0 commit comments

Comments
 (0)