1

Using tables in Fancordion v1.0.4, how can I use the row index in a column command to validate its value.

For example if my Fixture is:

class MyFixture : FixtureTest {

    [Str:Obj?][] getCountries() {
         return [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UK", "name":"United Kingdom"]]
    }
}

And the spec is:

table:
col[0]+verifyEq:getCountries[#ROW]["code"]
col[1]+verifyEq:getCountries[#ROW]["name"]

Country Code    Country Name
------------    ------------
AU              Australia
NZ              New Zealand
UK              United Kingdom

What should I use instead of the #ROW placeholder in the specification example above?

Is there a better way to write this specification and fixture? e.g. is it better to create a method in the fixture to retrieve each individual map in the list instead of the full list?

haraman
  • 2,644
  • 2
  • 23
  • 45
LightDye
  • 1,174
  • 8
  • 14
  • The `#ROW` macro has been added in this [commit](https://bitbucket.org/AlienFactory/affancordion/commits/0db1fde7fbca6d6c9d5accc43079b9101bdaed8b) - thanks for the idea! – Steve Eynon Dec 14 '15 at 16:02
  • Thank you for adding it. It can be quite useful. – LightDye Dec 15 '15 at 02:53

1 Answers1

1

As you noted there is no #ROW macro (but it may be a nice addition!) so currently you'll need to change either the assertions, or the data structure.

Change the assertions:

Here we change the assertions slightly and introduce our own row field that gets incremented at the end of every row iteration:

**  Hi!
** 
**   table:
**   col[0]+verifyEq:getCountries[#FIXTURE.row]["code"]
**   col[1]+verifyEq:getCountries[#FIXTURE.row]["name"]
**   row+exe:row++
**
**   Country Code    Country Name
**   ------------    ------------
**   AU              Australia
**   NZ              New Zealand
**   UK              United Kingdom
** 
class CountryTest : FixtureTest {
    Int row := 0

    [Str:Obj?][] getCountries() {
         return [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UK", "name":"United Kingdom"]]
    }
}

Change the data structure:

A better way would probably be to change the data being tested into a list of lists. For that has the added advantage of failing when the test data is too much or too little.

**  Hi!
** 
**   table:
**   verifyRows:getCountries()
**
**   Country Code    Country Name
**   ------------    ------------
**   AU              Australia
**   NZ              New Zealand
**   UK              United Kingdom
** 
class CountryTest : FixtureTest {

    Str[][] getCountries() {
        countries := [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UKs", "name":"United Kingdom"]]
        return countries.map { it.vals }
    }
}
Steve Eynon
  • 4,308
  • 1
  • 23
  • 44