Topic: Dry Cucumber step def

i find myself doing allot of

i fill the XXXX form properly
and
i fill the xxx with missing field

When /^I fill in the Staff form properly$/ do
  @staff_f = Fabricate(:staff)
  fill_in('staff_first_name', :with =>@staff_f.first_name)
  fill_in('staff_last_name', :with => @staff_f.last_name)
end

When /^I fill in the location form with out a last name$/ do
  @staff_f = Fabricate(:staff)
  fill_in('staff_first_name', :with =>@staff_f.first_name)
  fill_in('staff_last_name', :with => "")
end

but how can i call the I fill in the Staff form properly
and then i remove the last name

Thanks

Re: Dry Cucumber step def

You should use "Given I fill out the Staff form properly" instead of "When I fill in the Staff form properly"  Your specifying the state of the page, not indicating that an event has occurred.

Here's how I'd write the feature file:

Given I fill out the Staff form properly
When I click submit
Then I should see something

Given I fill out the Staff form properly
But I leave the last name blank
When I click submit
Then I should see error message

Here's the two Given steps:

Given /^I fill out the Staff form properly$/ do
  @staff_f = Fabricate(:staff)
  fill_in('staff_first_name', :with =>@staff_f.first_name)
  fill_in('staff_last_name', :with => @staff_f.last_name)
end

Given /^I leave the last name blank$/ do
  fill_in('staff_last_name', :with => "")
end

Check out: stackoverflow - reuse cucumber steps