Skip to content

Commit

Permalink
Fix custom comparator in scenario tables. Fixes unclebob#399.
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Feb 10, 2014
1 parent 49a5f0b commit df7e630
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You can define a custom comparator in the plugins.properties file. This

| scenario | test in scenario |
| check | echo | test | glob:t*t |

| script | echo fixture |
| check | echo | test | glob:t*t |
| test in scenario |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
5 changes: 5 additions & 0 deletions plugins.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ RecentChanges=fitnesse.wiki.fs.GitFileVersionsController
# Define custom test systems. Test systems are created through a factory.
#TestSystems=example:fitnesse.testsystems.example.EchoTestSystemFactory

##
# Custom comparators
#
# Match test output in ways not foreseen.
CustomComparators=glob:fitnesse.testsystems.slim.GlobComparator
4 changes: 3 additions & 1 deletion src/fitnesse/testsystems/slim/tables/ScenarioTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public String substitute(String content) throws SyntaxError {
}

protected ScriptTable createChild(ScenarioTestContext testContext, Table newTable) {
return new ScriptTable(newTable, id, testContext);
ScriptTable scriptTable = new ScriptTable(newTable, id, testContext);
scriptTable.setCustomComparatorRegistry(customComparatorRegistry);
return scriptTable;
}

public List<SlimAssertion> call(String[] args, ScriptTable parentTable, int row) throws SyntaxError {
Expand Down
2 changes: 2 additions & 0 deletions src/fitnesse/testsystems/slim/tables/ScriptTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ private List<SlimAssertion> assertionsFromScenario(int row) throws SyntaxError {
ScenarioTable scenario = getTestContext().getScenario(Disgracer.disgraceClassName(actionName));
List<SlimAssertion> assertions = new ArrayList<SlimAssertion>();
if (scenario != null) {
scenario.setCustomComparatorRegistry(customComparatorRegistry);
String[] args = getArgumentsStartingAt(1, lastCol, row, assertions);
assertions.addAll(scenario.call(args, this, row));
} else if (lastCol == 0) {
String firstNameCell = table.getCellContents(0, row);
for (ScenarioTable s : getScenariosWithMostArgumentsFirst()) {
s.setCustomComparatorRegistry(customComparatorRegistry);
String[] args = s.matchParameters(firstNameCell);
if (args != null) {
assertions.addAll(s.call(args, this, row));
Expand Down
5 changes: 2 additions & 3 deletions src/fitnesse/testsystems/slim/tables/SlimTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class SlimTable {

protected final Table table;
protected String id;
private CustomComparatorRegistry customComparatorRegistry;
protected CustomComparatorRegistry customComparatorRegistry;

public SlimTable(Table table, String id, SlimTestContext testContext) {
this.id = id;
Expand Down Expand Up @@ -109,8 +109,7 @@ protected SlimAssertion constructFixture(String fixtureName) {
protected String getFixtureName() {
String tableHeader = table.getCellContents(0, 0);
String fixtureName = getFixtureName(tableHeader);
String disgracedFixtureName = Disgracer.disgraceClassName(fixtureName);
return disgracedFixtureName;
return Disgracer.disgraceClassName(fixtureName);
}

protected String getFixtureName(String tableHeader) {
Expand Down

0 comments on commit df7e630

Please sign in to comment.