Rdbc – Design by Contract for Ruby

This library supports Design by Contract for Ruby.

Installation

Install the rdbc gem by the following command:

$ gem install rdbc

Usage

Given there is a the class Foo.

For instances of this class you can define a contract by subclassing:

FooContract < Rdbc::Contract.

Then connect the class Foo to its contract FooContract by using

class Foo
  contract FooContract
  ...
end

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

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

    • the instance itself

    • the parameters of the method call

  2. the original method bar itself is called

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

    • the instance before the original method is called

    • the instance after the original method is called

    • the return value of the method call respectively a raised exception

    • the parameters of the method call

  4. the mathod invariant is called with the parameters:

    • the instance before the original method is called

    • the instance after the original method is called

The instance before the execution of the original 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 - 2013 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.