declare

A unit testing framework

Usage

Require Ruby 2.6 or later

Add below code into your Gemfile`

group :test do
  gem 'declare', '>= 0.3.1', '< 0.4.0'
end

Overview

Target Code

class Person
  attr_reader :name, :birth

  def initialize(name)
    @name = name
    @birth = Time.now
  end
end

Test Code

require 'declare/autorun'

Declare.describe do
  The Person.new('John') do |john|
    can :name
    can :birth
    is_a Person
    kind_of Object

    NOT 'Taro'

    The john.name do |name|
      kind_of String
      is_a Person
      ok name.kind_of?(String)
      ng name.match(/[1-9]/)
    end

    The john.birth do
      kind_of Time
    end
  end
end

Report

Detail testing report
=====================

### "John" ### [./example/mixed.rb:25]

* ./example/mixed.rb:27
  Expected: it == other
  Actual  : "John" == "Taro"

------------------------------------------------------------------------------
3 scopes, 10 assertions, 1 failures
$ echo $?
1(count of the failures)

How to use in Rake Tasks likely with test-unit

Replace as below.

require 'test/unit'

to

require 'declare/autorun'