diff --git a/convey/context.go b/convey/context.go index 2c75c2d7..3cfbd590 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 e4f7b51a..628f5013 100644 --- a/convey/doc.go +++ b/convey/doc.go @@ -125,6 +125,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{}) {