Created
May 13, 2013 19:06
-
-
Save jferris/5570635 to your computer and use it in GitHub Desktop.
Example: custom rspec-mocks argument matcher
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
module ArrayMatching | |
class ArrayMatching | |
def initialize(array) | |
@array = array | |
end | |
def ==(other_array) | |
Set.new(@array) == Set.new(other_array) | |
end | |
def inspect | |
"an array with elements #{@array.inspect}" | |
end | |
end | |
# Matches arguments that contain the same elements as the given Array | |
def array_matching(elements) | |
ArrayMatching.new(elements) | |
end | |
end | |
RSpec.configure do |config| | |
config.include ArrayMatching | |
end |
I can no find any RSpec documentation about achieving the above example. Is there a link with more info you could provide?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: