Skip to content

Commit

Permalink
#56 Merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
x97mdr committed Jan 20, 2012
2 parents 968b628 + 3be97c2 commit 17693bf
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@FeatureTag
Feature: Feature title
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers

Background: Background name
Given background given
When background when
Then background then

@simpleScenario
Scenario: Simple Scenario
Given simple scenario given
And simple scenario given and
When simple scenario when
Then simple scenario then

@scenarioOutline
Scenario Outline: Scenario outline example
Given outline given <value 1>
When outline when <value 2>
Then outline then <value 3>
But nothing important here

Scenarios:
| value 1 | value 2 | value 3 |
| 123 | 456 | 789 |
| abc | def | ghi |
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Pickles.Test.Helpers;
using Pickles.DirectoryCrawler;


namespace Pickles.Test.Formatters
{
[TestFixture]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.IO;
using NUnit.Framework;
using Pickles.DirectoryCrawler;
using Pickles.DocumentationBuilders.JSON;
using Pickles.Parser;
using Should.Fluent;

namespace Pickles.Test.Formatters.JSON
{
public class when_creating_a_feature_with_meta_info
{

private const string RELATIVE_PATH = @"AcceptanceTest";
private const string ROOT_PATH = @"FakeFolderStructures\AcceptanceTest";
private const string FEATURE_PATH = @"AdvancedFeature.feature";

private Feature _testFeature;
private FileInfo _featureFileInfo;
private FeatureDirectoryTreeNode _featureDirectoryNode;
private FeatureWithMetaInfo _featureWithMeta;

[TestFixtureSetUp]
public void Setup()
{
_testFeature = new Feature { Name = "Test" };
_featureFileInfo = new FileInfo(Path.Combine(ROOT_PATH, FEATURE_PATH));
_featureDirectoryNode = new FeatureDirectoryTreeNode(_featureFileInfo, RELATIVE_PATH, _testFeature);

_featureWithMeta = new FeatureWithMetaInfo(_featureDirectoryNode);

}

[Test]
public void it_should_contain_the_feature()
{
_featureWithMeta.Feature.Should().Not.Be.Null();
_featureWithMeta.Feature.Name.Should().Equal("Test");
}

[Test]
public void it_should_contain_the_relative_path()
{
_featureWithMeta.RelativeFolder.Should().Equal(RELATIVE_PATH);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.IO;
using Ninject;
using NUnit.Framework;
using Pickles.DirectoryCrawler;
using Pickles.DocumentationBuilders.JSON;
using Should.Fluent;
using Pickles.Test.Helpers;


namespace Pickles.Test.Formatters.JSON
{
[TestFixture]
public class when_formatting_a_folder_structure_with_features : BaseFixture
{
private string filePath = Path.Combine(OUTPUT_DIRECTORY, JSONDocumentationBuilder.JS_FILE_NAME);
private const string ROOT_PATH = @"FakeFolderStructures";
private const string OUTPUT_DIRECTORY = @"C:\temp\";


[TestFixtureSetUp]
public void Setup()
{
var features = Kernel.Get<DirectoryTreeCrawler>().Crawl(ROOT_PATH);

var configuration = new Configuration
{
OutputFolder = new DirectoryInfo(OUTPUT_DIRECTORY),
DocumentationFormat = DocumentationFormat.JSON
};

var jsonDocumentationBuilder = new JSONDocumentationBuilder(configuration);
jsonDocumentationBuilder.Build(features);
}

[Test]
public void a_single_file_should_have_been_created()
{
File.Exists(filePath).Should().Be.True();
}

[Test]
public void should_contain_the_features()
{
var content = File.ReadAllText(filePath);
content.AssertJSONKeyValue("Name", "Addition");
}
}
}
20 changes: 20 additions & 0 deletions src/Pickles/Pickles.Test/Helpers/JSONStringAssertHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Should.Fluent;

namespace Pickles.Test.Helpers
{
public static class JSONStringAssertHelpers
{
private const string KEY_VALUE_TEMPLATE = "\"{0}\": \"{1}\"";
private const string ARRAY_TEMPLATE = "\"{0}\": [\r\n \"{1}\"\r\n ]";

public static void AssertJSONKeyValue(this string json, string key, string value)
{
json.Should().Contain(string.Format(KEY_VALUE_TEMPLATE, key, value));
}

public static void AssertJSONArrayValue(this string json, string key, string value)
{
json.Should().Contain(string.Format(ARRAY_TEMPLATE, key, value));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Xml.Linq;

namespace Pickles.Test.Helpers
{
public static class Class1
public static class XElementExentions
{
public static XElement FindFirstDescendantWithName(this XElement xelement, string localName )
{
Expand Down
12 changes: 11 additions & 1 deletion src/Pickles/Pickles.Test/Pickles.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.0.10827\lib\NET35\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NGenerics">
<HintPath>..\..\..\lib\ngenerics\NGenerics.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -156,7 +159,10 @@
</Compile>
<Compile Include="AssertExtensions.cs" />
<Compile Include="BaseFixture.cs" />
<Compile Include="Helpers\Class1.cs" />
<Compile Include="Formatters\JSON\when_creating_a_feature_with_meta_info.cs" />
<Compile Include="Formatters\JSON\when_formatting_a_folder_structure_with_features.cs" />
<Compile Include="Helpers\XElementExentions.cs" />
<Compile Include="Helpers\JSONStringAssertHelpers.cs" />
<Compile Include="WhenCrawlingFoldersForFeatures.cs" />
<Compile Include="Formatters\HtmlTableOfContentsFormatterTests.cs" />
<Compile Include="ParserFileFactory.cs" />
Expand Down Expand Up @@ -208,6 +214,9 @@
<LastGenOutput>Background.feature.cs</LastGenOutput>
</EmbeddedResource>
<None Include="App.config" />
<None Include="FakeFolderStructures\AcceptanceTest\AdvancedFeature.feature">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="FakeFolderStructures\AcceptanceTest\LevelOne.feature">
<LastGenOutput>LevelOne.feature.cs</LastGenOutput>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -245,6 +254,7 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject;
using Ninject;
using NUnit.Framework;
using Pickles.DocumentationBuilders.DITA;
using Pickles.DirectoryCrawler;
Expand All @@ -14,6 +10,8 @@ namespace Pickles.Test
[TestFixture]
public class WhenGeneratingPathsFromFeaturesToDitaFiles : BaseFixture
{
private Feature _testFeature = new Feature();

[Test]
public void ThenCanGeneratePathToTopLevelFeatureFileSuccessfully()
{
Expand Down
1 change: 1 addition & 0 deletions src/Pickles/Pickles.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<package id="IKVM" version="0.46.0.1" />
<package id="MarkdownSharp" version="1.13.0.0" />
<package id="Moq" version="4.0.10827" />
<package id="Newtonsoft.Json" version="4.0.5" />
<package id="Ninject" version="2.2.1.4" />
<package id="NUnit" version="2.5.10.11092" />
<package id="Should" version="1.1.12.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Uri GeneratePathToFeature(IDirectoryTreeNode directoryTreeNode)
if (fileInfo != null)
{
var nodeFilename = directoryTreeNode.OriginalLocation.Name.Replace(directoryTreeNode.OriginalLocation.Extension, string.Empty);
var nodeDitaName = directoryTreeNode.Name.ToDitaName() + ".dita";
var nodeDitaName = nodeFilename.ToDitaName() + ".dita";
var newUri = new Uri(Path.Combine(fileInfo.Directory.FullName.ToLowerInvariant(), nodeDitaName));

return new Uri(this.configuration.FeatureFolder.FullName + @"\").MakeRelativeUri(newUri);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Pickles.DirectoryCrawler;
using Pickles.Parser;

namespace Pickles.DocumentationBuilders.JSON
{
public class FeatureWithMetaInfo
{
public string RelativeFolder { get; set; }
public Feature Feature { get; set; }

public FeatureWithMetaInfo(FeatureDirectoryTreeNode featureNodeTreeNode)
{
Feature = featureNodeTreeNode.Feature;
RelativeFolder = featureNodeTreeNode.RelativePathFromRoot;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#region License

/*
Copyright [2011] [Jeffrey Cameron]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NGenerics.DataStructures.Trees;
using NGenerics.Patterns.Visitor;
using Pickles.DirectoryCrawler;

namespace Pickles.DocumentationBuilders.JSON
{
public class JSONDocumentationBuilder : IDocumentationBuilder
{

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

private readonly Configuration configuration;

public const string JS_FILE_NAME = @"pickledFeatures.json";


public JSONDocumentationBuilder(Configuration configuration)
{
this.configuration = configuration;
}

public void Build(GeneralTree<IDirectoryTreeNode> features)
{
if (log.IsInfoEnabled)
{
log.InfoFormat("Writing JSON to {0}", this.configuration.OutputFolder.FullName);
}

var featuresToFormat = new List<FeatureWithMetaInfo>();

var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node =>
{
var featureTreeNode = node as FeatureDirectoryTreeNode;
if (featureTreeNode != null)
{
featuresToFormat.Add(new FeatureWithMetaInfo(featureTreeNode));
}
});

features.AcceptVisitor(actionVisitor);

CreateFile(OutputFilePath, GenerateJSON(featuresToFormat));
}

private string OutputFilePath
{
get { return Path.Combine(configuration.OutputFolder.FullName, JS_FILE_NAME); }
}

private static string GenerateJSON(List<FeatureWithMetaInfo> features)
{
var settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new StringEnumConverter() }
};

return JsonConvert.SerializeObject(features, Formatting.Indented, settings);
}

private static void CreateFile(string outputFolderName, string jsonToWrite)
{
using (var writer = new StreamWriter(outputFolderName, false, Encoding.UTF8))
{
writer.Write(jsonToWrite);
writer.Close();
}
}
}
}
3 changes: 2 additions & 1 deletion src/Pickles/Pickles/DocumentationFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum DocumentationFormat
{
Html,
Word,
Dita
Dita,
JSON
}
}
6 changes: 5 additions & 1 deletion src/Pickles/Pickles/FeatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public Feature Parse(string filename)
}
catch (Exception e)
{
throw new FeatureParseException("There was an error parsing the feature file here: " + Path.GetFullPath(filename), e);
var message = string.Format("There was an error parsing the feature file here: {0}{1}Errormessage was:'{2}'",
Path.GetFullPath(filename),
Environment.NewLine,
e.Message);
throw new FeatureParseException(message, e);
}

reader.Close();
Expand Down
2 changes: 2 additions & 0 deletions src/Pickles/Pickles/Pickles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
<Compile Include="DocumentationBuilders\HTML\HtmlTableFormatter.cs" />
<Compile Include="DocumentationBuilders\HTML\HtmlTableOfContentsFormatter.cs" />
<Compile Include="DocumentationBuilders\IDocumentationBuilder.cs" />
<Compile Include="DocumentationBuilders\JSON\FeatureWithMetaInfo.cs" />
<Compile Include="DocumentationBuilders\JSON\JSONDocumentationBuilder.cs" />
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\PtOpenXmlUtil.cs" />
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\PtUtil.cs" />
<Compile Include="DocumentationBuilders\Word\TableOfContentsAdder\TocAdder.cs" />
Expand Down
Loading

0 comments on commit 17693bf

Please sign in to comment.