diff --git a/cucumber.nim b/cucumber.nim index 9a0a366..7f6c5d2 100644 --- a/cucumber.nim +++ b/cucumber.nim @@ -28,3 +28,4 @@ export typeinfo.Any, toAny export tables.`[]`, tables.`[]=` #export parameter.DeclareRefParamType, parameter.DeclareParamType #export parameter.parseInt, parameter.parseBool, parameter.parseString +export parameter diff --git a/cucumber/feature.nim b/cucumber/feature.nim index 9c442c6..ff4063b 100644 --- a/cucumber/feature.nim +++ b/cucumber/feature.nim @@ -154,7 +154,7 @@ proc readScenario( feature: Feature, stream: var LineStream, head: Line ) : Scenario proc readExamples( - scenario: Scenario, stream: var LineStream, indent: int + scenario: Scenario, stream: var LineStream, indent: int, step: Step = nil ) : void proc readBlock(step: Step, stream: var LineStream, indent: int): void @@ -351,8 +351,14 @@ proc readScenario( of ltBody: if line.content == "\"\"\"": if result.steps.len == 0: - raise newSyntaxError(line, "multiline block must follow step") + raise newSyntaxError(line, "Multiline block must follow step.") result.steps[^1].readBlock(stream, line.indent) + elif line.content[0] == '|': + stream.pushback line + if result.steps.len == 0: + raise newSyntaxError(line, "Step table must follow step.") + let lastStep = result.steps[^1] + result.readExamples(stream, line.indent, lastStep) else: addStep(result, result.steps, line) of ltComment: @@ -372,13 +378,16 @@ proc readBlock(step: Step, stream: var LineStream, indent: int) : void = content.add(repeat(" ", max(0, line.indent - indent)) & line.content & "\n") proc readExamples( - scenario: Scenario, stream: var LineStream, indent: int + scenario: Scenario, stream: var LineStream, indent: int, step: Step = nil ) : void = let result = Examples( parent: scenario, columns : @[], values: @[]) - scenario.examples.add result + if step == nil: + scenario.examples.add result + else: + step.table = result while true: let line = stream.nextLine if line.ltype != ltBody: diff --git a/cucumber/runner.nim b/cucumber/runner.nim index 5242fa8..184a93f 100644 --- a/cucumber/runner.nim +++ b/cucumber/runner.nim @@ -6,6 +6,7 @@ import strutils import options import nre import sequtils +import tables import "./types" import "./feature" import "./parameter" @@ -344,9 +345,13 @@ proc runHooks( result.exception = exc break -#TODO proc fillTable(sd: StepDefinition, stepTable: Examples): void = - discard + if stepTable == nil: + return + for icol, colName in stepTable.columns: + let setter = sd.columns[colName] + for row in stepTable.values: + setter(row[icol]) when isMainModule: diff --git a/cucumber/step.nim b/cucumber/step.nim index c7c99f3..8a6b379 100644 --- a/cucumber/step.nim +++ b/cucumber/step.nim @@ -24,7 +24,7 @@ type stepRE*: Regex defn*: proc(stepArgs: StepArgs) : StepResult blockParamName*: string - columns: TableRef[string, ColumnSetter] + columns*: TableRef[string, ColumnSetter] StepDefinition* = ref StepDefinitionObj StepDefinitionsObj* = object diff --git a/readme.rst b/readme.rst index 4494cd6..b6be642 100644 --- a/readme.rst +++ b/readme.rst @@ -72,10 +72,7 @@ set of rows used. 4. Background sections may have examples. If they do, all the scenarios of the feature are run for each example row. -5. Tables may be specified for steps, but step definitions currently can not -access them. (TODO!) - -6. The special tag "@skip" can be used to specify features and/or scenarios +5. The special tag "@skip" can be used to specify features and/or scenarios which are skipped by default. .. _step definitions: @@ -147,7 +144,7 @@ step text. Allowed values are: Such arguments must currently have type string. * ``column``: The argument is a sequence of values taken from a column - of a table specified by the step. Currently this is unsupported. + of a table specified by the step. Context arguments (``global``, ``feature`` or ``scenario``- qualified) may optionally include the ``var`` keyword. If they do, the variable is diff --git a/tests/features/parse_gherkin.feature b/tests/features/parse_gherkin.feature index 34648f6..0cef8ae 100644 --- a/tests/features/parse_gherkin.feature +++ b/tests/features/parse_gherkin.feature @@ -307,7 +307,7 @@ Scenario: A feature may have a tag. """ Then the feature has tag "@tag1" -Scenario: A feature may have multiple tag. +Scenario: A feature may have multiple tags. When I read the feature file: """ @tag1 @tag2 @tag3 @@ -334,7 +334,7 @@ Scenario: A scenario may have a tag. """ Then scenario 0 has tag "@tag1" -Scenario: A scenario may have multiple tag. +Scenario: A scenario may have multiple tags. When I read the feature file: """ Feature: parse gherkin @@ -373,11 +373,6 @@ Scenario: Feature and scenarios may all have multiple tags Then scenario 0 has tags "@tag1 @tag2 @tag3" Then scenario 1 has tags "@tag4 @tag5" -# A feature may have a tag -# A feature may have multple tags -# A feature may have tags specified on multiple lines -# A scenario may have a tag -# A scenario may have multiple tags # A feature file may contain comments # Comments before feature are associated with the feature # comments before scenario are associated with the scenario @@ -388,3 +383,19 @@ Scenario: Feature and scenarios may all have multiple tags # tables in steps +@check +Scenario: A step may define a table + When I read the feature file: + """ + Feature: parse gherkin + + Scenario: somesuch + Given a table: + | a | b | + | 1 | 2 | + | 3 | 3 | + """ + Then step 0 of scenario 0 has table with 2 rows and columns: + | name | + | a | + | b |