[Rails] step with several optional params

49 views
Skip to first unread message

Me

unread,
Feb 27, 2011, 8:11:50 PM2/27/11
to cu...@googlegroups.com
I wan to say either:

1. Then I see my dashboard or


2. Then I see my dashboard with 1 works
 or Then I see my dashboard with 1 works, 2 open submissions

Is this correct?

Then /^I should see my dashboard with? (?:"([^"]*)" favorite publishers,)(?:"([^"]*)" open submissions,)(?:"([^"]*)" total submissions) and? (?:"([^"]*)" works?)$/ do |favorite_pubs,open_sub,total_sub,works|
  #Then %{show me the page}
  Then %{I should see "Favorite Publishers"#{favorite_pubs}}
  Then %{I should see "Open Submissions"}
  Then %{I should see "Total Submissions"}
  Then %{I should see "Total Works"#{works}}
end

Craig Demyanovich

unread,
Feb 27, 2011, 8:36:28 PM2/27/11
to cu...@googlegroups.com, Me
Just run it and see if it works. :-)

Alternatively, you could separate this into 3 steps like so:

Then 'I see my dashboard' do
...
end

Then 'I see my dashboard with $count works' do |count|
...
end

Then 'I see my dashboard with $works_count works, $open_submissions_count open submissions' do |works_count, open_submissions_count|
...
end

Separate steps, with regular expressions or strings, can be much simpler than one step with lots of optional captures in its regex.


Regards,
Craig

Me

unread,
Feb 27, 2011, 9:34:07 PM2/27/11
to cu...@googlegroups.com, Me
Oh, I did , I was curious if anything jumped out to anyone.  The 1st one works, the second one does not.

Me

unread,
Feb 27, 2011, 9:34:49 PM2/27/11
to cu...@googlegroups.com, Me
Oh, I did , I was curious if anything jumped out to anyone.  The 1st one works, the second one does not.

Me

unread,
Feb 27, 2011, 9:49:09 PM2/27/11
to cu...@googlegroups.com, Me
I was trying to make it so any combination of the vars can be implemented.

Me

unread,
Feb 28, 2011, 12:18:52 AM2/28/11
to cu...@googlegroups.com, Me
I anyone is interested I worked it from left to right one at a tme, it now works:

Then /^I should see my dashboard(?: with?(?: "([^"]*)" works,?)?(?: "([^"]*)" open submissions,?)?(?: "([^"]*)" total submissions,?)?(?: "([^"]*)" favorite publishers,?))?$/ do |works,open_subs,total_subs,fav_pubs|
  Then %{I should see "Favorite Publishers #{fav_pubs}"}
  Then %{I should see "Open Submissions #{open_subs}"}
  Then %{I should see "Total Submissions #{total_subs}"}
Reply all
Reply to author
Forward
0 new messages