Skip to content

Commit ba9903a

Browse files
author
Jake Ginnivan
committed
Fixing issue with empty string in examples causing value not to be used error, and also empty string gets turned into null (we only want that behaviour for text table)
1 parent bc87dad commit ba9903a

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

TestStack.BDDfy.Tests/Scanner/FluentScanner/FluentWithExamples.FluentCanBeUsedWithExamples.approved.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ Scenario: Fluent can be used with examples
55
Given a different method with random arg 2
66
Given a different method with <Prop2>
77
When method using <example string>
8+
And I use a <Multi word heading>
89
Then all is good
910

1011
Examples:
11-
| Prop 1 | Prop2 | Prop 3 |
12-
| 1 | foo | ConsecutiveAssertion |
13-
| 2 | bar | Initialize |
12+
| Prop 1 | Prop2 | Prop 3 | Multi word heading |
13+
| 1 | foo | ConsecutiveAssertion | |
14+
| 2 | bar | Initialize | val2 |
1415

TestStack.BDDfy.Tests/Scanner/FluentScanner/FluentWithExamples.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ public void FluentCanBeUsedWithExamples()
1717
.And(_ => GivenADifferentMethodWithRandomArg(2))
1818
.And(_ => GivenADifferentMethodWith(_prop2))
1919
.When(_ => WhenMethodUsing__ExampleString__())
20+
.When(_ => AndIUseA(multiWordHeading))
2021
.Then(_ => ThenAllIsGood())
21-
.WithExamples(new ExampleTable("Prop 1", "Prop2", "Prop 3")
22+
.WithExamples(new ExampleTable("Prop 1", "Prop2", "Prop 3", "Multi word heading")
2223
{
23-
{1, "foo", ExecutionOrder.ConsecutiveAssertion },
24-
{2, "bar", ExecutionOrder.Initialize }
24+
{1, "foo", ExecutionOrder.ConsecutiveAssertion, "" },
25+
{2, "bar", ExecutionOrder.Initialize, "val2" }
2526
})
2627
.BDDfy();
2728

@@ -30,6 +31,12 @@ public void FluentCanBeUsedWithExamples()
3031
Approvals.Verify(textReporter.ToString());
3132
}
3233

34+
private void AndIUseA(string multiWordHeading)
35+
{
36+
multiWordHeading.ShouldBeOneOf("", "val2");
37+
this.multiWordHeading.ShouldBeOneOf("", "val2");
38+
}
39+
3340
private void GivenADifferentMethodWith(string prop2)
3441
{
3542
_prop2.ShouldBeOneOf("foo", "bar");
@@ -58,6 +65,7 @@ private void GivenMethodTaking__ExampleInt__(int exampleInt)
5865

5966
public int Prop1 { get; set; }
6067
private string _prop2 = null;
68+
private string multiWordHeading = null;
6169
public ExecutionOrder Prop_3 { get; set; }
6270
}
6371
}

TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static ExampleTable Parse(string table)
8181

8282
static object[] GetValues(string row)
8383
{
84-
return row.Split('|').Select(h => (object)h.Trim()).ToArray();
84+
return row.Split('|').Select(h => h.Trim()).Select(s=>string.IsNullOrEmpty(s) ? null : (object)s).ToArray();
8585
}
8686

8787
public static bool HeaderMatches(string header, string name)

TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ public int Row
3232
public object GetValue(Type targetType)
3333
{
3434
var stringValue = _underlyingValue as string;
35-
if (_underlyingValue == null || (_underlyingValue is string && string.IsNullOrEmpty(stringValue)))
35+
if (_underlyingValue == null)
3636
{
37-
if (targetType.IsValueType &&
38-
!(targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof (Nullable<>)))
37+
if (targetType.IsValueType && !(targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof (Nullable<>)))
3938
{
4039
var valueAsString = string.IsNullOrEmpty(stringValue) ? "<null>" : string.Format("\"{0}\"", _underlyingValue);
4140
throw new ArgumentException(string.Format("Cannot convert {0} to {1} (Column: '{2}', Row: {3})", valueAsString, targetType.Name, Header, Row));

0 commit comments

Comments
 (0)