throwWithRegexMessage
See original GitHub issueI find myself using regex to match dynamic errors, could this be added?
let throwWithRegexMessage (m:string) (t:System.Type) = CustomMatcher<obj>(sprintf "%s \"%s\"" (string t) m,
fun f -> match f with
| :? (unit -> unit) as testFunc ->
try
testFunc()
false
with
| ex -> ex.GetType() = t && Regex.IsMatch (ex.Message, m)
| _ -> false )
(fun () -> AsyncWrite2 (streamName) (int64(EventStore.ClientAPI.ExpectedVersion.Any)) (event)
|> Async.RunSynchronously
|> ignore)
|> should (throwWithRegexMessage @"EventStoreConnection 'ES-.{36}' is not active.") typeof<System.AggregateException>
Maybe there could be a better message I can make the PR if worth including.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How can I check if a function throws an error which ...
1 Answer 1 · regular expression: error message matches the pattern · string: error message includes the substring · error object: error message...
Read more >How to customize Error Message thrown by validateRegex?
I have the following code, which is throwing a "Regex Pattern not matched" message. I need for it to show a custom message....
Read more >Allow toThrow() matcher to match a regular expression #343
Passing a regex to 'toThrowError' checks that the thrown error message matches the regex. Passing a regex to 'toThrow' will check that what...
Read more >How to use regular expressions, handle exceptions, and ...
Write code that creates and throws an Error object. • Write code that uses a try-catch ... Describe how a regular expression can...
Read more >Validation Regex throw error while submitting the form.
I have created one Validation regex (which is accepting decimal values) or add it in variable , and it's accepting the decimal value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Diffract can show you a diff of your F# types etc., see: https://github.com/d-edge/Diffract
I am not aware about such diffs for .net test frameworks. I believe it cannot be added to DSL library (like FsUnit), It should be supposrted by framework (xUnit, NUnit, MSUnit) and runner (console runner) that will provide colorful output.
AFAIK, Expecto support string diff (but for a git-like diff for objects) https://github.com/haf/expecto/releases/tag/v2.2.0