Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RSpec basic flat array uniqueness matcher
RSpec::Matchers.define :be_uniq do
match do |actual|
values_match? actual.uniq, actual
end
failure_message do |actual|
diff = actual.dup
actual.uniq.each { |value| diff.delete_at diff.index(value) }
diff = diff.uniq
"expected that #{actual.inspect} to be uniq, but found the following repeated elements: #{diff.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.