Permalink
Browse files

Changed table diff response to use diff bang.

  • Loading branch information...
1 parent 71a7d0e commit 661fee5f50bfc92e07245ff240f1f7a2227aad55 @richardlawrence committed May 2, 2010
Showing with 36 additions and 9 deletions.
  1. +1 −5 Cuke4Nuke/Core/Processor.cs
  2. +34 −4 Cuke4Nuke/Specifications/Core/Processor_Specification.cs
  3. +1 −0 History.txt
@@ -76,10 +76,6 @@ public string Process(string request)
}
}
return Invoke(requestObject[1]["id"].Value<string>(), args);
- case "diff_ok":
- return SuccessResponse();
- case "diff_failed":
- return FailResponse("Tables don't match.");
default:
return FailResponse("Invalid request '" + request + "'");
}
@@ -223,7 +219,7 @@ private string TableDiffResponse(Table expectedTable, Table actualTable)
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Table));
string expectedTableJson = (string)converter.ConvertToString(expectedTable);
string actualTableJson = (string)converter.ConvertToString(actualTable);
- return String.Format("[\"diff\", [{0},{1}]]", expectedTableJson, actualTableJson);
+ return String.Format("[\"diff!\", [{0},{1}]]", expectedTableJson, actualTableJson);
}
StepDefinition GetStepDefinition(string id)
@@ -23,7 +23,8 @@ public class Processor_Specification
StepDefinition _stepDefinitionWithOneIntParameter;
StepDefinition _stepDefinitionWithOneDoubleParameter;
StepDefinition _stepDefinitionWithIntDoubleAndStringParameters;
- StepDefinition _pendingStepDefinition;
+ StepDefinition _pendingStepDefinition;
+ private StepDefinition _stepDefinitionWithTableDiff;
List<StepDefinition> _stepDefinitions;
@@ -43,7 +44,8 @@ public void SetUp()
_stepDefinitionWithOneIntParameter = new StepDefinition(GetType().GetMethod("OneIntParameter"));
_stepDefinitionWithOneDoubleParameter = new StepDefinition(GetType().GetMethod("OneDoubleParameter"));
_stepDefinitionWithIntDoubleAndStringParameters = new StepDefinition(GetType().GetMethod("IntDoubleAndStringParameters"));
- _pendingStepDefinition = new StepDefinition(GetType().GetMethod("Pending"));
+ _pendingStepDefinition = new StepDefinition(GetType().GetMethod("Pending"));
+ _stepDefinitionWithTableDiff = new StepDefinition(GetType().GetMethod("TableDiff"));
_stepDefinitions = new List<StepDefinition> {
_stepDefinition,
@@ -54,7 +56,8 @@ public void SetUp()
_stepDefinitionWithOneIntParameter,
_stepDefinitionWithOneDoubleParameter,
_stepDefinitionWithIntDoubleAndStringParameters,
- _pendingStepDefinition
+ _pendingStepDefinition,
+ _stepDefinitionWithTableDiff
};
var loader = new MockLoader(_stepDefinitions);
var objectFactory = new ObjectFactory();
@@ -245,6 +248,15 @@ public void Invoke_of_pending_step_definition_should_return_pending_response()
AssertPendingResponse(response);
}
+ [Test]
+ public void Invoke_of_step_definition_with_table_diff_should_return_diff_bang_response()
+ {
+ var request = CreateInvokeRequest(_stepDefinitionWithTableDiff.Id);
+ var response = _processor.Process(request);
+
+ AssertDiffBangResponse(response);
+ }
+
static string CreateInvokeRequest(string id, params string[] invokeArgs)
{
JsonData req = new JsonData();
@@ -286,7 +298,14 @@ static void AssertFailResponse(string response, string message , Type exceptionT
Assert.That(jsonData[0].ToString(), Is.EqualTo("fail"));
JsonAssert.HasString(jsonData[1], "message", message);
JsonAssert.HasString(jsonData[1], "backtrace");
- JsonAssert.HasString(jsonData[1], "exception", exceptionType.ToString());
+ JsonAssert.HasString(jsonData[1], "exception", exceptionType.ToString());
+ }
+
+ static void AssertDiffBangResponse(string response)
+ {
+ var jsonData = JsonMapper.ToObject(response);
+ JsonAssert.IsArray(jsonData);
+ Assert.That(jsonData[0].ToString(), Is.EqualTo("diff!"));
}
[Given("check method called")]
@@ -342,6 +361,17 @@ public static void Pending()
{
}
+ [Given("^a step with a table diff call$")]
+ public static void TableDiff()
+ {
+ Table table1 = new Table();
+ table1.Data.Add(new List<string> { "foo", "bar" });
+ Table table2 = new Table();
+ table1.Data.Add(new List<string> { "foo", "baz" });
+
+ table1.AssertSameAs(table2);
+ }
+
class MockLoader : Loader
{
internal List<StepDefinition> StepDefinitions { get; private set; }
View
@@ -2,6 +2,7 @@
=== Features
* Internationalized Given/When/Then attributes
* Debug rather than Release binaries to support step definition debugging
+* Table diff response changed to diff! to allow Cucumber to format table diff output
=== Bugs Fixed

0 comments on commit 661fee5

Please sign in to comment.