rspec-expectations
rspec-expectations copied to clipboard
`include` breaks with a time/float ranges
Subject of the issue
include
breaks with a time range
Originally reported by @schwern in https://github.com/rubocop-hq/rubocop-rspec/issues/926
Your environment
- Ruby version: 2.7.1
- rspec-expectations version:
master
(eb1787f
)
Steps to reproduce
RSpec.describe 'include' do
it do # works
range = (3..5)
expect(range).not_to include(6)
end
range = (Time.now-20...Time.now-10)
now = Time.now
it do # works
expect(range.include?(now)).not_to be true
end
it do # breaks
expect(range).not_to include(now)
end
end
Expected behavior
All examples pass
Actual behavior
The example with a time range and include
matcher fails with:
1) include is expected not to include 2020-06-11 10:47:01.120378000 +0300
Failure/Error: expect(range).not_to include(now)
TypeError:
can't iterate from Time
# ./lib/rspec/matchers/built_in/include.rb:134:in `each'
# ./lib/rspec/matchers/built_in/include.rb:134:in `any?'
# ./lib/rspec/matchers/built_in/include.rb:134:in `actual_collection_includes?'
It breaks on Float as well.
require 'rspec'
describe 'include' do
it 'is not equivalent' do
obj = 2.5
range = (obj...obj)
expect(range.include?(obj)).to be_falsey # pass
expect(range).not_to include(obj) # TypeError: can't iterate from Float
end
end
Hi @pirj, @schwern, @JonRowe! I just put out a PR that attempts to address this issue. Would one of you mind giving it a review when you get a chance?
@bclayman-sq Certainly. We're always watching. 👀
Hi @pirj, thanks again for kicking off those builds for me!
I've fixed up a couple issues causing a failing build and think this one should pass. In particular, I've now targeted ruby versions >= 2.1.9 for this improvement. Assuming CI passes, I'll update the docs to indicate these improvements are available for >= 2.1.9. How does that sound to you?
Bump.