Skip to content

Instantly share code, notes, and snippets.

@jferris
Created May 13, 2013 19:06
Show Gist options
  • Save jferris/5570635 to your computer and use it in GitHub Desktop.
Save jferris/5570635 to your computer and use it in GitHub Desktop.
Example: custom rspec-mocks argument matcher
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
@gabebw
Copy link

gabebw commented May 13, 2013

Usage:

updater.should_receive(:process).with(array_matching(operations))

@vrinek
Copy link

vrinek commented Jul 3, 2014

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