Skip to content

Commit

Permalink
prefer :parent_example_group metadata (>= RSpec 3)
Browse files Browse the repository at this point in the history
- :example_group is deprecated since RSpec 3.0.0
- missing spec was added (for nested shared groups)
  • Loading branch information
e2 committed Jun 26, 2015
1 parent 1e71c21 commit 0e34593
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/guard/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def self.extract_spec_location(metadata)
location = metadata[:location]

until spec_path?(location)
metadata = metadata[:example_group]
metadata = metadata[:parent_example_group] || metadata[:example_group]

unless metadata
STDERR.puts "no spec file found for #{root_metadata[:location]}"
STDERR.puts "no spec file location in #{root_metadata.inspect}"
return root_metadata[:location]
end

Expand Down
32 changes: 31 additions & 1 deletion spec/lib/guard/rspec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,43 @@ def expected_output(spec_filename)
}

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

expect(described_class.extract_spec_location(metadata)).
to eq metadata[:location]
end
end

context "when a shared examples are nested" do
it "should return location of the root spec" do
metadata = {
location: "./spec/support/breadcrumbs.rb:75",
example_group: {
example_group: {
location: "./spec/requests/breadcrumbs_spec.rb:218"
}
}
}

expect(described_class.extract_spec_location(metadata)).
to eq "./spec/requests/breadcrumbs_spec.rb"
end
end

context "when RSpec 3.0 metadata is present" do
it "should return location of the root spec" do
metadata = {
location: "./spec/support/breadcrumbs.rb:75",
parent_example_group: {
location: "./spec/requests/breadcrumbs_spec.rb:218"
}
}

expect(described_class.extract_spec_location(metadata)).
to eq "./spec/requests/breadcrumbs_spec.rb"
end
end

context "with only success" do
it "notifies success" do
formatter.dump_summary(*summary_with_no_failures)
Expand Down

0 comments on commit 0e34593

Please sign in to comment.