-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
When I test objects that has an attribute which is an array of ranges, the have_attributes
matcher doesn't detect difference when expected range contains the actual range. So this fails as it should:
let(:has_ranges) { OpenStruct.new(ranges: [0...10]) }
it 'detects incorrect range' do
expect(has_ranges).to have_attributes(ranges: [1...10])
end
But this passes fine:
let(:has_ranges) { OpenStruct.new(ranges: [0...10]) }
it 'detects incorrect range' do
expect(has_ranges).to have_attributes(ranges: [-1...11])
end
The problem seems to be in this file:
rspec/support/fuzzy_matcher.rb
10| def self.values_match?(expected, actual)
11| if Hash === actual
12| return hashes_match?(expected, actual) if Hash === expected
13| elsif Array === expected && Enumerable === actual && !(Struct === actual)
14| return arrays_match?(expected, actual.to_a)
15| end
16|
17| return true if expected == actual
18|
19| begin
20| expected === actual
21| rescue ArgumentError
22| # Some objects, like 0-arg lambdas on 1.9+, raise
23| # ArgumentError for `expected === actual`.
24| false
25| end
26| end
So ranges are compared at line 20 using ===
which tests whether lhs covers rhs
My setup:
rspec-core (3.13.5)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
rspec-support (~> 3.13.0)
rspec-rails (6.0.4)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.13.4)
rubocop-rspec (3.3.0)
rspec-rails (~> 6.0.0.rc1)
Metadata
Metadata
Assignees
Labels
No labels