Sha256: 92838300a41bdb43c2b949c9647e8a365979b20c84ffd3b569c0315fa2f62da1
Contents?: true
Size: 1008 Bytes
Versions: 3
Compression:
Stored size: 1008 Bytes
Contents
module SimpleAssertions # Adds attribute matcher to +assert_raises+. # # == Example # # # old behaviour # assert_raises(StandardError) { ... } # # # exact match on attribute message # assert_raises(RuntimeError, :message => "yay!") do # raise "yay!" # end # # # pattern match on attributes # assert_raises(MyError, :message => /foo/, :code => 23) do # raise MyError, "foo bar", 23 # end module AssertRaises def assert_raises(*args, &block) attributes = args.last.is_a?(Hash) ? args.pop : {} super(*args, &block).tap do |exception| attributes.each do |attribute, expected| assert_respond_to exception, attribute actual = exception.public_send(attribute) msg = proc { "Expected #{mu_pp(expected)} to match #{mu_pp(actual)} for #{attribute} on #{mu_pp(exception)}" } matched = expected == actual || expected === actual assert matched, msg end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems