-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
custom error messages #35
Comments
Hi Ben - thanks for your suggestion :) My brief thoughts on your idea are that Shouldly's intention is to provide more helpful error messages out of the box so that you don't (necessarily) have to. By grabbing the source-line when we print the error message, we're intending that the code is clear enough such that the reason for the failure is obvious. In your particular case, i'm not sure that the user-provided message is giving any more information about the reason for the failure than you could ascertain from Shouldly's failure message alone. e.g.
which is as much information as "text not found on page body". If you wanted more detail about the text, you could (say) rename the So there's that option, or another possibility is that your example has shown a deficiency in Shouldly's ability to cater for custom text matching. Out of curiosity, what does your |
Ops, I didn't noticed that the failing line will be included in the error message. Of course, I agree with the philosophy of no string messages needed.
(just a thought, it sounds hard, but if it's possible I can help with it on a fork) about the ContainsText() method, I'm no sure (it's in a third-party lib), but I think it searches thru a page DOM tree for text that is visible to user. Also I couldn't use ShouldContain because it prints the whole page text, which is too long. I think I can close this issue now, |
Hi Ben - you closed the issue, but I cant help but feel I wasn't able to fully solve your problems with Shouldly.. Are you satisfied with the limitation of actual output of 100 chars and would that solve the problems you're experiencing? -xerx |
Hi, yes, absolutely!
Thanks for you concern xerxes. |
I'm still missing additional assertion error message and keeps me from using shouldly in some scenarios. Mostly in situations where it isn't clear why the assertion is there in the first place. So actually it is more a reason why the assertion is there. I think a syntax like this would be useful.
|
First of all I think that syntax is not possible, as the ShouldBe() method will throw an Exception before the Because() method is even called. // check for an ObsoleteAttribute using reflection (is it possible or using a lambda is required?)
detailResult.Papers[0].General.ShouldBeObsolete();
// if you also want to be sure that obsolete properties are never assigned, this could check that property value === default(T)
detailResult.Papers[0].General.ShouldBeObsolete().AndUnassigned(); You can write another issue requesting for that (and possibly submit a pull request with it). |
It would be nice if we can provide custom messages to assertions, eg:
or:
(in the example ContainsText is an implementation that cannot be replaced by ShouldContain() )
The text was updated successfully, but these errors were encountered: