What is the syntax for calling multiline steps from other steps? I''d like to do something like this: Given /^I have filled in the form$/ do |details| details.hashes.each |pair| When "I fill in #{pair[''field'']} with #{pair[''value'']}" end end Given /^(.*) has filled in the form$/ do |user, details| Given "I am logged in and #{user}" Given "I have filled in the form", details When "I log out" end My feature file would have something like this: Given Joe has filled in the form: | field | value | | x | 1 | | y | 2 | I''d also like to do something like this: Given /^Everything is filled in$/ do Given "Joe has filled in the form: | field | value | | x | 1 | | y | 2 |" end How can I do this? Also, how does it work for multi line strings (""")? Thanks! Paul P.S. Those are contrived examples. -- Posted via http://www.ruby-forum.com/.
Pau Cor wrote:> What is the syntax for calling multiline steps from other steps? I''d > like to do something like this: > > Given /^I have filled in the form$/ do |details| > details.hashes.each |pair| > When "I fill in #{pair[''field'']} with #{pair[''value'']}" > end > end > >Yes, you can do this.> Given /^(.*) has filled in the form$/ do |user, details| > Given "I am logged in and #{user}" > Given "I have filled in the form", details > When "I log out" > end > My feature file would have something like this: > > Given Joe has filled in the form: > | field | value | > | x | 1 | > | y | 2 | > > > I''d also like to do something like this: > > Given /^Everything is filled in$/ do > Given "Joe has filled in the form: > | field | value | > | x | 1 | > | y | 2 |" > end > >I''m not sure if it works with step tables, so you will just have to experiment and see. Same thing for the multi-line strings.. I''m not sure but that seems more possible that the step table.> How can I do this? Also, how does it work for multi line strings (""")? > > Thanks! > Paul > > P.S. Those are contrived examples. >
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/.
Andrew Premdas
2008-Dec-05 06:29 UTC
[rspec-users] calling multiline steps from other steps
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 However 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 tryGiven /^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 idea. ---- 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'') end When I fill in signup details for fred HTH Andrew 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>
Andrew Premdas wrote:> 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 > > However > > 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. ><snip>> > 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 idea. >Actually, you can embed tables in steps, they are called "Step Tables". :) Read about them here: http://github.com/aslakhellesoy/cucumber/wikis/using-fit-tables-in-a-feature I have used them many times and I find them very handy. I had rolled my own with story runner and so having it built into cucumber makes things very nice. -Ben
Aslak Hellesøy
2008-Dec-05 07:22 UTC
[rspec-users] calling multiline steps from other steps
> 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? >Not possible yet. Please file a ticket.> Paul > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Aslak Hellesøy
2008-Dec-05 07:24 UTC
[rspec-users] calling multiline steps from other steps
And please link to this thread in the ticket. Nabble or somesuch.> 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
Andrew Premdas
2008-Dec-05 10:44 UTC
[rspec-users] calling multiline steps from other steps
Ooh interesting stuff thanks for that Ben, never got past the scenario tables until now :) Andrew 2008/12/5 Ben Mabey <ben at benmabey.com>> Andrew Premdas wrote: > >> 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 >> >> However >> >> 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. >> >> <snip> > >> >> 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 >> idea. >> >> > Actually, you can embed tables in steps, they are called "Step Tables". :) > Read about them here: > > http://github.com/aslakhellesoy/cucumber/wikis/using-fit-tables-in-a-feature > > I have used them many times and I find them very handy. I had rolled my > own with story runner and so having it built into cucumber makes things very > nice. > > -Ben > > > _______________________________________________ > 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/4a0e630f/attachment.html>
Aslak Helles?y wrote:> And please link to this thread in the ticket. Nabble or somesuch.I am sorry for taking so long to post the ticket: http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/144-call-multiline-steps-from-other-steps -- Posted via http://www.ruby-forum.com/.