Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public void Find_Scenarios_In_Feature_File(
}

[Theory]
[InlineData(typeof(AddFeature), new string[] {"AddTwoNumbers.feature", "AddNumbersTo5.feature"})]
[InlineData(typeof(ComplexFeature), new string[] {"Features/ComplexGroupOfScenarios1.feature", "Features/ComplexGroupOfScenarios2.feature", "Features/ComplexGroupOfScenarios3.feature", "Features/Complex.feature"})]
[InlineData(typeof(AddFeature), _addFeature_pattern, new string[] {"AddTwoNumbers.feature", "AddNumbersTo5.feature"})]
[InlineData(typeof(ComplexFeature), _complexFeature_pattern, new string[] {"Features/ComplexGroupOfScenarios1.feature", "Features/ComplexGroupOfScenarios2.feature", "Features/ComplexGroupOfScenarios3.feature", "Features/Complex.feature"})]
public void Find_Scenarios_In_Many_Feature_Files_Sharing_Pattern(
Type featureClassType, string[] files)
Type featureClassType, string pattern, string[] files)
{
//arrange.

_featureFileRepository.Setup(r => r.GetFeatureFilePaths() )
_featureFileRepository.Setup(r => r.FindFilesByPattern(pattern) )
.Returns( new List<String>(files))
.Verifiable();

Expand Down Expand Up @@ -122,13 +122,15 @@ private sealed class MyFeatureWithAttribute : Feature

}

[FeatureFile("Add*.feature")]
private const string _addFeature_pattern = "Add*.feature";
[FeatureFile(_addFeature_pattern)]
private sealed class AddFeature : Feature
{

}

[FeatureFile("Features/Complex*.feature")]
private const string _complexFeature_pattern = "Features/Complex*.feature";
[FeatureFile(_complexFeature_pattern)]
private sealed class ComplexFeature : Feature
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public List<FeatureFile> Discover(Type featureClassType)

if (fileClassInfo.IsPattern) {
_featureFileRepository
.GetFeatureFilePaths()
.FindAll(f => fileClassInfo.MatchesFilePathPattern(f))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what you are trying to fix? MatchesFilePathPattern - this returns false but must return true. Am I missing something?

.ForEach( f=> featurePathsAndFiles.Add(f, _featureFileRepository.GetByFilePath(f)));
.FindFilesByPattern(fileClassInfo.FeatureFilePath)
.ForEach( f=>
featurePathsAndFiles.Add(f, _featureFileRepository.GetByFilePath(f))
);
if (featurePathsAndFiles.Count == 0) {
throw new System.IO.FileNotFoundException($"No features found for pattern ${fileClassInfo.FeatureFilePath}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ private FeatureClassInfo(string featureFilePath)
this._matcher = new Regex(regex,
RegexOptions.Compiled | RegexOptions.IgnoreCase);
}


}

public static FeatureClassInfo FromFeatureClassType(Type featureClassType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using Gherkin;
using Gherkin.Ast;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq;

namespace Xunit.Gherkin.Quick
{
internal sealed class FeatureFileRepository : IFeatureFileRepository
{
private readonly string _featureFileSearchPattern;
private readonly char[] _common_path_separators = new char[]{'/', '\\'};

public FeatureFileRepository(string featureFileSearchPattern)
{
_featureFileSearchPattern = !string.IsNullOrWhiteSpace(featureFileSearchPattern)
? featureFileSearchPattern
: throw new ArgumentNullException(nameof(featureFileSearchPattern));
public FeatureFileRepository(string featureFileSearchPattern)
{
_featureFileSearchPattern = !string.IsNullOrWhiteSpace(featureFileSearchPattern)
? featureFileSearchPattern
: throw new ArgumentNullException(nameof(featureFileSearchPattern));
}

public FeatureFile GetByFilePath(string filePath)
Expand All @@ -35,15 +36,25 @@ private static GherkinDocument ParseGherkinDocument(string filePath)
return gherkinDocument;
}
}
}

public List<string> GetFeatureFilePaths()
{
var featureFilePaths = Directory.GetFiles("./", _featureFileSearchPattern, SearchOption.AllDirectories)
.Select(p => p.Replace('\\', '/'))
.ToList();

return featureFilePaths;
}
}

public List<string> FindFilesByPattern(string pattern) {
var lastPathSeparatorIndex = pattern.LastIndexOfAny(_common_path_separators);
string baseDirectory = Path.GetFullPath(lastPathSeparatorIndex > -1 ? pattern.Substring(0,lastPathSeparatorIndex) : "");
string filePattern = pattern.Substring(lastPathSeparatorIndex+1);
var found = Directory
.EnumerateFiles(baseDirectory, filePattern, SearchOption.AllDirectories)
.ToList();
return found;
}

public List<string> GetFeatureFilePaths()
{
var featureFilePaths = Directory.GetFiles("./", _featureFileSearchPattern, SearchOption.AllDirectories)
.Select(p => p.Replace('\\', '/'))
.ToList();

return featureFilePaths;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Xunit.Gherkin.Quick
{
internal interface IFeatureFileRepository
{
FeatureFile GetByFilePath(string filePath);
List<string> GetFeatureFilePaths();
FeatureFile GetByFilePath(string filePath);
List<string> GetFeatureFilePaths();
List<string> FindFilesByPattern(string pattern);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong here conceptually. This is a feature file repository not a file path repository. What are you trying to do with it?

}
}