Closed sirwolfgang closed 1 year ago
This seems to work fine; Just weird to me that this has never come up before?
module RSpec
module Mocks
module ArgumentMatchers
def array_excluding(*args)
actually_an_array = Array === args.first && args.count == 1 ? args.first : args
ArrayExcludingMatcher.new(actually_an_array)
end
# @private
class ArrayExcludingMatcher
def initialize(expected)
@expected = expected
end
def ===(actual)
actual = actual.uniq
@expected.uniq.none? do |expected_element|
actual.any? do |actual_element|
RSpec::Support::FuzzyMatcher.values_match?(expected_element, actual_element)
end
end
rescue NoMethodError
false
end
def description
"array_excluding(#{formatted_expected_values})"
end
private
def formatted_expected_values
@expected.map do |x|
RSpec::Support.rspec_description_for_object(x)
end.join(", ")
end
end
end
end
end
Closing to continue discussion in #1528
Is there any technical reason there is not an
array_excluding
argument matcher? There's hash excluding right below it.https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/argument_matchers.rb#L74-L93