← Graph

How to assert on collection properties in Test Bench?

question 2 connections

Audience member describes a case where they want to assert that an array contains a hash with a specific key, rather than assert on the whole output, and asks how to do this with Test Bench's minimal API — citing RSpec composable matchers as useful in this case. Ladd notes that emitting large primitive data structures from an object is usually a Tell-Don't-Ask smell (unless the object is a query object). In Eventide's current work with third-party APIs that return massive XML/JSON, they build specialized fixtures: 'assert the Nth element', 'enter the last element and assert on it', a nokogiri-backed fixture that uses CSS selectors for XML assertions, and fixtures that verify individual JSON attributes. The direction is more and more such fixtures. Bellware adds that since every fixture is just a class with a `call` method and two inputs, writing an `assert_equal`-style or any other specialized matcher is simply writing a small class — no matcher API, no `should`/`expect` ceremony.

answer_summary
Build a specialized fixture per verification shape (CSS-selector XML, JSON attribute, 'Nth element', etc.). Because a fixture is just a class with a call method, there's no matcher-API ceremony — you get exactly the verification tool you need rather than a general-purpose matcher DSL.
question How to assert on collection properties in Test Bench?
about
Answer: build specialized fixtures (CSS-selector XML, JSON attribute, Nth-element) rather than general-purpose matchers.
question How to assert on collection properties in Test Bench?
asked_at
Audience Q&A on replacing RSpec composable matchers for collection properties.

Provenance