Created
November 28, 2014 03:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
new Spec("blah").WithFixture<ApprovalNameEnhancer>()