Giter Club home page Giter Club logo

ae's Introduction

Assertive Expressive

Website / API / User Guide / Report Issue / Source Code

Gem Version Build Status     Flattr Me

About

Assertive Expressive (AE) is an assertions framework intended for reuse by any TDD, BDD or similar system.

Features

  • Clear, simple and concise syntax.
  • Uses higher-order functions and fluid notation.
  • Reusable core extensions ease assertion construction.
  • Core extensions are standardized around Ruby Facets.
  • But Facets is not a dependency; the extensions are built-in.
  • Easily extensible allowing for alternate notations.
  • Eats it's own dog food.

Synopsis

AE defines the method assert. It's is compatible with the 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 argument or block. In that case it returns an instance of Assertor. An Assertor is an Assertions Functor, or Higher-Order Function. It is a function that operates on another function. With it, we can make assertions like so:

x.assert == y

a.assert.include? e

StandardError.assert.raised? do
  ...
end

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

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

"Daffy Duck".assert.daffy?

When an assertion fails an Assertion exception is raised. Any test framework can catch this exception and process it accordingly. Technically the framework should check to see that the exception object responds affirmatively to the #assertion? method. This way any type of exception can be used as a means of assertion, not just AE's Assertion class.

Please have a look at the QED and API documentation to learn more.

Integration

Generally speaking, AE can be used with any test framework simply by putting require 'ae' in a test helper script. However to fully integrate with a test framework and ensure the test framework recognizes AE assertions (as more than just exceptions) and to ensure assertion counts are correct, a little extra interfacing code may be necessary.

Lucky for you AE has already done the leg work for the most common test frameworks:

require 'ae/adapters/testunit'
require 'ae/adapters/minitest'
require 'ae/adapters/rspec'

(Note that Cucumber does not need an adapter.)

AE also includes a script that will automatically detect the current test framework by checking for the existence of their respective namespace modules.

require 'ae/adapter'

Nomenclature

With AE, defining assertions centers around the #assert method. So assert can be thought of as AE's primary nomenclature. However, variant nomenclatures have been popularized by other test frameworks, in particular should and must. If you prefer one of them terms, AE provides optional libraries that can loaded for utilizing them.

require 'ae/should'
require 'ae/must'

By loading one of these scripts (or both) into your test system (e.g. via a test helper script) you gain access to subjunctive terminology. See the API documentation for the Subjunctive module for details.

Legacy

To ease transition from TestUnit style assertion methods, AE provides a TestUnit legacy module.

require 'ae/legacy'

This provides a module AE::Legacy::Assertions which is included in AE::World and can be mixed into your test environment to provide old-school assertion methods, e.g.

assert_equal(foo, bar, "it failed")

Installation

Gem Installs

Install AE in the usual fashion:

$ gem install ae

Site Installs

Local installation requires Setup.rb.

$ gem install setup

Then download the tarball package from GitHub and do:

$ tar -xvzf ae-1.0.0.tgz
$ cd ae-1.0.0.tgz
$ sudo setup.rb all

Windows users use 'ruby setup.rb all'.

Contributing

If you would like to contribute code to the AE project, for the upstream repository and create a branch for you changes. When your changes are ready for review (and no, they do not have to 100% perfect if you still have some issues you need help working out).

It you need to personally discuss some ideas or issue you try to get up with us via the mailing list or the IRC channel.

Copyrights & License

Copyright (c) 2008 Rubyworks. All rights reserved.

Unless otherwise provided for by the originating author, this program is distributed under the terms of the BSD-2-Clause license. Portions of this program may be copyrighted by others.

See the NOTICE.rdoc file for details.

AE is a Rubyworks project.

ae's People

Contributors

trans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

apotheon sysfce2

ae's Issues

Configurable #assert failure?

Would it be useful to allow #assert to take an Exception argument and raise that instead of the Assertion exception if the assertion fails? Eg.

10.assert(ArgumentError) == 5  #=> raises ArgumentError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.