Skip to content

Commit

Permalink
Changed table diff response to use diff bang.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlawrence committed May 2, 2010
1 parent 71a7d0e commit 661fee5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
6 changes: 1 addition & 5 deletions Cuke4Nuke/Core/Processor.cs
Expand Up @@ -76,10 +76,6 @@ public string Process(string request)
} }
} }
return Invoke(requestObject[1]["id"].Value<string>(), args); return Invoke(requestObject[1]["id"].Value<string>(), args);
case "diff_ok":
return SuccessResponse();
case "diff_failed":
return FailResponse("Tables don't match.");
default: default:
return FailResponse("Invalid request '" + request + "'"); return FailResponse("Invalid request '" + request + "'");
} }
Expand Down Expand Up @@ -223,7 +219,7 @@ private string TableDiffResponse(Table expectedTable, Table actualTable)
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Table)); TypeConverter converter = TypeDescriptor.GetConverter(typeof(Table));
string expectedTableJson = (string)converter.ConvertToString(expectedTable); string expectedTableJson = (string)converter.ConvertToString(expectedTable);
string actualTableJson = (string)converter.ConvertToString(actualTable); 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) StepDefinition GetStepDefinition(string id)
Expand Down
38 changes: 34 additions & 4 deletions Cuke4Nuke/Specifications/Core/Processor_Specification.cs
Expand Up @@ -23,7 +23,8 @@ public class Processor_Specification
StepDefinition _stepDefinitionWithOneIntParameter; StepDefinition _stepDefinitionWithOneIntParameter;
StepDefinition _stepDefinitionWithOneDoubleParameter; StepDefinition _stepDefinitionWithOneDoubleParameter;
StepDefinition _stepDefinitionWithIntDoubleAndStringParameters; StepDefinition _stepDefinitionWithIntDoubleAndStringParameters;
StepDefinition _pendingStepDefinition; StepDefinition _pendingStepDefinition;
private StepDefinition _stepDefinitionWithTableDiff;


List<StepDefinition> _stepDefinitions; List<StepDefinition> _stepDefinitions;


Expand All @@ -43,7 +44,8 @@ public void SetUp()
_stepDefinitionWithOneIntParameter = new StepDefinition(GetType().GetMethod("OneIntParameter")); _stepDefinitionWithOneIntParameter = new StepDefinition(GetType().GetMethod("OneIntParameter"));
_stepDefinitionWithOneDoubleParameter = new StepDefinition(GetType().GetMethod("OneDoubleParameter")); _stepDefinitionWithOneDoubleParameter = new StepDefinition(GetType().GetMethod("OneDoubleParameter"));
_stepDefinitionWithIntDoubleAndStringParameters = new StepDefinition(GetType().GetMethod("IntDoubleAndStringParameters")); _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> { _stepDefinitions = new List<StepDefinition> {
_stepDefinition, _stepDefinition,
Expand All @@ -54,7 +56,8 @@ public void SetUp()
_stepDefinitionWithOneIntParameter, _stepDefinitionWithOneIntParameter,
_stepDefinitionWithOneDoubleParameter, _stepDefinitionWithOneDoubleParameter,
_stepDefinitionWithIntDoubleAndStringParameters, _stepDefinitionWithIntDoubleAndStringParameters,
_pendingStepDefinition _pendingStepDefinition,
_stepDefinitionWithTableDiff
}; };
var loader = new MockLoader(_stepDefinitions); var loader = new MockLoader(_stepDefinitions);
var objectFactory = new ObjectFactory(); var objectFactory = new ObjectFactory();
Expand Down Expand Up @@ -245,6 +248,15 @@ public void Invoke_of_pending_step_definition_should_return_pending_response()
AssertPendingResponse(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) static string CreateInvokeRequest(string id, params string[] invokeArgs)
{ {
JsonData req = new JsonData(); JsonData req = new JsonData();
Expand Down Expand Up @@ -286,7 +298,14 @@ static void AssertFailResponse(string response, string message , Type exceptionT
Assert.That(jsonData[0].ToString(), Is.EqualTo("fail")); Assert.That(jsonData[0].ToString(), Is.EqualTo("fail"));
JsonAssert.HasString(jsonData[1], "message", message); JsonAssert.HasString(jsonData[1], "message", message);
JsonAssert.HasString(jsonData[1], "backtrace"); 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")] [Given("check method called")]
Expand Down Expand Up @@ -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 class MockLoader : Loader
{ {
internal List<StepDefinition> StepDefinitions { get; private set; } internal List<StepDefinition> StepDefinitions { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -2,6 +2,7 @@
=== Features === Features
* Internationalized Given/When/Then attributes * Internationalized Given/When/Then attributes
* Debug rather than Release binaries to support step definition debugging * 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 === Bugs Fixed


Expand Down

0 comments on commit 661fee5

Please sign in to comment.