Created
November 22, 2012 01:05
-
-
Save willnet/4128828 to your computer and use it in GitHub Desktop.
attributes custom matcher for minitest
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
# -*- coding: utf-8 -*- | |
class EqualAttributesMatcher | |
def initialize(attrs) | |
@attrs = attrs | |
end | |
def matches?(model) | |
@model = model | |
@attrs.all? { |k,v| @model.send(k) == v } | |
end | |
def failure_message_for_should | |
left_diff = @attrs.reject {|k,v| @model.send(k) == v} | |
right_diff = left_diff.each_with_object({}) {|(k,_), hash| hash[k] = @model[k] } | |
"expected #{@attrs} but diff -#{left_diff} +#{right_diff}}" | |
end | |
def failure_message_for_should_not | |
"expected not equal #{@attrs} but equal" | |
end | |
end | |
MiniTest::Unit::TestCase.register_matcher EqualAttributesMatcher, :have_equal_attributes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment