Created
September 6, 2018 10:49
-
-
Save henrikj242/86567768083f067baf6fee8e1d418831 to your computer and use it in GitHub Desktop.
Rspec custom matcher example
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
# 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