Skip to content

Commit

Permalink
adds step table support
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunc committed Apr 24, 2016
1 parent d84ee1e commit 908bebe
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions cucumber.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 13 additions & 4 deletions cucumber/feature.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions cucumber/runner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import strutils
import options
import nre
import sequtils
import tables
import "./types"
import "./feature"
import "./parameter"
Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion cucumber/step.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions tests/features/parse_gherkin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 |

0 comments on commit 908bebe

Please sign in to comment.