Skip to content

Instantly share code, notes, and snippets.

@xlson
Created July 14, 2017 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlson/dd970f2588f3344011f36ddb31450828 to your computer and use it in GitHub Desktop.
Save xlson/dd970f2588f3344011f36ddb31450828 to your computer and use it in GitHub Desktop.
Example of removing blanks in columnNames
import spock.lang.Specification
class ColumnFixesSpec extends Specification {
def csvData = """Name,Last Name,Age
Leonard,Gram,33"""
def "Removing all blanks from columnNames to make them easier to parse"() {
setup:
def columnNames = CsvParser.parseCsv(csvData).next().columns.collect { it.key.toString().replaceAll(' ','') }
def csv = CsvParser.parseCsv(csvData, columnNames:columnNames)
def line = csv.next()
expect:
line.Name == 'Leonard'
line.LastName == 'Gram'
line.Age == '33'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment