Fixrb

The main gem of Fixrb

Fix

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

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

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

From the blog

All posts