Fixrb

The main gem of Fixrb

Fix

Write once what a Ruby object must do; test every implementation against it.

Fix is a Ruby testing framework. A specification says what a subject MUST, SHOULD or MAY do, in the words of RFC 2119, and nothing about how it is made. Write it once, then test an Array against it today, your own class tomorrow, a library you depend on, or the next version of any of them, beside the RSpec or minitest suite you already have.

Install
gem install fix
Version
1.0.1, for Ruby 3.3 or later
Source
github.com/fixrb/fix, MIT license
From RSpec
Coming from RSpec: what each idiom becomes, and what is left out
require "fix"

# A stack, whatever it is made of.
Fix :Stack do
  on :push, 1 do
    on :pop do
      it MUST eq 1
    end
  end

  on :pop do
    it SHOULD be_nil
  end

  on :peek do
    it MAY be_nil
  end
end

# A test picks the subject: an Array.
exit(Fix[:Stack].test { [] })
ruby stack.rb
stack.rb:7: Success: expected 1 to eq 1
stack.rb:12: Success: expected nil to be nil
stack.rb:16: Info: NoMethodError: undefined method 'peek' for an instance of Array
One line per expectation, the status of the process for the whole. Under MAY, a method the subject does not have is an info, and the run passes. This output was written by running the file, like every output on the pages of the gems and of the guide.

What makes Fix different

Ruby has always judged an object by what it does: if it walks like a duck and quacks like a duck, it is a duck. Fix writes that judgement down. A specification says what a duck does, and how much each thing matters; any object can then be tested against it.

Pixel art at night: a board reads :Duck, then walk, swim and speak, each with its level. In the pond, a white duck quacks under three checks; a robot in the water up to its waist, arms up, under a check, a warning and an info; a yellow rubber duck under a cross, a check and an info.
Three candidates, one specification: the duck meets all of it; the robot passes, with a warning for the way it swims and an info for the voice it lacks; the rubber duck floats, but does not walk, a MUST not met, and fails.

Other gems

Fix is built from small libraries and extended by small gems. Each does one thing, in a few hundred lines of code at most, so that you can read it before you trust it.

Around Fix

Gems that extend Fix, or bring its specifications to other test frameworks.

  • fix-its

    Adds the word its to specifications: a method of the subject and its expectation on one line.

    Version 1.0

  • matchi-fix

    A matcher of matchi that tests a value against a specification of Fix, from any test framework.

    Version 4.0

  • fix-command

    The fix command: runs each specification file in a process of its own, and tells how many files were met.

    Version 1.0

Libraries

Building blocks that do not depend on Fix: use them on their own, with any test framework, or to build one. Fix 1.0 is built on aw, defi, matchi and spectus.

  • matchi

    Matchers for any test framework, in which the expected value makes the comparison, not the object under test.

    Version 6.0

  • spectus

    Expectations with the requirement levels of RFC 2119, MUST, SHOULD and MAY, that give a result instead of raising. The engine of Fix 1.0, built on defi.

    Version 6.0

  • aw

    Runs a block in a forked process and returns its result. Fix 1.0 uses it to keep contexts apart.

    Version 1.0

  • defi

    Prepares a method call, a name and its arguments, to send to any object and keep what came back.

    Version 4.0

  • test_tube

    Checks a value, or what a block returns or raises, against a matcher. Built on defi; not used by Fix 1.0.

    Version 4.0

  • expresenter

    Presents the result of an expectation: success, warning, info, failure or error. Not used by Fix 1.0.

    Version 1.5

Tools

A command to run as it is, rather than a library to build on.

  • brutal

    Writes plain Ruby test files from a YAML manifest, by recording what the code returns in every combination of contexts. Built on aw.

    Version 2.0

Built with Fixrb

The libraries are not only the engine of Fix: other frameworks can stand on them. Here is one.

From the blog

All posts