Skip to content

[rspec-expectations] Fix Include Matcher For Ranges #125

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Nov 30, 2024

This is rspec/rspec-expectations#1324

This PR addresses issue #1191 for ruby >= 2.1.9.

Previously, a few parts of the Include matcher assumed all Ranges were iterable. This caused it to raise errors like TypeError: Can't iterate from [Float|Time]

This happens because Ranges require that their beginning element implement succ. Float doesn't, which causes the error. Time is different because it does implement succ but

a) Range#succ is deprecated as of ruby 1.9.2 and
b) Some Ruby implementations raise an exception when trying to iterate through a range of Time objects

This PR does a few things:

  1. Fixes the Include matcher to handle Ranges that don't support iteration, while continuing to support Ranges that do
  2. Adds specs for both types of Ranges in 1). There weren't any for the Include matcher used with Ranges.

bclayman-sq and others added 3 commits November 30, 2024 11:52
This is issue #1191.

Previously, a few parts of the Include matcher assumed all Ranges
were iterable.  This caused it to raise errors like:
TypeError: Can't iterate from [Float|Time]

This happens because Ranges require that their beginning element implement
succ.  Float doesn't which causes the error.  Time is different because it
does implement succ but a) it's deprecated as of Ruby 1.9.2 and b) some Ruby
implementations raise an exception when trying to iterate through a range of
Time objects.

This PR does a few things:
1) Fixes the Include matcher to handle Ranges that don't support iteration, while
continuing to support Ranges that do
2) Adds specs for both types of Ranges in 1).  There weren't any for the Include matcher
used with Ranges.
@JonRowe JonRowe changed the base branch from dev to main December 3, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants