Expects

A DSL for validating input for methods

Coverage Status Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'expects'

And then execute:

$ bundle

Or install it yourself as:

$ gem install expects

Usage

Include Expects in your class and then call it in your methods eg:

class YourClass
  include Expects

  def initialize(name)
    expects name, String
  end
end

You can pass an array instead of one class to accept multiple types e.g.

expects number, [Fixnum, Float]

If you try to pass anything other than a string to YourClass.new expects will raise an exception which you can catch like so:

begin
  YourClass.new(1234)
rescue UnexpectedInput => e
  e.message # Expected 1234 to be String
  e.subject # 1234
  e.expected # [String]
end

All exceptions thrown by expects are instances of UnexpectedInput

Contributing

  1. Fork it
  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 new Pull Request