Tuesday, November 3, 2009

Nested Step Definitions: Passing Table as Arg

From within a step definition, it is possible to pass a table to another step using the following technique:
1
2
3
4
5
6
7
8
Given /^I have just entered the results for "([^\"]*)"$/ do |identifier|
Given %\I follow "Enter Results" for "#{identifier}"\
And %\I enter the following class test results:\, table(%\
| # | Name | Score|
| 1 | John Tan | 99.0 |
| 2 | John Hoo | 80.0 |
\
)
end

Here's the step definition that does processing of the table (nothing unusual actually):
1
2
3
4
5
Given /^I enter the following class test results:$/ do |table|
table.hashes.each do |hash|
# blah blah
end
end

Sweet :]

No comments:

Post a Comment

Labels