Skip to content

Instantly share code, notes, and snippets.

@henrikj242
Created September 6, 2018 10:49
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 henrikj242/86567768083f067baf6fee8e1d418831 to your computer and use it in GitHub Desktop.
Save henrikj242/86567768083f067baf6fee8e1d418831 to your computer and use it in GitHub Desktop.
Rspec custom matcher example
# Save this file in spec/support/matchers
RSpec::Matchers.define :be_an_array_of do |expected|
match do |actual|
actual.is_a?(Array) && actual.map(&:class) == expected
end
end
# usage:
# expect([Subscriber.new(email: 'test@example.com'), []]).to be_an_array_of([Subscriber, Array])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment