Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix for RSpec deprecation warning, take III #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions spec/lib/guard/rspec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ def rspec_summary_args(*args)
[n.new(*args)]
end

# Returns a Hash that throws an error if a key is accessed that isn't set.
def hash_double(attrs)
dbl = Hash.new{|hsh, key| raise "Missing key: #{key.inspect}." }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused block argument - hsh. If it's necessary, use _ or _hsh as an argument name to indicate that it won't be used.
Space missing to the left of {.
Space between { and | missing.

dbl.merge(attrs)
end

let(:example_dump_summary_args) { rspec_summary_args(123, 3, 1, 0) }
let(:summary_with_no_failures) { rspec_summary_args(123, 3, 0, 0) }
let(:summary_with_only_pending) { rspec_summary_args(123, 3, 0, 1) }
Expand Down Expand Up @@ -119,10 +125,10 @@ def expected_output(spec_filename)
end

it "should find the spec file for shared examples" do
metadata = {
metadata = hash_double(
location: "./spec/support/breadcrumbs.rb:75",
example_group: { location: "./spec/requests/breadcrumbs_spec.rb:218" }
}
)

result = described_class.extract_spec_location(metadata)
expect(result).to start_with "./spec/requests/breadcrumbs_spec.rb"
Expand All @@ -131,20 +137,20 @@ def expected_output(spec_filename)
# Skip location because of rspec issue
# https://github.com/rspec/rspec-core/issues/1243
it "returns only the spec file without line number for shared examples" do
metadata = {
metadata = hash_double(
location: "./spec/support/breadcrumbs.rb:75",
example_group: { location: "./spec/requests/breadcrumbs_spec.rb:218" }
}
)
expect(described_class.extract_spec_location(metadata)).
to eq "./spec/requests/breadcrumbs_spec.rb"
end

context "when a shared examples has no location" do
it "should return location of the root spec" do
metadata = {
metadata = hash_double(
location: "./spec/support/breadcrumbs.rb:75",
example_group: {}
}
)

expect(STDERR).to receive(:puts).
with("no spec file location in #{metadata.inspect}")
Expand All @@ -156,14 +162,14 @@ def expected_output(spec_filename)

context "when a shared examples are nested" do
it "should return location of the root spec" do
metadata = {
metadata = hash_double(
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"
Expand All @@ -172,12 +178,12 @@ def expected_output(spec_filename)

context "when RSpec 3.0 metadata is present" do
it "should return location of the root spec" do
metadata = {
metadata = hash_double(
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"
Expand Down