-
-
Save jGRUBBS/b8b7a3cce9fbc3808f8fff5b25c342b1 to your computer and use it in GitHub Desktop.
An RSpec matcher to check for intersection between two enumerables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spec::Matchers.define :intersect_with do |challenge_range| | |
# Check to see if any elements exist in the intersection | |
match do |current_range| | |
[current_range.to_a & challenge_range.to_a].flatten.any? | |
end | |
failure_message_for_should do |current_range| | |
"#{current_range.inspect} doesn't overlap with #{challenge_range.inspect}" | |
end | |
failure_message_for_should_not do |current_range| | |
"#{current_range.inspect} overlaps with #{challenge_range.inspect}" | |
end | |
description do | |
"intersection of an enumerable's elements" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment