=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 A a standard example for Design by Contract consider the following Stack class and its contract StackContract. :include:spec/stack_spec.rb The mechanics are really simple. There is the class Stack. For instances of this class you can define a contract by subclassing DesignByContract::Contract, in the example the contract is named StackContract. Then connect the class Stack to its contract StackContract by using the line contract StackContract in the class definition of Stack. Then the following happens when a method of a Stack 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 Stack. In any of these contract methods you can use assertions as in Test::Unit tests. When an assertion fails, the exception Test::Unit::AssertionFailedError is raised. =Support The project home is at GitHub[http://github.com/armin-joellenbeck/rdbc/tree/master]: http://github.com/armin-joellenbeck/rdbc/tree/master Feel free to send: * bug reports * support requests * feature requests * patches =Copyright Copyright (c) 2007 - 2009 by Armin Jöllenbeck 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.