mirror of
https://github.com/Smaug123/WoofWare.Expect
synced 2025-10-09 06:08:40 +00:00
Add a specific exception (#3)
This commit is contained in:
@@ -27,7 +27,7 @@ actual was:
|
|||||||
|
|
||||||
return
|
return
|
||||||
Assert
|
Assert
|
||||||
.Throws<Exception>(fun () ->
|
.Throws<ExpectException>(fun () ->
|
||||||
expectWithMockedFilePath ("filepath.fs", 99) {
|
expectWithMockedFilePath ("filepath.fs", 99) {
|
||||||
snapshot "123"
|
snapshot "123"
|
||||||
return 124
|
return 124
|
||||||
|
@@ -15,6 +15,9 @@ type private SnapshotValue =
|
|||||||
| BareString of string
|
| BareString of string
|
||||||
| Json of string
|
| Json of string
|
||||||
|
|
||||||
|
/// An exception indicating that a value failed to match its snapshot.
|
||||||
|
exception ExpectException of Message : string
|
||||||
|
|
||||||
/// A dummy type which is here to provide better error messages when you supply
|
/// A dummy type which is here to provide better error messages when you supply
|
||||||
/// the `snapshot` keyword multiple times.
|
/// the `snapshot` keyword multiple times.
|
||||||
type YouHaveSuppliedMultipleSnapshots = private | NonConstructible
|
type YouHaveSuppliedMultipleSnapshots = private | NonConstructible
|
||||||
@@ -160,25 +163,29 @@ type ExpectBuilder (?sourceOverride : string * int) =
|
|||||||
JsonSerializer.Serialize (actual, options) |> JsonDocument.Parse
|
JsonSerializer.Serialize (actual, options) |> JsonDocument.Parse
|
||||||
|
|
||||||
if not (JsonElement.DeepEquals (canonicalActual.RootElement, canonicalSnapshot.RootElement)) then
|
if not (JsonElement.DeepEquals (canonicalActual.RootElement, canonicalSnapshot.RootElement)) then
|
||||||
failwithf
|
sprintf
|
||||||
"snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s"
|
"snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s"
|
||||||
(sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath)
|
(sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath)
|
||||||
(sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber)
|
(sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber)
|
||||||
source.MemberName
|
source.MemberName
|
||||||
(canonicalSnapshot.RootElement.ToString () |> Text.predent '-')
|
(canonicalSnapshot.RootElement.ToString () |> Text.predent '-')
|
||||||
(canonicalActual.RootElement.ToString () |> Text.predent '-')
|
(canonicalActual.RootElement.ToString () |> Text.predent '-')
|
||||||
|
|> ExpectException
|
||||||
|
|> raise
|
||||||
|
|
||||||
| SnapshotValue.BareString snapshot ->
|
| SnapshotValue.BareString snapshot ->
|
||||||
let actual = actual.ToString ()
|
let actual = actual.ToString ()
|
||||||
|
|
||||||
if actual <> snapshot then
|
if actual <> snapshot then
|
||||||
failwithf
|
sprintf
|
||||||
"snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s"
|
"snapshot mismatch! snapshot at %s:%i (%s) was:\n\n%s\n\nactual was:\n\n%s"
|
||||||
(sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath)
|
(sourceOverride |> Option.map fst |> Option.defaultValue source.FilePath)
|
||||||
(sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber)
|
(sourceOverride |> Option.map snd |> Option.defaultValue source.LineNumber)
|
||||||
source.MemberName
|
source.MemberName
|
||||||
(snapshot |> Text.predent '-')
|
(snapshot |> Text.predent '-')
|
||||||
(actual |> Text.predent '+')
|
(actual |> Text.predent '+')
|
||||||
|
|> ExpectException
|
||||||
|
|> raise
|
||||||
|
|
||||||
| None, _ -> failwith "Must specify snapshot"
|
| None, _ -> failwith "Must specify snapshot"
|
||||||
| _, None -> failwith "Must specify actual value with 'return'"
|
| _, None -> failwith "Must specify actual value with 'return'"
|
||||||
|
@@ -11,6 +11,12 @@ WoofWare.Expect.ExpectBuilder.Return [method]: unit -> 'T WoofWare.Expect.Expect
|
|||||||
WoofWare.Expect.ExpectBuilder.Run [method]: (unit -> 'T WoofWare.Expect.ExpectState) -> unit
|
WoofWare.Expect.ExpectBuilder.Run [method]: (unit -> 'T WoofWare.Expect.ExpectState) -> unit
|
||||||
WoofWare.Expect.ExpectBuilder.Snapshot [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
WoofWare.Expect.ExpectBuilder.Snapshot [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
||||||
WoofWare.Expect.ExpectBuilder.SnapshotJson [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
WoofWare.Expect.ExpectBuilder.SnapshotJson [method]: (unit WoofWare.Expect.ExpectState, string, string option, int option, string option) -> WoofWare.Expect.YouHaveSuppliedMultipleSnapshots WoofWare.Expect.ExpectState
|
||||||
|
WoofWare.Expect.ExpectException inherit System.Exception, implements System.Collections.IStructuralEquatable
|
||||||
|
WoofWare.Expect.ExpectException..ctor [constructor]: string
|
||||||
|
WoofWare.Expect.ExpectException..ctor [constructor]: unit
|
||||||
|
WoofWare.Expect.ExpectException.Equals [method]: (System.Exception, System.Collections.IEqualityComparer) -> bool
|
||||||
|
WoofWare.Expect.ExpectException.Equals [method]: System.Exception -> bool
|
||||||
|
WoofWare.Expect.ExpectException.Message [property]: [read-only] string
|
||||||
WoofWare.Expect.ExpectState`1 inherit obj, implements 'T WoofWare.Expect.ExpectState System.IEquatable, System.Collections.IStructuralEquatable, 'T WoofWare.Expect.ExpectState System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
WoofWare.Expect.ExpectState`1 inherit obj, implements 'T WoofWare.Expect.ExpectState System.IEquatable, System.Collections.IStructuralEquatable, 'T WoofWare.Expect.ExpectState System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
||||||
WoofWare.Expect.ExpectState`1.Equals [method]: ('T WoofWare.Expect.ExpectState, System.Collections.IEqualityComparer) -> bool
|
WoofWare.Expect.ExpectState`1.Equals [method]: ('T WoofWare.Expect.ExpectState, System.Collections.IEqualityComparer) -> bool
|
||||||
WoofWare.Expect.YouHaveSuppliedMultipleSnapshots inherit obj, implements WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IEquatable, System.Collections.IStructuralEquatable, WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
WoofWare.Expect.YouHaveSuppliedMultipleSnapshots inherit obj, implements WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IEquatable, System.Collections.IStructuralEquatable, WoofWare.Expect.YouHaveSuppliedMultipleSnapshots System.IComparable, System.IComparable, System.Collections.IStructuralComparable
|
||||||
|
Reference in New Issue
Block a user