Skip to content

Instantly share code, notes, and snippets.

@robfe
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robfe/d5f9cc160dcb573bd7ea to your computer and use it in GitHub Desktop.
Save robfe/d5f9cc160dcb573bd7ea to your computer and use it in GitHub Desktop.
Make XUnit tests dynamically skippable for SpecLight
/// <summary>
/// Speclight users like to see "Pending" steps (that throw NotImplementedException) as "skip" not "fail"
/// </summary>
public class SpecAttribute : FactAttribute
{
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
yield return new SkipIfNotImplemented(method);
}
class SkipIfNotImplemented : FactCommand
{
public SkipIfNotImplemented(IMethodInfo method) : base(method){}
public override MethodResult Execute(object testClass)
{
try
{
return base.Execute(testClass);
}
catch (NotImplementedException e)
{
return new SkipResult(testMethod, DisplayName, e.Message);
}
}
}
//the rest of this file can be deleted if you're not using ApprovalTests.Net
static SpecAttribute()
{
ApprovalTests.Namers.StackTraceParsers.StackTraceParser.AddParser(new StackTraceParser());
}
public class StackTraceParser : AttributeStackTraceParser
{
public override string ForTestingFramework
{
get { return "xUnit Spec"; }
}
protected override string GetAttributeType()
{
return typeof(SpecAttribute).FullName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment