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

Assertions assertInitial, assertNotInitial #26

Open
andre2007 opened this issue Sep 10, 2019 · 3 comments
Open

Assertions assertInitial, assertNotInitial #26

andre2007 opened this issue Sep 10, 2019 · 3 comments

Comments

@andre2007
Copy link

I would like to test whether a struct is initial or not.

As workaround assertTrue, assertSame could be used but two new assertions assertInitial and assertNotInitial would be more expressive.

@linkrope
Copy link
Owner

Just out of curiosity: what's the use case for such assertions?

To express the intent, an alias could help. Also, the error message could be improved that way:

alias assertInitial = actual => assertEqual(actual, typeof(actual).init, "not inital");

@andre2007
Copy link
Author

In my test I want to check whether the http service call was triggered. The http client is mocked for the test and while it is triggered a delegate is called. In the delegate I stored the Request structure and with assertInitial I want to check whether it was filled:

@Test void createBinding()
{
    Request request;

    requests.setNoContentResponse(HttpMethod.post, "/apps/myapp/bindings", (r) {
        request = r;
    });

    cut.execute(["myapp", "--binding", "b1"]);
    assertFalse(request == Request.init);
}

@linkrope
Copy link
Owner

OK: this is a problem related to mocking.
With hand-made mocks, there are several approaches:

  • bool called;
  • int callCount;
  • Request request;
  • Request[] requests; (where you replace request = r; with request ~= r;)

I don't like the idea of supporting "approach 3" with a rather special assertion.
So, I would suggest that you try the alias proposal.

BTW: we abandoned hand-made mocks in favour of a mocking framework:
https://github.com/funkwerk/dmocks.

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

No branches or pull requests

2 participants