Skip to content

Commit

Permalink
Update cucumber json report format to match official json schema
Browse files Browse the repository at this point in the history
Produce test result value according to
https://github.com/cucumber/cucumber-json-schema

Update existing cucumber tests to run on non-windows platform
picklesdoc#609
  • Loading branch information
Andrey Leskov committed Sep 20, 2021
1 parent bda6b18 commit 136eff3
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StepDefinitions.cs" company="PicklesDoc">
// Copyright 2017 Dmitry Grekov
// Copyright 2012-present PicklesDoc team and community contributors
Expand Down Expand Up @@ -44,19 +44,19 @@ public sealed class StepDefinitions : BaseFixture /* God object antipattern */
[Given("I have this feature description")]
public void IHaveThisFeatureDescription(string featureDescription)
{
var configuration = this.Configuration;
FeatureParser parser = new FeatureParser(Configuration);
FeatureParser parser = new FeatureParser(configuration);

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

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

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

jsonDocumentationBuilder.Build(this.nodes);
Expand All @@ -65,7 +65,7 @@ public void WhenIGenerateTheJsonDocumentation()
[Then("the JSON file should contain")]
public void ThenTheResultShouldBe(string expectedResult)
{
var actualResult = this.FileSystem.File.ReadAllText(@"c:\output\cucumberResult.json");
var actualResult = this.FileSystem.File.ReadAllText(FileSystem.Path.Combine("output","cucumberResult.json"));

//standardize newlines across various environments
actualResult = actualResult.Replace("\r\n", "\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CucumberDocumentationBuilderTests.cs" company="PicklesDoc">
// Copyright 2011 Jeffrey Cameron
// 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.IO;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Reflection;
using NUnit.Framework;
using PicklesDoc.Pickles.DataStructures;
using PicklesDoc.Pickles.DirectoryCrawler;

namespace PicklesDoc.Pickles.DocumentationBuilders.Cucumber.UnitTests
{
[TestFixture]
public class CucumberDocumentationBuilderTests
{
[Test]
public void GIVEN_MacOS_test_When_create_document_Then_there_is_no_error()
{
var featureDescription =
@"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
";

var fileSystem = new FileSystem();
fileSystem.Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
var IFileSystemInfo = fileSystem.DirectoryInfo.FromDirectoryName(@"./");
var configuration = new Configuration
{
OutputFolder = IFileSystemInfo
};
var builder = new CucumberDocumentationBuilder(configuration, fileSystem);
FeatureParser parser = new FeatureParser(configuration);
var feature = parser.Parse(new StringReader(featureDescription));
var tree = new Tree(new FeatureNode(IFileSystemInfo, string.Empty, feature));
builder.Build(tree);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Scenario: A simple feature
"name": "I have entered 50 into the calculator",
"line": 8,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
},
Expand All @@ -55,7 +55,7 @@ Scenario: A simple feature
"name": "I have entered 70 into the calculator",
"line": 9,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
},
Expand All @@ -64,7 +64,7 @@ Scenario: A simple feature
"name": "I press C",
"line": 10,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
},
Expand All @@ -73,7 +73,7 @@ Scenario: A simple feature
"name": "the screen should be empty",
"line": 11,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ Scenario: A feature with a table
"name": "a feature with a large table of data:",
"line": 8,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
},
Expand All @@ -149,7 +149,7 @@ Scenario: A feature with a table
"name": "I click on the table heading",
"line": 32,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
},
Expand All @@ -158,8 +158,9 @@ Scenario: A feature with a table
"name": "the table body should collapse",
"line": 33,
"result": {
"status": "inconclusive",
"status": "Undefined",
"duration": 1
}
}
"""
"""

Loading

0 comments on commit 136eff3

Please sign in to comment.