Skip to content

Commit fd47d3a

Browse files
committed
Make linter happy.
Replace the sugared rspec helpers with core matchers.
1 parent b763325 commit fd47d3a

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ Metrics/BlockLength:
1313

1414
Style/IfUnlessModifier:
1515
Enabled: false
16+
17+
Metrics/BlockLength:
18+
Max: 35
19+
Exclude:
20+
- 'spec/*/*_spec.rb'

lib/jsonapi/rspec/attributes.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Attributes
55
match do |actual|
66
actual = JSONAPI::RSpec.as_indifferent_hash(actual)
77
@attributes_node = actual['attributes']
8-
8+
99
return false unless @attributes_node
1010

1111
@has_attribute = @attributes_node.key?(attr.to_s)
@@ -34,11 +34,13 @@ module Attributes
3434
result
3535
end
3636

37-
failure_message do |actual|
37+
failure_message do |_actual|
3838
if @has_attribute
39-
"expected `#{attr}` attribute to have value `#{@expected}` but was `#{@actual}`"
39+
"expected `#{attr}` attribute " \
40+
"to have value `#{@expected}` but was `#{@actual}`"
4041
else
41-
"expected attributes to include `#{attr}`. Actual attributes were #{@attributes_node.keys}"
42+
"expected attributes to include `#{attr}`. " \
43+
"Actual attributes were #{@attributes_node.keys}"
4244
end
4345
end
4446

spec/jsonapi/attributes_spec.rb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@
2020
it { expect(doc).to have_attribute(:six).with_value(foo: 'bar') }
2121

2222
it 'rejects with an appropriate failure message' do
23-
expect {
24-
expect(doc).to have_attribute(:three)
25-
}.to fail_with('expected attributes to include `three`. Actual attributes were ["one", "two", "four", "six"]')
23+
expect { expect(doc).to have_attribute(:three) }
24+
.to raise_error(
25+
RSpec::Expectations::ExpectationNotMetError,
26+
'expected attributes to include `three`. ' \
27+
'Actual attributes were ["one", "two", "four", "six"]'
28+
)
2629
end
2730

28-
it 'rejects with an appropriate failure message for chained with_value, simple values' do
29-
expect {
30-
expect(doc).to have_attribute(:one).with_value(2)
31-
}.to fail_with('expected `one` attribute to have value `2` but was `1`')
31+
it 'fails with a failure message for chained with_value' do
32+
expect { expect(doc).to have_attribute(:one).with_value(2) }
33+
.to raise_error(
34+
RSpec::Expectations::ExpectationNotMetError,
35+
/expected `one` attribute to have value `2` but was `1`/m
36+
)
3237
end
3338

34-
it 'rejects with an appropriate failure message for chained with_value, complex values show diff' do
35-
expect {
36-
expect(doc).to have_attribute(:six).with_value(bar: 'baz')
37-
}.to fail_with(/expected `six` attribute to have value `{:bar=>"baz"}` but was `{:foo=>"bar"}`.*Diff:/m)
39+
it 'fails with a failure message and diff for chained with_value' do
40+
expect { expect(doc).to have_attribute(:six).with_value(bar: 'baz') }
41+
.to raise_error(
42+
RSpec::Expectations::ExpectationNotMetError,
43+
/expected `six` .* `{:bar=>"baz"}` but was `{:foo=>"bar"}`.*Diff:/m
44+
)
3845
end
3946
end
4047

spec/spec_helper.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,8 @@
66
end
77
SimpleCov.minimum_coverage 90
88

9-
module FailMatchers
10-
def fail
11-
raise_error(RSpec::Expectations::ExpectationNotMetError)
12-
end
13-
14-
def fail_with(message)
15-
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
16-
end
17-
18-
def fail_including(snippet)
19-
raise_error(
20-
RSpec::Expectations::ExpectationNotMetError,
21-
a_string_including(snippet)
22-
)
23-
end
24-
end
25-
269
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
2710
RSpec.configure do |config|
28-
config.include FailMatchers
29-
3011
config.expect_with :rspec do |expectations|
3112
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
3213
end

0 commit comments

Comments
 (0)