Cucumber and general Ruby question


I have this cucumber step definition:

Given /^the site has pages “(.+)” and “(.+)”$/ do | page_1, page_2 |
Page.create :title => page_1 if Page.find_by_title(page_1).nil?
Page.create :title => page_2 if Page.find_by_title(page_2).nil?

This works, but obviously I would like to DRY it up. I was thinking along the lines.

Given /^the site has pages “(.+)” and “(.+)”$/ do | *args |
args.each { |page| Page.create :title => page if Page.find_by_title(page).nil? }

The code is not syntactically correct that is what my question is about: how to implement this concept right?


you could use tables

   Given the site has the following pages
        >page title|
        > title 1 |
        > title 2 |
        > title 3 |

Given /^the site has the following pages$/ do | pages |
    pages.each |page_title|
      Page.create :title => page_title unless Page.find_by_title