Module: Rubyzen::Matchers

Defined in:
lib/rubyzen/matchers/zen_empty_matcher.rb,
lib/rubyzen/matchers/zen_true_matcher.rb,
lib/rubyzen/matchers/zen_false_matcher.rb

Overview

Custom RSpec matchers for asserting on Rubyzen collections.

Instance Method Summary collapse

Instance Method Details

#zen_empty(custom_message = nil, allowlist: nil, baseline: nil) ⇒ Object

Asserts that a Rubyzen collection is empty.

Used in architectural lint rules to verify that no items match a forbidden pattern (e.g., no controllers call .where directly).

Examples:

Ensure no controllers use .where

expect(controllers.all_methods.call_sites.with_name('where')).to zen_empty

With baseline for gradual adoption

expect(violations).to zen_empty(baseline: ['LegacyController'])

Parameters:

  • custom_message (String, nil) (defaults to: nil)

    optional failure message

  • allowlist (Array<String>, nil) (defaults to: nil)

    items to permanently ignore

  • baseline (Array<String>, nil) (defaults to: nil)

    known violations for gradual adoption



18
# File 'lib/rubyzen/matchers/zen_empty_matcher.rb', line 18

def zen_empty(custom_message = nil, allowlist: nil, baseline: nil); end

#zen_false(custom_message = nil, allowlist: nil, baseline: nil) {|item| ... } ⇒ Object

Asserts that a block returns false for every item in a collection.

Supports allowlist: and baseline: for gradual adoption, matching items where the block returns true against exception lists.

Examples:

Ensure no methods have more than 5 parameters

expect(methods).to zen_false { |m| m.parameters.size > 5 }

With a baseline for gradual adoption

expect(classes).to zen_false(baseline: ['LegacyModel']) { |k| k.lines_of_code > 200 }

Parameters:

  • custom_message (String, nil) (defaults to: nil)

    optional failure message

  • allowlist (Array<String>, nil) (defaults to: nil)

    items to permanently ignore

  • baseline (Array<String>, nil) (defaults to: nil)

    known violations for gradual adoption

Yields:

  • (item)

    block that should return false for each item



18
# File 'lib/rubyzen/matchers/zen_false_matcher.rb', line 18

def zen_false(custom_message = nil, allowlist: nil, baseline: nil, &block); end

#zen_true(custom_message = nil, allowlist: nil, baseline: nil) {|item| ... } ⇒ Object

Asserts that a block returns true for every item in a collection.

Examples:

Ensure all methods have parameters

expect(methods).to zen_true { |m| m.parameters? }

With a custom failure message

expect(services).to zen_true("All services must inherit from BaseService") { |s| s.superclass_name == 'BaseService' }

Parameters:

  • custom_message (String, nil) (defaults to: nil)

    optional failure message

  • allowlist (Array<String>, nil) (defaults to: nil)

    items to permanently ignore

  • baseline (Array<String>, nil) (defaults to: nil)

    known violations for gradual adoption

Yields:

  • (item)

    block that should return true for each item



15
# File 'lib/rubyzen/matchers/zen_true_matcher.rb', line 15

def zen_true(custom_message = nil, allowlist: nil, baseline: nil, &block); end