trans edited this page Feb 23, 2011 · 8 revisions
Clone this wiki locally

AE is an assertions framework. It was designed to serve as a reusable domain language for other test frameworks, such as QED and Cucumber. Essentially AE defines the method assert. The method is compatible with the same method as defined by Test::Unit and minitest which verifies truth of a single argument (and can accept an optional failure message).

  assert( true )

In addition AE’s assert method has been extended to accept a block, the result of which is likewise verified.

  assert{ true }

But the real power the AE’s assert method lies in it’s use without an argument or a block. In that case it returns an instance of Assertor. An Assertor is an Assertions Functor, or Higher-Order Function —a function that operates on another function. With it, we easily make assertions with a fluent notation.

  x.assert == y

  a.assert.include? e

  StandardError.assert.raised? do

And so forth. Any method can be used in conjunction with assert to make an assertion.

  class String
    def daffy?
      /daffy/i =~ self

  "Daffy Duck".assert.daffy?

In addition to assert, AE provides the assertion method, expect. It works much like assert but uses #=== to evaluate success. This allows for some useful flexibility in making assertions. For instance, it can be used to test for a matching regular expression.

    expect /t/ do

Even more useful, #expect will catch exceptions when a exception class is provided.

    expect ArgumentError do
      raise ArgumentError

In this example the ArgumentError will be caught, and the assertion successful. While essentially the same as using ArgumentError.assert.raised?, expect is a bit more concise.

Additional Support Libraries

AE also provides some optional support libraries, including subjunctive forms, such as #should, and legacy assertions for backward compatibility with Test::Unit’s assertion methods.

Further Reading

Please have a look at the QED generated Demonstrandum or the RDoc generated API Documentation to learn more.