[rspec-users] calling multiline steps from other steps

Andrew Premdas apremdas at gmail.com
Fri Dec 5 01:29:40 EST 2008

Given /^I have filled in the form$/ do |details|
 details.hashes.each |pair|

Can't see this working because you've got no place to collect details


Given /^I have filled in the form with (.*)$/ do |details|
 details.hashes.each |pair|

would work, but you'd have to do some tricky stuff to get your hash out.


 Given Joe has filled in the form:
   | field | value |
   | x     | 1     |
   | y     | 2     |

For this to work the step that matches has to collect two thing so really
you need

 Given Joe has filled in foo with bar
   | field | value |
   | x     | 1     |
   | y     | 2     |

and a matcher

Given /^Joe has filled in (.*) with (.*)$/ do |field, value|

>From that you could try

Given /^Form filled in correctly$/
  Given "Joe has filled in foo with bar"
     | field | value |
     | x     | 1     |
     |   y   | 2     |

but I doubt that would work as I think you need the "More Examples:"
statement. Also don't think embedding tables in step definitions is a good


You could use convention over configuration to do more filling in with less
variables. For example I fill in user forms using just the login name to
generate the other fields

e.g. login - fred, password - fredpass, email fred at example.com  etc.

Now a step can take one parameter fred and fill in many details

e.g. using webrat

When /^I fill in signup details for (.*) $/ do |user|
  fill_in(:login, :with => user)
  fill_in(:email, :with => user + '@example.com')
  fill_in(:password, :with => user + 'pass')
  fill_in('user[password_confirmation]', :with => user + 'pass')

When I fill in signup details for fred



2008/12/5 Pau Cor <lists at ruby-forum.com>

> Ben Mabey wrote:
> > you will just have to
> > experiment and see.
> Thanks for the reply!
> So far all my experiments have failed :/
> Anyone else have any ideas?
> Paul
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081205/49ade77e/attachment.html>

More information about the rspec-users mailing list