Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created September 6, 2016 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulcutter/d252c52581ed1ab18a750f4b9079e6e3 to your computer and use it in GitHub Desktop.
Save soulcutter/d252c52581ed1ab18a750f4b9079e6e3 to your computer and use it in GitHub Desktop.
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