Took me a while, but I solved this eventually. Thanks to all for the above answers. Here are the feature file, step definitions and methods I used to work it out.
Feature: try and work out a simple version of the f2d pages that could be used for all
Scenario Outline: first go
Given I set up an object for these things
| page_1 | page_2 |
| <page_1> | <page_2> |
Then I create objects and output two things for one
Examples:
| page_1 | page_2 |
| elephants | scary pants |
Step Definitions:
Given(/^I set up an object for these things$/) do |table|
set_up_a_hash_from_a_table(table)
end
Then(/^I create objects and output two things for one$/) do
do_something_with_a_hash
end
Methods:
def set_up_a_hash_from_a_table(table)
@objects = Hash.new
@summary = Array.new
data = table.hashes
data.each do |field_data|
@objects['page_1'] = field_data['page_1']
@objects['page_2'] = field_data['page_2']
end
end
def do_something_with_a_hash
show_me_page_1
show_me_page_2
puts "Summary is #{@summary}"
end
def show_me_page_1
do_stuff_for_a_page('page_1')
end
def show_me_page_2
do_stuff_for_a_page('page_2')
end
def do_stuff_for_a_page(my_object)
puts "key is #{my_object} and value is #{@objects[my_object]}"
@summary.push("#{my_object} - #{@objects[my_object]}")
end
Result:
#=> key is page_1 and value is elephants
#=> key is page_2 and value is scary pants
#=> Summary is ["page_1 - elephants", "page_2 - scary pants"]