diff --git a/convey/context.go b/convey/context.go index 0661f567..b3272625 100644 --- a/convey/context.go +++ b/convey/context.go @@ -177,6 +177,17 @@ func (ctx *context) So(actual interface{}, assert Assertion, expected ...interfa } } +func (ctx *context) SoMsg(msg string, actual interface{}, assert assertion, expected ...interface{}) { + if result := assert(actual, expected...); result == assertionSuccess { + ctx.assertionReport(reporting.NewSuccessReport()) + return + } else { + ctx.reporter.Enter(reporting.NewScopeReport(msg)) + defer ctx.reporter.Exit() + ctx.assertionReport(reporting.NewFailureReport(result)) + } +} + func (ctx *context) Reset(action func()) { /* TODO: Failure mode configuration */ ctx.resets = append(ctx.resets, action) diff --git a/convey/doc.go b/convey/doc.go index 50e93692..a8bdfa15 100644 --- a/convey/doc.go +++ b/convey/doc.go @@ -24,6 +24,7 @@ type C interface { FocusConvey(items ...interface{}) So(actual interface{}, assert Assertion, expected ...interface{}) + SoMsg(msg string, actual interface{}, assert Assertion, expected ...interface{}) SkipSo(stuff ...interface{}) Reset(action func()) @@ -125,6 +126,11 @@ func So(actual interface{}, assert Assertion, expected ...interface{}) { mustGetCurrentContext().So(actual, assert, expected...) } +// SoMsg is an extension of So that allows you to specify a message to report on error. +func SoMsg(msg string, actual interface{}, assert assertion, expected ...interface{}) { + mustGetCurrentContext().SoMsg(msg, actual, assert, expected...) +} + // SkipSo is analogous to So except that the assertion that would have been passed // to So is not executed and the reporter is notified that the assertion was skipped. func SkipSo(stuff ...interface{}) {