Created
September 6, 2016 18:24
-
-
Save soulcutter/d252c52581ed1ab18a750f4b9079e6e3 to your computer and use it in GitHub Desktop.
RSpec basic flat array uniqueness matcher
This file contains 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
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