Project

fix-its

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Fix::Its adds the word its to the language of Fix: a method of the subject and one expectation about what it returns, on one line. its(:size) { MUST eq 3 } is on(:size) { it MUST eq 3 }, and the result points at the line of its.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.0
 Project Readme

Fix::Its

Version Yard documentation License

Fix::Its adds the word its to the language of Fix: a method of the subject and one expectation about what it returns, on one line. its(:size) { MUST eq 3 } is on(:size) { it MUST eq 3 }, and the result points at the line of its.

fixrb.dev presents the gem, and the guide of Fix shows the word in The word its.

Installation

# Gemfile
gem "fix-its"

Fix::Its requires Ruby 3.3 or later on a system with fork, and depends on Fix.

Usage

# word_fix.rb
require "fix/its"

Fix :Word do
  its(:size) { MUST eq 5 }
  its(:upcase) { MUST eq "HELLO" }
  its(:start_with?, "he") { MUST be_true }

  on :chars do
    its(:first) { MUST eq "h" }
  end
end

exit(Fix[:Word].test { "hello" })
word_fix.rb:5: Success: expected 5 to eq 5
word_fix.rb:6: Success: expected "HELLO" to eq "HELLO"
word_fix.rb:7: Success: expected true to be true
word_fix.rb:10: Success: expected "h" to eq "h"

its takes the name of the method and its arguments, as on does, and a block that gives the requirement: a level and a matcher, MUST eq 5. Inside an on or a with, its sends its method to the value of that context. Since its is a word of the language, a let cannot be named so.

The block is the context of the on, read once with the rest of the document: what else it does there is read as in an on, and its last expression is the requirement. A block that gives anything else, a bare matcher or an it of its own, raises ArgumentError at load, as does a missing block.

In Ruby 3.4 and later, a bare it in a block is the parameter of the block: its(:size) { MUST eq it } builds eq nil. On Ruby 3.3 that bare it is the word of Fix, which raises ArgumentError for want of a requirement. Write the value.

its takes no location:, which could not be told from a keyword argument of the method: a word that composes its in turn has its results pointing at its own call of its.

Versioning

Fix::Its follows Semantic Versioning 2.0.

License

The gem is available as open source under the terms of the MIT License.

Sponsors

This project is sponsored by Sashité