Created
September 6, 2012 14:58
-
-
Save danilat/3657079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaunchRockService { | |
def emails | |
def getEmailsFromCSV(csv) { | |
def emails = [] | |
def lines = csv.split('\n') | |
lines.each{ | |
def email = it.split(',')[1] | |
emails << email.replaceAll('"','') | |
} | |
return emails | |
} | |
def getEmailsFromFile(file){ | |
def lines = file.text.split('\n') | |
def total = lines.size()-1 | |
lines = lines[1..total] | |
emails = getEmailsFromCSV(lines.join('\n')) | |
} | |
def emailIsForBeta(email){ | |
return emails.contains(email) | |
} | |
} | |
//----- Spock Spec | |
class LaunchRockServiceSpec extends spock.lang.Specification { | |
def launchRockService | |
def void setup() { | |
launchRockService = new LaunchRockService() | |
} | |
def "Emails are extracted from the LaunchRock CSV string"() { | |
setup: | |
def csv = """ "2012-03-01 19:23:45","[email protected]","beta.minchador.com","0","0","","http://minchador.com?lrRef=WP7Zn" | |
"2012-02-27 15:00:28","[email protected]","beta.minchador.com","2","0","","http://minchador.com?lrRef=Rm7gT" | |
"2012-02-27 13:04:05","[email protected]","beta.minchador.com","6","0","","http://minchador.com?lrRef=JT9QG" """ | |
when: | |
def emails = launchRockService.getEmailsFromCSV(csv) | |
then: | |
emails != null | |
emails.size() == 3 | |
true == emails.contains("[email protected]") | |
} | |
def "Emails are extracted from the LaunchRock CSV file" (){ | |
setup: | |
def file = new File("csv/launchrock_export.csv") | |
when: | |
launchRockService.getEmailsFromFile(file) | |
then: | |
launchRockService.emails != null | |
launchRockService.emails.size() == 74 | |
true == launchRockService.emails.contains("[email protected]") | |
} | |
def "Emails exists if is in the CSV" (){ | |
setup: | |
def file = new File("csv/launchrock_export.csv") | |
launchRockService.getEmailsFromFile(file) | |
when: | |
def response = launchRockService.emailIsForBeta("[email protected]") | |
then: | |
response == true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment