Skip to content

Commit

Permalink
Adding Cucumber JSON Documentation Builder (#413)
Browse files Browse the repository at this point in the history
* Adding Cucumber JSON as possible export format

* Version

* fixing the tests

* Fixing unit tests

* Separated Cucumber Documentation as separate project

* Fixing Build Pipeline

* Adding missed build dependency steps

* resolved the namespace issues that was preventing the build from completing successfully

* Addressing code review comments

* adding cucumber output format
  • Loading branch information
dgrekov authored and dirkrombauts committed Jan 25, 2017
1 parent ddd1f08 commit 5769fa5
Show file tree
Hide file tree
Showing 33 changed files with 1,123 additions and 7 deletions.
7 changes: 7 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ Target "BuildTest.TestFrameworks" (fun _ ->
|> Log "AppBuild-Output: "
)

Target "BuildTest.DocumentationBuilders.Cucumber" (fun _ ->
!! "src/Pickles/Pickles.DocumentationBuilders.Cucumber.UnitTests/Pickles.DocumentationBuilders.Cucumber.UnitTests.csproj"
|> MSBuildRelease testDir "Build"
|> Log "AppBuild-Output: "
)

Target "BuildTest.DocumentationBuilders.Dhtml" (fun _ ->
!! "src/Pickles/Pickles.DocumentationBuilders.Dhtml.UnitTests/Pickles.DocumentationBuilders.Dhtml.UnitTests.csproj"
|> MSBuildRelease testDir "Build"
Expand Down Expand Up @@ -124,6 +130,7 @@ Target "Default" (fun _ ->
==> "BuildGui"
==> "BuildTest"
==> "BuildTest.TestFrameworks"
==> "BuildTest.DocumentationBuilders.Cucumber"
==> "BuildTest.DocumentationBuilders.Dhtml"
==> "BuildTest.DocumentationBuilders.Excel"
==> "BuildTest.DocumentationBuilders.Html"
Expand Down
2 changes: 2 additions & 0 deletions chocolatey.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Target "CreatePackage CMD" (fun _ ->
cmdDir + "PicklesDoc.Pickles.Library.dll";
cmdDir + "PicklesDoc.Pickles.ObjectModel.dll";
cmdDir + "PicklesDoc.Pickles.TestFrameworks.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Word.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Excel.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Json.dll";
Expand Down Expand Up @@ -73,6 +74,7 @@ Target "CreatePackage GUI" (fun _ ->
guiDir + "PicklesDoc.Pickles.Library.dll";
guiDir + "PicklesDoc.Pickles.ObjectModel.dll";
guiDir + "PicklesDoc.Pickles.TestFrameworks.dll";
guiDir + "PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll";
guiDir + "PicklesDoc.Pickles.DocumentationBuilders.Word.dll";
guiDir + "PicklesDoc.Pickles.DocumentationBuilders.Excel.dll";
guiDir + "PicklesDoc.Pickles.DocumentationBuilders.Json.dll";
Expand Down
1 change: 1 addition & 0 deletions chocolatey/pickles.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Optionally, *Pickles* can **integrate test results**, so that your stakeholders
<file src="PicklesDoc.Pickles.Library.dll" target="tools" />
<file src="PicklesDoc.Pickles.ObjectModel.dll" target="tools" />
<file src="PicklesDoc.Pickles.TestFrameworks.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Word.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Excel.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Json.dll" target="tools" />
Expand Down
1 change: 1 addition & 0 deletions chocolatey/picklesui.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Optionally, *Pickles* can **integrate test results**, so that your stakeholders
<file src="PicklesDoc.Pickles.Library.dll" target="tools" />
<file src="PicklesDoc.Pickles.ObjectModel.dll" target="tools" />
<file src="PicklesDoc.Pickles.TestFrameworks.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Word.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Excel.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Json.dll" target="tools" />
Expand Down
Empty file added index.html
Empty file.
3 changes: 3 additions & 0 deletions nuget.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Target "CreatePackageCommandLine" (fun _ ->
cmdDir + "PicklesDoc.Pickles.Library.dll";
cmdDir + "PicklesDoc.Pickles.ObjectModel.dll";
cmdDir + "PicklesDoc.Pickles.TestFrameworks.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Word.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Excel.dll";
cmdDir + "PicklesDoc.Pickles.DocumentationBuilders.Json.dll";
Expand Down Expand Up @@ -67,6 +68,7 @@ Target "CreatePackageMsBuild" (fun _ ->
msBuildDir + "PicklesDoc.Pickles.Library.dll";
msBuildDir + "PicklesDoc.Pickles.ObjectModel.dll";
msBuildDir + "PicklesDoc.Pickles.TestFrameworks.dll";
msBuildDir + "PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll";
msBuildDir + "PicklesDoc.Pickles.DocumentationBuilders.Word.dll";
msBuildDir + "PicklesDoc.Pickles.DocumentationBuilders.Excel.dll";
msBuildDir + "PicklesDoc.Pickles.DocumentationBuilders.Json.dll";
Expand Down Expand Up @@ -103,6 +105,7 @@ Target "CreatePackagePowerShell" (fun _ ->
powerShellDir + "PicklesDoc.Pickles.ObjectModel.dll";
powerShellDir + "PicklesDoc.Pickles.TestFrameworks.dll";
powerShellDir + "PicklesDoc.Pickles.PowerShell.dll";
powerShellDir + "PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll";
powerShellDir + "PicklesDoc.Pickles.DocumentationBuilders.Word.dll";
powerShellDir + "PicklesDoc.Pickles.DocumentationBuilders.Excel.dll";
powerShellDir + "PicklesDoc.Pickles.DocumentationBuilders.Json.dll";
Expand Down
3 changes: 1 addition & 2 deletions src/Pickles/.vs/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@
</site>
<site name="Pickles.BaseDhtmlFiles" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\DevProjects\Tools\pickles\src\Pickles\Pickles.BaseDhtmlFiles" />
</application>
<virtualDirectory path="/" physicalPath="Z:\pickles\src\Pickles\Pickles.BaseDhtmlFiles" /> </application>
<bindings>
<binding protocol="http" bindingInformation="*:52000:localhost" />
</bindings>
Expand Down
1 change: 1 addition & 0 deletions src/Pickles/Pickles.CommandLine/Pickles.CommandLine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<file src="PicklesDoc.Pickles.Library.dll" target="tools" />
<file src="PicklesDoc.Pickles.ObjectModel.dll" target="tools" />
<file src="PicklesDoc.Pickles.TestFrameworks.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Cucumber.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Word.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Excel.dll" target="tools" />
<file src="PicklesDoc.Pickles.DocumentationBuilders.Json.dll" target="tools" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="NUnit" />

</specFlow>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StepDefinitions.cs" company="PicklesDoc">
// Copyright 2017 Dmitry Grekov
// Copyright 2012-present PicklesDoc team and community contributors
//
//
// 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.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using PicklesDoc.Pickles.DocumentationBuilders.Cucumber;
using PicklesDoc.Pickles.Test;
using PicklesDoc.Pickles.DataStructures;
using PicklesDoc.Pickles;
using System.IO;
using PicklesDoc.Pickles.DirectoryCrawler;
using Autofac;
using NFluent;

namespace Pickles.DocumentationBuilders.Cucumber.UnitTests.AutomationLayer
{
[Binding]
[Scope(Tag = "cucumber")]
public sealed class StepDefinitions : BaseFixture /* God object antipattern */
{
private Tree nodes;

[Given("I have this feature description")]
public void IHaveThisFeatureDescription(string featureDescription)
{
var configuration = this.Configuration;
FeatureParser parser = new FeatureParser(this.FileSystem, configuration);

var feature = parser.Parse(new StringReader(featureDescription));

this.nodes = new Tree(new FeatureNode(this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\"), string.Empty, feature));
}

[When(@"I generate the documentation")]
public void WhenIGenerateTheJsonDocumentation()
{
var configuration = this.Configuration;
configuration.OutputFolder = this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\");
var jsonDocumentationBuilder = this.Container.Resolve<CucumberDocumentationBuilder>();

jsonDocumentationBuilder.Build(this.nodes);
}

[Then("the JSON file should contain")]
public void ThenTheResultShouldBe(string expectedResult)
{
var actualResult = this.FileSystem.File.ReadAllText(@"c:\output\cucumberResult.json");

//standardize newlines across various environments
actualResult = actualResult.Replace("\r\n", "\n");
expectedResult = expectedResult.Replace("\r\n", "\n");
Check.That(actualResult).Contains(expectedResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
Feature: Formatting A Feature

@cucumber
Scenario: A simple feature

Given I have this feature description
"""
Feature: Clearing Screen
In order to restart a new set of calculations
As a math idiot
I want to be able to clear the screen
@workflow @slow
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
"""
When I generate the documentation
Then the JSON file should contain
"""
[
{
"keyword": "Feature",
"name": "Clearing Screen",
"tags": [],
"line": 1,
"elements": [
{
"keyword": "Scenario",
"name": "Clear the screen",
"line": 7,
"type": "scenario",
"tags": [
{
"name": "@workflow"
},
{
"name": "@slow"
}
],
"steps": [
{
"keyword": "Given",
"name": "I have entered 50 into the calculator",
"line": 8,
"result": {
"status": "inconclusive",
"duration": 1
}
},
{
"keyword": "And",
"name": "I have entered 70 into the calculator",
"line": 9,
"result": {
"status": "inconclusive",
"duration": 1
}
},
{
"keyword": "When",
"name": "I press C",
"line": 10,
"result": {
"status": "inconclusive",
"duration": 1
}
},
{
"keyword": "Then",
"name": "the screen should be empty",
"line": 11,
"result": {
"status": "inconclusive",
"duration": 1
}
}
"""

@cucumber
Scenario: A feature with a table

Given I have this feature description
"""
Feature: Interactive DHTML View
In order to increase stakeholder engagement with pickled specs
As a SpecFlow evangelist
I want to adjust the level of detail in the DHTML view to suit my audience
So that I do not overwhelm them.
Scenario: Scenario with large data table
Given a feature with a large table of data:
| heading | page # |
| Chapter 1 | 1 |
| Chapter 2 | 5 |
| Chapter 3 | 10 |
| Chapter 4 | 15 |
| Chapter 5 | 20 |
| Chapter 6 | 25 |
| Chapter 7 | 30 |
| Chapter 8 | 35 |
| Chapter 9 | 40 |
| Chapter 10 | 45 |
| Chapter 11 | 50 |
| Chapter 12 | 55 |
| Chapter 13 | 60 |
| Chapter 14 | 65 |
| Chapter 15 | 70 |
| Chapter 16 | 75 |
| Chapter 17 | 80 |
| Chapter 18 | 85 |
| Chapter 19 | 90 |
| Chapter 20 | 95 |
| Chapter 21 | 100 |
| Chapter 22 | 105 |
When I click on the table heading
Then the table body should collapse
"""
When I generate the documentation
Then the JSON file should contain
"""
[
{
"keyword": "Feature",
"name": "Interactive DHTML View",
"tags": [],
"line": 1,
"elements": [
{
"keyword": "Scenario",
"name": "Scenario with large data table",
"line": 7,
"type": "scenario",
"tags": [],
"steps": [
{
"keyword": "Given",
"name": "a feature with a large table of data:",
"line": 8,
"result": {
"status": "inconclusive",
"duration": 1
}
},
{
"keyword": "When",
"name": "I click on the table heading",
"line": 32,
"result": {
"status": "inconclusive",
"duration": 1
}
},
{
"keyword": "Then",
"name": "the table body should collapse",
"line": 33,
"result": {
"status": "inconclusive",
"duration": 1
}
}
"""
Loading

0 comments on commit 5769fa5

Please sign in to comment.