Happy !

EvanDonahue / Contracts

Project infos

License MIT
Tags
Creation date 2017-05-11
Website

Monticello registration

About Contracts

Contracts allow you to write type signatures for your methods and have them dynamically checked during testing.

Examples:

MyIntegerr >> + aNumber "Use uppercase symbols in the type signature to test that inputs and outputs are instances of the specified class using #isKindOf:"

MyInteger >> squared "Use lowercase symbols in the type signature to test that inputs respond true to the specified selector using #perform:."

MyCollection >> collect: aBlockOrSymbol "Use array literals to represent values that may be any one of several types."

MyCollection >> add: anObject "You may create classes that represent arbitrary contracts by implementing #asContractC on the class side to return an instance, and #satisfiesContractC: on the instance side to return true or false depending on whether the value should trigger a ContractViolation. AnyC is an example of a custom contract that accepts all values."

To activate the contracts on a given class, use MyClass >> enforceContractC. To remove all contracts, use MyClass >> unenforceContractC.

NB: Be sure to unenforceContractC before attempting to edit a class method. Contracts do not play well with Nautilus or Monticello. Recommendation is to use #enforceContractC in TestCase >> setUp and #unenforceContractC in TestCase >> tearDown.