Cucumber and general Ruby question

Hello,

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? end

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? } end

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

Thanks.

you could use tables

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

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