Created
September 30, 2009 05:16
-
-
Save briandoll/197818 to your computer and use it in GitHub Desktop.
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
class Test::Unit::TestCase | |
def assert_each(assertions) | |
error_messages = "" | |
assertions.each do |assertion, message, *variables| | |
template = message.nil? ? "<?> is not true." : message | |
if variables.empty? | |
msg = build_message(nil, template, assertion) | |
else | |
msg = build_message(nil, template, *variables) | |
end | |
if err = safe_assert_block(msg){ assertion } | |
error_messages << err.to_s << "\n" | |
end | |
end | |
raise Test::Unit::AssertionFailedError.new(error_messages) if !error_messages.blank? | |
end | |
def safe_assert_block(message="assert_block failed.") | |
_wrap_assertion do | |
if (! yield) | |
message | |
end | |
end | |
end | |
end |
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
class SomeTest | |
context "Foo" do | |
should "be foo like" do | |
assert_each([['bar'.eql?('foo')], | |
['foo'.eql?('bar'), "foo should be foo but was <?>", 'bar'], | |
['blah'.eql?('foo'), "foo and <?>", 'yes'], | |
['bar'.eql?('baz'), "<?> and <?>", 'bar', 'baz']]) | |
end | |
end | |
end |
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
1) Failure: | |
test: Foo should be foo like. (SomeTest) | |
... | |
<false> is not true. | |
foo should be foo but was <"bar"> | |
foo and <"yes"> | |
<"bar"> and <"baz"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment