All Projects → Groogy → crystal-clear

Groogy / crystal-clear

Licence: Zlib license
Design by Contract for Crystal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to crystal-clear

karate
Test Automation Made Simple
Stars: ✭ 6,384 (+14086.67%)
Mutual labels:  assertions, contract-testing
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+12115.56%)
Mutual labels:  assertions, contract-testing
notary
A contracts broker that provides a declarative way of sharing, validating & discovering contracts between multiple projects.
Stars: ✭ 16 (-64.44%)
Mutual labels:  contracts, contract-testing
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-60%)
Mutual labels:  assertions
ethereum-erc20
Fungible token implementation for the Ethereum blockchain.
Stars: ✭ 27 (-40%)
Mutual labels:  contracts
apid
User focused API testing
Stars: ✭ 90 (+100%)
Mutual labels:  assertions
picolisp-unit
Unit Testing framework for PicoLisp
Stars: ✭ 22 (-51.11%)
Mutual labels:  assertions
portman
Port OpenAPI Specs to Postman Collections, inject test suite and run via Newman 👨🏽‍🚀
Stars: ✭ 530 (+1077.78%)
Mutual labels:  contract-testing
awesome-smart-contracts
Awesome Ethereum Projects List
Stars: ✭ 35 (-22.22%)
Mutual labels:  contracts
jasmine2-custom-message
custom failure message on any jasmine v2 assertion
Stars: ✭ 27 (-40%)
Mutual labels:  assertions
vim-UT
Unit Testing plugin for Vim
Stars: ✭ 18 (-60%)
Mutual labels:  assertions
ethereum-crowdsale
0xcert protocol crowdsale contracts for Ethereum blockchain.
Stars: ✭ 15 (-66.67%)
Mutual labels:  contracts
GETProtocolCore
🎫 Contract overview and definition of GET Protocol's NFTs
Stars: ✭ 31 (-31.11%)
Mutual labels:  contracts
jasmine-custom-message
custom failure message on any jasmine v1.3 assertion
Stars: ✭ 15 (-66.67%)
Mutual labels:  assertions
jsonassert
A Go test assertion library for verifying that two representations of JSON are semantically equal
Stars: ✭ 102 (+126.67%)
Mutual labels:  assertions
pact-consumer-swift
A Swift / ObjeciveC DSL for creating pacts.
Stars: ✭ 89 (+97.78%)
Mutual labels:  contract-testing
ContractTestingBoilerplate
Contract Testing Boilerplate for the microservices developed using Spring Boot and Kafka in a maven multi-module project.
Stars: ✭ 36 (-20%)
Mutual labels:  contract-testing
assert.sh
❗ Assertion lib for shell script users
Stars: ✭ 105 (+133.33%)
Mutual labels:  assertions
fluentcheck
Fluent assertions for Python
Stars: ✭ 79 (+75.56%)
Mutual labels:  assertions
concise
✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
Stars: ✭ 47 (+4.44%)
Mutual labels:  assertions

crystal-clear

Crystal Clear is a small little library with minimal overhead for you who is bad at maintaining the specs for your project. It does this by moving that into be more inline on the project and keep the specs source local. It implements the Design by Contract approach which let's you define what the behaviour for a method, even a whole class, is supposed to be. Most of the code is generated at compile time and you can opt out performance intensive code from the tests. The entire contract framework can be disabled using the -D DISABLE_CONTRACTS flag when compiling.

Installation

Add this to your application's shard.yml:

dependencies:
  crystal-clear:
    github: Groogy/crystal-clear

Usage

To include Crystal clear you just have to write this to get started.

require "crystal-clear"

Everything else happens magically with metaprogramming in the library. All you now need to do is provide the contracts that will specify how the class and its methods are supposed to behave. The tools you need to keep in mind are requires, ensures, invariants. These macros are where the magic happens.

  • requires(condition) describes something a method expects to be true before calling it, usually used with incoming arguments. It is the expection of the contract when using that method.
  • ensures(condition) is the expectation you can put on the method, what it ensures to be true when the method returns (no matter from what branch in the method returns from). The return value of the method is available in the variable return_value.
  • invariants(condition) define something that must always be true and is done on a class level, it is a contract promising when entering or leaving its methods that something will be true.
require "crystal-clear"

class FooBar
  include CrystalClear

  invariant @val != nil

  def initialize(@val)
  end

  requires val > 0
  ensures return_value > 0
  def test_method(val)
    100 // val + 1
  end

  requires val > 0
  ensures return_value > 0
  def bad_method(val)
    @val = nil # Will throw an exception because this is not okay!
    100 // val + 1
  end

  def break_internally
    @val = nil # Will throw an exception because this is not okay! 
  end

  def fixes_internally
    break_internally 
    @val = 5 # Invariants are only run when you leave the object completly so this is fine
  end
end

Future Features

I've added some future proofing structure so that I can add more cool features but it needs a lot more work from me. Though as I add features it should not break the interface you work towards so it is still safe to use without risk of breakage.

  • Better integration with the built in spec command in Crystal. Add expects_contract_pass macros and other similar ones to let you hook in to the already built in tests for your spec.
  • Better configuration, should be able to set yourself from your own code if the contracts should be enabled or not at compile time, or even runtime.
  • Add more hooks that proves wanted in the generated Contracts module in the contracted classes.

Contributing

If you have ideas on how to develop this library more or what features it is missing, I would love to hear about it. You can always contact me on IRC #crystal-lang at freenode.

  1. Fork it ( https://github.com/Groogy/crystal-clear/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • Groogy - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].