Skip to content

Add assert_hash_attributes extracted from Catberry - #1

Merged
AbuMareBear merged 1 commit into
mainfrom
assert-hash-attributes
Sep 28, 2026
Merged

AbuMareBear merged 1 commit into
mainfrom
assert-hash-attributes

Conversation

@AbuMareBear

Copy link
Copy Markdown
Contributor

Adds assert_hash_attributes(hash, **expected), the hash counterpart to assert_attributes, extracted from Catberry's test helpers.

assert_hash_attributes(
  JSON.parse(response.body),
  "@type": "Person",
  name: "Marceline",
  nickname: nil
)

Changes

  • Shared comparisons. The nil, Time, rich text, and assert_equal branches move into a private assert_value, used by both assertions. assert_attributes failure messages are unchanged.
  • Key lookup. Each key is tried as given, then as a string, so symbol keys match parsed JSON. Catberry's version only looked up string keys.
  • Missing keys fail with Expected hash to have key :nickname, but its keys were [...], even when the expected value is nil. Catberry's version treated a missing key as nil.
  • RBS signatures, a README section, and a CHANGELOG entry.
  • Metrics/ClassLength is excluded for tests, alongside the existing Metrics/AbcSize exclusion.

Testing

bundle exec rake: 27 runs, 0 failures; RuboCop clean. Every branch has a passing case and a failing case that checks the message, plus symbol vs. string keys and missing keys.

Applies the same nil, Time, and rich text comparisons as assert_attributes to hash values. Keys are looked up as given, then as strings, so symbol keys match parsed JSON. A missing key fails, even when the expected value is nil.
@AbuMareBear
AbuMareBear merged commit 3ef42d4 into main Sep 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant