You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we are using a bespoke Step attribute to introduce consistency when naming steps . This works in Visual Studio, but the Rider (plugin) does not recognize any steps annotated with our custom attribute so the navigation/step highlighting/suggestions in SpecFlow feature files do not work
public partial class AutoStepAttribute : StepDefinitionBaseAttribute
{
// https://stackoverflow.com/questions/3216085/split-a-pascalcase-string-into-separate-words
[GeneratedRegex(@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])")]
private static partial Regex CreateStepNameRegex();
private static readonly Regex _stepNameRegex = CreateStepNameRegex();
[Obsolete("This constructor should not be used, instead the step name should be auto generated. It is only defined so SpecFlow step scanning works without the explicitely defined regex. Seems like SpecFlow is using StepDefinition constructors definitions to influence their behaviour")]
public AutoStepAttribute(string regex, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "")
: this(memberName, sourceFilePath)
{ }
public AutoStepAttribute([CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "")
: base(null, new[] { StepDefinitionType.Given, StepDefinitionType.When, StepDefinitionType.Then })
{
Regex = GetStepName(memberName, sourceFilePath);
}
private static string GetStepName(string memberName, string sourceFilePath)
{
var fileName = Path.GetFileNameWithoutExtension(sourceFilePath);
var stepsName = fileName.Replace("Steps", string.Empty);
var stepName = ParseStepName(memberName);
var result = $"{stepsName} {stepName}";
return result;
}
private static string ParseStepName(string defintion)
{
defintion = defintion.Replace("_", string.Empty);
var words = _stepNameRegex.Split(defintion);
StringBuilder sb = new();
foreach (var word in words)
{
if (sb.Length > 0)
{
sb.Append(' ');
}
if (word.Length > 1 && char.IsUpper(word[1])) // if it's a variable
{
sb.Append("(.*)");
}
else
{
sb.Append(word.ToLower(CultureInfo.InvariantCulture));
}
}
return sb.ToString();
}
}
Usage inside Steps file
[AutoStep]
public async Task IsSelected()
{
....
}
Is implementing StepDefinitionBaseAttribute not supported by the Rider plugin?
Kind regards,
Stefan
The text was updated successfully, but these errors were encountered:
Hi,
we are using a bespoke Step attribute to introduce consistency when naming steps . This works in Visual Studio, but the Rider (plugin) does not recognize any steps annotated with our custom attribute so the navigation/step highlighting/suggestions in SpecFlow feature files do not work
Usage inside Steps file
Is implementing StepDefinitionBaseAttribute not supported by the Rider plugin?
Kind regards,
Stefan
The text was updated successfully, but these errors were encountered: