[rspec-users] specifying which button webrat should press

Andrew Premdas apremdas at gmail.com
Thu Nov 20 08:44:48 EST 2008


I did something similar with

  Scenario: Cart shows item price and total price
    Given there is a product with name foo and price £24.50
    And I am on the products page
    When I add product with name foo to cart

And a step matcher

When /^I add product with name (.*) to cart$/ do |name|
  p = Product.find_by_name(name)
  p.should_not be_nil
  clicks_link_within("#product_#{product.id}", "Add to Basket")
end

A couple of things that influenced this where

1) I didn't think it was appropriate to have the technical mechanism
for adding the product (push button, click add link etc.) in the
feature

2) Any page with multiple button|links with the same text must have
some surrounding element that allows you to differentiate. This
technical detail belongs in the steps

As far as your features go I think that

  And I accept Fred's invite

scans better than

  And I push "accept" near "Fred"

HTH


2008/11/20 Pau Cor <lists at ruby-forum.com>:
> 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
>    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
>    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 at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list