On Thu, Nov 20, 2008 at 12:07 AM, Pau Cor <[EMAIL PROTECTED]> wrote: > aslak hellesoy wrote: >> give buttons unique dom ids and pass the id to #clicks_button ? > > Of course that's the easy way to do it :) > > I was hoping to keep my stories a bit closer to English. Plus then I'd > need some extra instance variable so that step can calculate the dom_id. > Here is an example of what I'm going for: > > Scenario: Accepting a friend request > Given there is a user named "Fred" > And I am logged in as a normal user named "Joe" > And there is an unaccepted invite from "Fred" to me > And there is a user named "Sally" > And there is an unaccepted invite from "Sally" to me > When I go to "the invites from friends page" > And I push "accept" near "Fred" > # I want to avoid: And I push #accept_button_user_1
You're on the right track, and I don't think Aslak was recommending putting accept_button_user_1 in the step. What you can do is put it in the step definition, and use some sort of map. For example, I usually have a map of page names to paths so I can say: When I visit the new pet form which is implemented like this: When /I visit the (.*)/ do |page| visit case page when "new pet form" new_pet_path end end So you can do a similar mapping with Fred. Maybe it works like this (just guessing - don't know what your app looks like) When /I push "(.)" near "(.*)" do |what, who| user = User.find_by_first_name(who) clicks_button "#{what}_button_user_#{user.id}" end As long as you keep this sort of thing simple, I find it very manageable and it actually begins to encourage good APIs and conventions in the app. > Then I should see "Now you are friends with Fred" > When I push "ignore" near "Sally" > Then I should see "Sally won't ever bother you again" > > > Or maybe you are suggesting: > > Scenario: Accepting a friend request > Given there is a user named "Fred" > And I am logged in as a normal user named "Joe" > And there is an unaccepted invite from "Fred" to me > And there is a user named "Sally" > And there is an unaccepted invite from "Sally" to me I might do something to eliminate the need for the previous statement: Given /there is an unaccepted invite from "(.*)" to me/ do |username| user = User.find_or_create_by_first_name(username) # whatever you need to create the invite end Now these first lines can be reduced to: Given I am logged in as a normal user named "Joe" And there is an unaccepted invite from "Fred" to me And there is an unaccepted invite from "Sally" to me That's a lot less noise, and there is a clear implication that Fred and Sally exist. WDYT? David > When I go to "the invites from friends page" > And I push "accept" for user "Fred" > Then I should see "Now you are friends with Fred" > When I push "ignore" for user "Sally" > Then I should see "Sally won't ever bother you again" > > with this matcher: > When /^I push "(.*)" for user "(.*)"$/ do |button, user_name| > user = User.find_by_name(user_name) > scope.clicks_button("accept_#{dom_id(user)}") > end > > Am I putting too much thought into this? > > Paul > > P.S. I am sorry if this has been a dumb question. I'm still just trying > to learn the best way to approach this stuff. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users