Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ScenarioInfo.Description parameter to get from context #1078

Merged
merged 7 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions TechTalk.SpecFlow.Generator/UnitTestFeatureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ private void GenerateTestBody(TestClassGenerationContext generationContext, Scen
new CodeVariableDeclarationStatement(typeof(ScenarioInfo), "scenarioInfo",
new CodeObjectCreateExpression(typeof(ScenarioInfo),
new CodePrimitiveExpression(scenario.Name),
new CodePrimitiveExpression(scenario.Description),
tagsExpression)));

AddLineDirective(testMethod.Statements, scenario);
Expand Down
5 changes: 3 additions & 2 deletions TechTalk.SpecFlow/ScenarioInfo.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Linq;

namespace TechTalk.SpecFlow
{
public class ScenarioInfo
{
public string[] Tags { get; private set; }
public string Title { get; private set; }
public string Description { get; private set; }

public ScenarioInfo(string title, params string[] tags)
public ScenarioInfo(string title, string description, params string[] tags)
{
Title = title;
Description = description;
Tags = tags ?? new string[0];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void Setup()

var culture = new CultureInfo("en-US");
contextManagerStub = new Mock<IContextManager>();
scenarioInfo = new ScenarioInfo("scenario_title");
scenarioInfo = new ScenarioInfo("scenario_title", "scenario_description");
scenarioContext = new ScenarioContext(scenarioContainer, scenarioInfo, testObjectResolverMock.Object);
scenarioContainer.RegisterInstanceAs(scenarioContext);
contextManagerStub.Setup(cm => cm.ScenarioContext).Returns(scenarioContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Should_be_able_to_resolve_from_scenario_container()
var testThreadContainer = containerBuilder.CreateTestThreadContainer(containerBuilder.CreateGlobalContainer());
var contextManager = CreateContextManager(testThreadContainer);
contextManager.InitializeFeatureContext(new FeatureInfo(FeatureLanguage, "test feature", null));
contextManager.InitializeScenarioContext(new ScenarioInfo("test scenario"));
contextManager.InitializeScenarioContext(new ScenarioInfo("test scenario", "test_description"));

contextManager.TestThreadContext.Should().NotBeNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private ScenarioContext CreateScenarioContext(Action<IObjectContainer> registerT
{
IObjectContainer testThreadContainer;
testRunner = TestObjectFactories.CreateTestRunner(out testThreadContainer, registerTestThreadMocks, registerGlobalMocks);
return new ScenarioContext(new ObjectContainer(testThreadContainer), new ScenarioInfo("sample scenario", new string[0]), testThreadContainer.Resolve<ITestObjectResolver>());
return new ScenarioContext(new ObjectContainer(testThreadContainer), new ScenarioInfo("sample scenario", "sample scenario description", new string[0]), testThreadContainer.Resolve<ITestObjectResolver>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void CurrentTopLevelStepDefinitionType_AfterInitializingNewScenarioContex

contextManager.InitializeStepContext(this.CreateStepInfo("I have called initialize once"));
//// Do not call CleanupStepContext, in order to simulate an inconsistent state
contextManager.InitializeScenarioContext(new ScenarioInfo("the next scenario"));
contextManager.InitializeScenarioContext(new ScenarioInfo("the next scenario", "description of the next scenario"));

var actualCurrentTopLevelStepDefinitionType = contextManager.CurrentTopLevelStepDefinitionType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public virtual void SetUp()
ContainerBuilderStub = containerBuilderMock.Object;
ContextManagerStub = new ContextManager(MockRepository.Stub<ITestTracer>(), TestThreadContainer, ContainerBuilderStub);
ContextManagerStub.InitializeFeatureContext(new FeatureInfo(FeatureLanguage, "test feature", null));
ContextManagerStub.InitializeScenarioContext(new ScenarioInfo("test scenario"));
ContextManagerStub.InitializeScenarioContext(new ScenarioInfo("test scenario", "test scenario description"));

StepArgumentTypeConverterStub = MockRepository.Stub<IStepArgumentTypeConverter>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void Can_get_and_set_a_null_value_with_a_string()

private static ScenarioContext CreateScenarioContext()
{
return new ScenarioContext(new ObjectContainer(), new ScenarioInfo("Test", new string[] {}), new TestObjectResolver());
return new ScenarioContext(new ObjectContainer(), new ScenarioInfo("Test", "Test Description", new string[] {}), new TestObjectResolver());
}

public class ScenarioTestClass : IScenarioTestInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static IObjectContainer CreateDefaultScenarioContainer(StringConfigProv
var instance = new ContainerBuilder();
var testThreadContainer = CreateDefaultTestThreadContainer(configurationHolder);

return instance.CreateScenarioContainer(testThreadContainer, new ScenarioInfo("test scenario info"));
return instance.CreateScenarioContainer(testThreadContainer, new ScenarioInfo("test scenario info", "test_scenario_description"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public void Should_resolve_a_test_runner_specific_test_tracer()
{
var testRunner1 = TestRunnerManager.GetTestRunner(anAssembly, 0);
testRunner1.OnFeatureStart(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));
testRunner1.OnScenarioStart(new ScenarioInfo("foo"));
testRunner1.OnScenarioStart(new ScenarioInfo("foo", "foo_desc"));
var tracer1 = testRunner1.ScenarioContext.ScenarioContainer.Resolve<ITestTracer>();

var testRunner2 = TestRunnerManager.GetTestRunner(anAssembly, 1);
testRunner2.OnFeatureStart(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));
testRunner2.OnScenarioStart(new ScenarioInfo("foo"));
testRunner2.OnScenarioStart(new ScenarioInfo("foo", "foo_desc"));
var tracer2 = testRunner2.ScenarioContext.ScenarioContainer.Resolve<ITestTracer>();

tracer1.Should().NotBeSameAs(tracer2);
Expand Down
143 changes: 143 additions & 0 deletions Tests/TechTalk.SpecFlow.Specs/Features/Description.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
Feature: DescriptionAccessing

Scenario: Check Scenario description is not empty
Given the following binding class
"""
[Binding]
public class DescriptionTestsBinding
{
[Then(@"Check ""(.*)"" match with scenario description in context")]
public void ThenCheckMatchWithScenarioDescriptionInContext(string desc)
{
var testValue = ScenarioContext.Current.ScenarioInfo.Description;
if (testValue != desc) throw new Exception("Scenario Description is incorrectly parsed");
}
}
"""

And there is a feature file in the project as
"""
Feature: DescriptionFeature
Test Feature Description

Scenario: ScenarioDescriptionCheck
Test Scenario Description
Then Check "Test Scenario Description" match with scenario description in context
"""
When I execute the tests
Then the execution summary should contain
| Succeeded |
| 1 |

Scenario: Check Scenario description is null if empty
Given the following binding class
"""
[Binding]
public class DescriptionTestsBinding
{
[Then(@"Check that scenario description is null in context")]
public void ThenCheckThatScenarioDescriptionIsNullInContext()
{
var testValue = ScenarioContext.Current.ScenarioInfo.Description;
if (testValue != null) throw new Exception("Scenario Description is incorrectly parsed");
}
}
"""

And there is a feature file in the project as
"""
Feature: DescriptionFeature
Test Feature Description

Scenario: ScenarioDescriptionCheck

Then Check that scenario description is null in context
"""
When I execute the tests
Then the execution summary should contain
| Succeeded |
| 1 |


Scenario: Check Feature description is null if empty
Given the following binding class
"""
[Binding]
public class StepsWithFeatureContext
{
private readonly FeatureContext featureContext;

public StepsWithFeatureContext(FeatureContext featureContext)
{
if (featureContext == null) throw new ArgumentNullException("featureContext");
this.featureContext = featureContext;
}

[Then(@"Check that Feature description is null in context")]
public void ThenCheckThatFeatureDescriptionIsNullInContext()
{
var testValue = featureContext.FeatureInfo.Description;;
if (testValue != null) throw new Exception("Feature Description is incorrectly parsed");
}

}
"""

And there is a feature file in the project as
"""
Feature: DescriptionFeature

Scenario: FeatureDescriptionCheck
Then Check that Feature description is null in context
"""
When I execute the tests
Then the execution summary should contain
| Succeeded |
| 1 |


Scenario: Check Feature description is not empty
Given the following binding class
"""
[Binding]
public class StepsWithFeatureContext
{
private readonly FeatureContext featureContext;

public StepsWithFeatureContext(FeatureContext featureContext)
{
if (featureContext == null) throw new ArgumentNullException("featureContext");
this.featureContext = featureContext;
}


[Then(@"Check ""(.*)"" match with Feature description in context")]
public void ThenCheckMatchWithFeatureDescriptionInContext(string desc)
{
var testValue = featureContext.FeatureInfo.Description;;
if (testValue != desc) throw new Exception("Feature Description is incorrectly parsed");
}
}
"""

And there is a feature file in the project as
"""
Feature: DescriptionFeature
Test Feature Description

Scenario: FeatureDescriptionCheck
Then Check "Test Feature Description" match with Feature description in context
"""
When I execute the tests
Then the execution summary should contain
| Succeeded |
| 1 |









Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Feature: DescriptionParser

Scenario: Parsing of Feature Description
Given there is a Gherkin file as
"""
Feature: DescriptionParser
Test Feature Description
"""
When the file is parsed
Then no parsing error is reported

Scenario: Parsing of Scenario Description
Given there is a Gherkin file as
"""
Feature: DescriptionParser

Scenario: ScenarioDescriptionParse
Test Scenario Description
Given something
When something
"""
When the file is parsed
Then no parsing error is reported

Scenario: Parsing of Scenario and Feature Description
Given there is a Gherkin file as
"""
Feature: DescriptionParser
Test Feature Description
Scenario: ScenarioDescriptionParse
Test Scenario Description
Given something
When something
"""
When the file is parsed
Then no parsing error is reported



2 changes: 2 additions & 0 deletions Tests/TechTalk.SpecFlow.Specs/TechTalk.SpecFlow.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@
<None Include="Features\CallingStepsFromStepDefinition.feature" />
<None Include="Features\Configuration.feature" />
<None Include="Features\ContextInjection.feature" />
<None Include="Features\Description.feature" />
<None Include="Features\ExternalSteps.feature" />
<None Include="Features\InAppDomainParallelExecution.feature" />
<None Include="Features\InjectoContextToHooks.feature" />
<None Include="Features\LanguageSupport.feature" />
<None Include="Features\Parser\DescriptionParser.feature" />
<None Include="Features\Reports\StepDefinitionReport.feature" />
<None Include="Features\ScopedHooks.feature" />
<None Include="Features\XUnit2Provider.feature" />
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.4 - 2018-??-??
Fixes:
+ Expose ScenarioInfo.Description parameter to get from context https://github.com/techtalk/SpecFlow/pull/1078


2.3.2 - 2018-04-17
Fixes:
+ Fix issue when using environment variables in a generator plugin's path https://github.com/techtalk/SpecFlow/pull/1045
Expand All @@ -10,12 +15,14 @@ Fixes:
API Changes:
+ Generator probing functionality was moved from GeneratorPluginLoader to GeneratorPluginLocator https://github.com/techtalk/SpecFlow/pull/1045


2.3.1 - 2018-03-01
Fixes:
+ Fixes stepdefinitionreport to include bindings that use [StepDefinition] https://github.com/techtalk/SpecFlow/pull/1024
+ Fix code-behind generation for SpecFlow+Excel Excel files https://github.com/techtalk/SpecFlow/pull/1048
+ Fix runtime support for MSTest V2 https://github.com/techtalk/SpecFlow/pull/1053


2.3 - 2018-02-16

New Features:
Expand Down