Git Product home page Git Product logo

moguro's Introduction

Moguro Gem Version Build Status Code Climate Coverage Status

Decorator style assertions and type check library for Contract programming

This gem is still in development and it isnt available to production.

Installation

Add this line to your application's Gemfile:

gem 'moguro'

And then execute:

$ bundle

Or install it yourself as:

$ gem install moguro

Usage

require 'moguro'

class MockClass
  include Moguro::Decorator
  
  # Must match argument names of decorate method
  pre_c ->(a: Integer, b: String) {
    assert_equal(a, 1)
    assert_equal(b, 'b')
  }
 
  def puts_method(a, b)
    puts b
    a + 1
  end
  
  # Return values are auto assigned in order
  post_c -> (first: String) {
    p first
  }
  def post_contract_violation_method
    1
  end
  
end

c = MockClass.new
c.puts_method(1, 'b')
# 1
# => 2

begin 
  c.puts_method('a', 1)
rescue => e
  p e
end
# =>
# Type MissMatch: a is expected (Integer) actual a(String) (Moguro::Errors::ArgumentsTypeMismatchError)
# Expected: [a: (Integer), b: (String)]
# Actual: [a: a(String), b: 1(Integer)]
# Value guarded in: MockClass::puts_method
# At: #{source_location}

begin
  c.post_contract_violation_method
rescue => e
  p e
end

# =>
# Type MissMatch: first is expected (String) actual 1(Integer)
#  Expected: [first: (String)]
#  Actual: [first: 1(Integer)]
#  Value guarded in: MockClass::post_contract_violation_method
#  At: #{source_location}

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Moguro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

moguro's People

Contributors

rike422 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.