Module: Matchi

Defined in:
lib/matchi.rb,
lib/matchi/be.rb,
lib/matchi/eq.rb,
lib/matchi/match.rb,
lib/matchi/change.rb,
lib/matchi/satisfy.rb,
lib/matchi/be_within.rb,
lib/matchi/change/by.rb,
lib/matchi/change/to.rb,
lib/matchi/predicate.rb,
lib/matchi/change/from.rb,
lib/matchi/be_a_kind_of.rb,
lib/matchi/change/from/to.rb,
lib/matchi/raise_exception.rb,
lib/matchi/be_an_instance_of.rb,
lib/matchi/change/by_at_most.rb,
lib/matchi/change/by_at_least.rb

Overview

Main namespace for the Matchi gem, providing a collection of expectation matchers.

Matchi is a framework-agnostic Ruby library that offers a comprehensive set of matchers for testing and verification purposes. Each matcher follows a consistent interface pattern, making them easy to use and extend.

Each matcher in the Matchi ecosystem implements a consistent interface:

  • An initializer that sets up the expected values or conditions

  • A #match? method that takes a block and returns a boolean

  • An optional #to_s method that provides a human-readable description

Examples:

Basic usage with equality matcher

Matchi::Eq.new("hello").match? { "hello" }     # => true
Matchi::Eq.new("hello").match? { "world" }     # => false

Type checking with inheritance awareness

Matchi::BeAKindOf.new(Numeric).match? { 42 }   # => true
Matchi::BeAKindOf.new(String).match? { 42 }    # => false

Verifying state changes

array = []
Matchi::Change.new(array, :length).by(2).match? { array.push(1, 2) }  # => true

Pattern matching with regular expressions

Matchi::Match.new(/^test/).match? { "test_string" }  # => true

Creating a custom matcher

module Matchi
  class BePositive
    def match?
      raise ArgumentError, "a block must be provided" unless block_given?
      yield.positive?
    end

    def to_s
      "be positive"
    end
  end
end

See Also:

Defined Under Namespace

Classes: Be, BeAKindOf, BeAnInstanceOf, BeWithin, Change, Eq, Match, Predicate, RaiseException, Satisfy