Skip to content

Instantly share code, notes, and snippets.

@briandoll
Created September 30, 2009 05:16
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 briandoll/197818 to your computer and use it in GitHub Desktop.
Save briandoll/197818 to your computer and use it in GitHub Desktop.
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
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
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