Skip to content

Instantly share code, notes, and snippets.

@robfe
Created November 28, 2014 03:09
Show Gist options
  • Save robfe/a2b089ffbddfefdcd179 to your computer and use it in GitHub Desktop.
Save robfe/a2b089ffbddfefdcd179 to your computer and use it in GitHub Desktop.
Adds step names to Approvals.Net file names, so you can have multiple asserts in one unit test
public class ApprovalNameEnhancer : SpecFixtureBase
{
public override void StepSetup(Step step)
{
//tack the step description onto the approval file name:
NamerFactory.AdditionalInformation = step.Description;
//ok, but what if the step used twice in the same spec (with the same arguments)?
var dupes = step.Spec.Steps.Where(x => x.Description == step.Description);
var index = dupes.ToList().IndexOf(step);
if (index > 0)
{
NamerFactory.AdditionalInformation += string.Format("#{0}", index + 1);
}
}
}
@robfe
Copy link
Author

robfe commented Nov 28, 2014

Usage: new Spec("blah").WithFixture<ApprovalNameEnhancer>()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment