The Three Levels of Requirements Inspired by RFC 2119
How Fix implements the MUST, SHOULD and MAY requirement levels for more precise specifications, and how this compares with RSpec’s historical evolution.
The main gem of Fixrb
Specifications for Ruby, in the words of RFC 2119, tested against any subject.
A specification says what a subject MUST, SHOULD or MAY do, 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.
gem install fixrequire "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
It is read once, when the file is loaded: no setup, no mock, no logic, and anything wrong in it raises before a test runs. It names no class; the test picks the subject.
MUST, SHOULD and MAY tell what is required, what is recommended and what is optional. A SHOULD not met is a warning, a MAY on a method the subject lacks is an info, and both pass.
Each context runs in a child process. What a subject does to a global, a constant or ENV stays in its context, and the order of the contexts cannot change a result.
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.
Gems that extend Fix, or bring its specifications to other test frameworks.
Adds the word its to specifications: a method of the subject and its expectation on one line.
Version 1.0
A matcher of matchi that tests a value against a specification of Fix, from any test framework.
Version 4.0
The fix command, to run specification files.
Moving to Fix 1.0
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 spectus, matchi and aw.
Matchers for any test framework, in which the expected value makes the comparison, not the object under test.
Version 6.0
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
Runs a block in a forked process and returns its result. Fix 1.0 uses it to keep contexts apart.
Version 1.0
Prepares a method call, a name and its arguments, to send to any object and keep what came back.
Version 4.0
Checks a value, or what a block returns or raises, against a matcher. Built on defi.
Version 4.0
Presents the result of an expectation: success, warning, info, failure or error.
Version 1.5
A command to run as it is, rather than a library to build on.
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
How Fix implements the MUST, SHOULD and MAY requirement levels for more precise specifications, and how this compares with RSpec’s historical evolution.
How Fix’s approach to testing in Ruby keeps specifications apart from their implementations, for a test suite that is easier to maintain and to reuse.
Explore why the distinction between expected and actual values is crucial in test design, and how it impacts the robustness and reliability of your test suite.