Skip to content

Commit

Permalink
#23: BDD: Comments next to scenario steps are now aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Jan 17, 2024
1 parent 902a5d4 commit f66a43e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private void Generate(StringBuilder code, Scenario scenario, string? backgroundM

string scenarioOriginalTitle = scenario.Line.Text.Trim();
code.AppendLine($" [Xunit.Fact(DisplayName = \"{scenarioOriginalTitle.Replace("\"", "\\\"")}\")]");
// TODO: Marcin Celej [from: Marcin Celej on: 16-01-2024]: Align the comment on right side
string methodName = Sentence.ToMethod(scenario.Title);
code.AppendLine($" public void {methodName}() // {scenarioOriginalTitle}");
code.AppendLine(" {");
Expand Down Expand Up @@ -127,10 +126,13 @@ private string GenerateTags(List<string> tags)

private void GenerateSteps(StringBuilder code, List<Step> steps)
{
var max = steps.Max(step => GetStepType(step).Length + Sentence.ToMethod(step.Text).Length) + 2;
foreach (var step in steps)
{
// TODO: Marcin Celej [from: Marcin Celej on: 16-01-2024]: Align the comments on right side
code.AppendLine($" {GetStepType(step)}().{Sentence.ToMethod(step.Text)}(); // {step.Line.Text.Trim()}");
string stepType = GetStepType(step);
string method = Sentence.ToMethod(step.Text);
var spaces = new string(' ', max - stepType.Length - method.Length);
code.AppendLine($" {stepType}().{method}();{spaces}// {step.Line.Text.Trim()}");
}

string GetStepType(Step step)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Technical Debt for Synergy.Contracts

Total: 4
Total: 2

## [XUnitFeatureGenerator.cs](../../../Synergy.Behaviours.Testing/Generator/XUnitFeatureGenerator.cs)
- TODO: Marcin Celej [from: Marcin Celej on: 09-01-2024]: Introduce here [Xunit.Trait("Category", featureName)]
- TODO: Marcin Celej [from: Marcin Celej on: 16-01-2024]: Align the comment on right side
- TODO: Marcin Celej [from: Marcin Celej on: 16-01-2024]: Align the comments on right side

## [GherkinTokenizer.cs](../../../Synergy.Behaviours.Testing/Gherkin/Tokenizer/GherkinTokenizer.cs)
- TODO: Marcin Celej [from: Marcin Celej on: 10-05-2023]: Support Scenario Outline along with Examples
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public void AddTwoNumbers() // Scenario: Add two numbers
{
Background().CalculatorBackground();

Given().TheFirstNumberIs50(); // Given the first number is 50
And().TheSecondNumberIs70(); // And the second number is 70
Given().TheFirstNumberIs50(); // Given the first number is 50
And().TheSecondNumberIs70(); // And the second number is 70
When().TheTwoNumbersAreAdded(); // When the two numbers are added
Then().TheResultShouldBe120(); // Then the result should be 120
Then().TheResultShouldBe120(); // Then the result should be 120

Moreover().AfterAddTwoNumbers();
}

// @Add
[Xunit.Fact(DisplayName = "Scenario: Add two numbers in \"different\" way")]
public void AddTwoNumbersInDifferentWay() // Scenario: Add two numbers in "different" way
[Xunit.Fact(DisplayName = "Example: Add two numbers in \"different\" way")]
public void AddTwoNumbersInDifferentWay() // Example: Add two numbers in "different" way
{
Background().CalculatorBackground();

Given().TwoNumbers(); // Given Two numbers:
And().TheFirstNumberIs50(); // * the first number is 50
And().TheSecondNumberIs70(); // * the second number is 70
Given().TwoNumbers(); // Given Two numbers:
And().TheFirstNumberIs50(); // * the first number is 50
And().TheSecondNumberIs70(); // * the second number is 70
When().TheTwoNumbersAreAdded(); // When the two numbers are added
Then().TheResultShouldBe120(); // Then the result should be 120
Then().TheResultShouldBe120(); // Then the result should be 120
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Calculator
Then the result should be 120

@Add
Scenario: Add two numbers in "different" way
Example: Add two numbers in "different" way
Given Two numbers:
* the first number is 50
* the second number is 70
Expand Down

0 comments on commit f66a43e

Please sign in to comment.