Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor fluent API & source printing for better readability #22

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

arikkfir
Copy link
Owner

This change refactors the fluent API of the package to make the test source code flow better in terms of readability. For example, instead of:

With(t).Verify(1).Will(EqualTo(2)).OrFail()

The API is now either:

With(t).EnsureThat("1 equals 2").ByVerifying(1).Will(EqualTo(2)).Now()
With(t).VerifyThat(1).Will(EqualTo(2)).Now()

The call to "EnsureThat" is optional and is meant to help documenting the test in case of failures. The change from ".OrFail()" to ".Now()" ensures that every assertion ends with a timing specification:

With(t).VerifyThat(1).Will(EqualTo(2)).Now()
With(t).VerifyThat(1).Will(EqualTo(2)).For(...)
With(t).VerifyThat(1).Will(EqualTo(2))Within(...)

Additionally, this refactor improves the printing of the assertion's source code location, enabling support for multi-line location source code. For instance, for the following assertion:

With(t).
    EnsureThat("...").
    ByVerifying(1).
    Will(EqualTo(2)).
    Now()

Previous versions only printed the line containing the "Now()" call, but this version will print the entire statement (from the "With(t)" up to and including the call to "Now()".)

@arikkfir arikkfir added feature New features and functionality refactor Structural changes without functional changes labels Jun 23, 2024
@arikkfir arikkfir self-assigned this Jun 23, 2024
@arikkfir arikkfir enabled auto-merge (squash) June 23, 2024 13:07
This change refactors the fluent API of the package to make the test
source code flow better in terms of readability. For example, instead
of:

    With(t).Verify(1).Will(EqualTo(2)).OrFail()

The API is now either:

    With(t).EnsureThat("1 equals 2").ByVerifying(1).Will(EqualTo(2)).Now()
    With(t).VerifyThat(1).Will(EqualTo(2)).Now()

The call to "EnsureThat" is optional and is meant to help documenting
the test in case of failures. The change from ".OrFail()" to ".Now()"
ensures that every assertion ends with a timing specification:

- With(t).... .Now()
- With(t).... .For(...)
- With(t).... .Within(...)

Additionally, this refactor improves the printing of the assertion's
source code location, enabling support for multi-line location source
code. For instance, for the following assertion:

    With(t).
        EnsureThat("...").
        ByVerifying(1).
        Will(EqualTo(2)).
        Now()

previous versions only printed the line containing the "Now()" call, but
this version will print the entire statement (from the "With(t)" up to
and including the call to "Now()".)
@arikkfir arikkfir force-pushed the refactor/better-fluent-api-and-location-printout branch from 660ec9d to 4c532fb Compare June 23, 2024 13:24
@arikkfir arikkfir merged commit 0936ebf into main Jun 23, 2024
4 checks passed
@arikkfir arikkfir deleted the refactor/better-fluent-api-and-location-printout branch June 23, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New features and functionality refactor Structural changes without functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant