Skip to content

feat: chaining the extraction of multiple properties of the same subject#88

Merged
haraldmaida merged 27 commits into
mainfrom
feat/extracting-ref-for-asserting-multiple-fields-of-same-subject
Apr 26, 2026
Merged

feat: chaining the extraction of multiple properties of the same subject#88
haraldmaida merged 27 commits into
mainfrom
feat/extracting-ref-for-asserting-multiple-fields-of-same-subject

Conversation

@haraldmaida
Copy link
Copy Markdown
Member

For asserting custom structs it should be possible to chain the extraction of multiple properties from the same subject for individual assertions.

For example:

use asserting::prelude::*;

struct Person {
    name: String,
   age: u8,
}

let person = Person {
    name: "Silvia".into(),
    age: 25
};

assert_that!(person)
    .extracting_ref("name", |p| &p.name)
    .is_equal_to("Silvia")
    .and()
    .extracting_ref("age", |p| &p.age)
    .is_at_least(18);

As this requires, ,that the type of the extracted property implements ToOwned (or Clone), the new method extracting_ref is added (instead of re-purposing the existing method extracting).

… multiple fields on same subject for assertion
…ields-of-same-subject

# Conflicts:
#	src/prelude.rs
…` - it should be called only once at the root `Spec`
…expecting` as trait `Expecting`

BREAKING-CHANGE: the behavior of the trait method `Expecting::expecting` is exactly the same as the original methods `Spec::expecting` and `DerivedSpec::expecting`. The only change in custom code is that maybe the trait has to be imported in scope. The `Expecting` trait is included in the prelude. If the import `use asserting::prelude::` is used, there is no change needed.
…rom Spec into trait `Satisfies` and implement it for `Spec` and `DerivedSpec`
…ields-of-same-subject

# Conflicts:
#	src/iterator/mod.rs
@haraldmaida haraldmaida self-assigned this Apr 26, 2026
@haraldmaida haraldmaida added the enhancement New feature or request label Apr 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

❌ Patch coverage is 56.80346% with 400 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.95%. Comparing base (18675f5) to head (e77929e).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
src/derived_spec/mod.rs 50.12% 387 Missing and 4 partials ⚠️
src/iterator/mod.rs 87.14% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
- Coverage   92.85%   87.95%   -4.91%     
==========================================
  Files          41       42       +1     
  Lines        5756     6649     +893     
  Branches     5756     6649     +893     
==========================================
+ Hits         5345     5848     +503     
- Misses        345      731     +386     
- Partials       66       70       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haraldmaida haraldmaida merged commit 7b62599 into main Apr 26, 2026
18 of 20 checks passed
@haraldmaida haraldmaida deleted the feat/extracting-ref-for-asserting-multiple-fields-of-same-subject branch April 26, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant