Rdbc – Design by Contract for Ruby

This library supports Design by Contract for Ruby.

Installation

Install the rdbc gem itself by the following command:

$ gem install armin-joellenbeck-rdbc --source http://gems.github.com

Usage

Given there is a the class Foo. For instances of this class you can define a contract by subclassing Rdbc::Contract, in the example the contract is named FooContract. Then connect the class Foo to its contract FooContract by using the line

contract FooContract

in the class definition of Foo.

Then the following happens when a method of a Foo instance is called:

  1. the corresponding pre condition is called with the parameters:

    • the instance itself

    • the parameters of the method call

  2. the method is called

  3. the corresponding post condition is called with the parameters:

    • the instance before the method is called

    • the instance after the method is called

    • the return value of the method call

    • the parameters of the method call

  4. the invariant is called with the parameters:

    • the instance before the method is called

    • the instance after the method is called

The instance before the execution of method in 3. and 4. is in fact a copy of the instance before the execution. So you have to implement the method initialize_copy in the class under contract, i.e. the class Foo.

Support

The project home is at GitHub: github.com/armin-joellenbeck/rdbc/tree/master

Feel free to send:

  • bug reports

  • support requests

  • feature requests

  • patches

Copyright

Copyright © 2007 - 2009 by Armin Jöllenbeck <[email protected]>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.