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

EnumAssertions.Be() doesn't identify the subject (but its NotBe() counterpart does) #1832

Closed
jasonsparc opened this issue Mar 6, 2022 · 5 comments · Fixed by #1835
Closed

Comments

@jasonsparc
Copy link

I decided to look at the source code after finding out that my enum assertions weren't identifying the subject name when using Be(), and yet it is identified correctly when using NotBe().

Apparently, in EnumAssertions.Be() (see line 60), {context:the enum} was not being used:

public AndConstraint<TAssertions> Be(TEnum expected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(expected) == true)
.BecauseOf(because, becauseArgs)
.FailWith("Expected the enum to be {0}{reason}, but found {1}.",
expected, Subject);
return new AndConstraint<TAssertions>((TAssertions)this);
}

This doesn't match the counterpart NotBe() (see line 105):

public AndConstraint<TAssertions> NotBe(TEnum unexpected, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(unexpected) != true)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:the enum} not to be {0}{reason}, but it is.", unexpected);
return new AndConstraint<TAssertions>((TAssertions)this);
}

The above are permalinks but the issue currently exists in both the develop and master branches.

@jasonsparc
Copy link
Author

jasonsparc commented Mar 6, 2022

Also, I think the failure message for NotBe() would be better if instead of "Expected the enum not to be …", it was rather "Expected the enum to not be …" – I'm not a native English speaker btw, so it could be just me that I find the wording weird, but it might be a typo, so I'm reporting it also just in case.

Actual current output in my tests:

Expected state not to be DisposeState.DisposedFully {value: 7} because `HandleDisposeRequest() == false`, but it is.

@jnyrup jnyrup added the bug label Mar 6, 2022
@dennisdoomen
Copy link
Member

Also, I think the failure message for NotBe() would be better if instead of "Expected the enum not to be …", it was rather "Expected the enum to not be …"

You're right. That's better.

@jnyrup
Copy link
Member

jnyrup commented Mar 6, 2022

We have a "not to be" or "to not be" discussion somewhere, but I can't find it right now.

Just for the record, we're using "not to be" most places.

  • not to be: 77 occurrences
  • to not be: 19 occurrences

@dennisdoomen
Copy link
Member

#1340

We should change that thing into a page on www.fluentassertions.com

@jnyrup
Copy link
Member

jnyrup commented Mar 6, 2022

Found it, I was looking for #713 and #620.

@jnyrup jnyrup linked a pull request Mar 6, 2022 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants