Forum: RSpec understanding "within"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sarah A. (Guest)
on 2008-12-23 02:03
So, I want to test clicking a link in a table and found this handy
example by Aslak:

http://github.com/aslakhellesoy/cucumber_rails/tre...

When /^I delete the (\d+)(?:st|nd|rd|th) lorry$/ do |pos|
  visit lorries_url
  within("table > tr:nth-child(#{pos.to_i+1})") do
    click_link "Destroy"
  end
end

What if I wanted to destroy the lorry with "name 3" instead of the 3rd
lorry?  I looked up 'within' in the Webrat docs
http://gitrdoc.com/brynary/webrat/tree/master/ but there was no
description and the source is a bit mysterious.

Could someone describe what "table > tr:nth-child(#{pos.to_i+1})" does?
by semantic pattern matching I could guess that "ol >
li:nth-child(#{pos.to_i+1})" would also work, but it would be nifty to
know why.

Thanks,
Sarah
Jeremiah Heller (Guest)
on 2008-12-23 06:43
(Received via mailing list)
On 22 Dec 2008, at 16:03, Sarah A. wrote:
> Could someone describe what "table > tr:nth-child(#{pos.to_i+1})"
> does?
> by semantic pattern matching I could guess that "ol >
> li:nth-child(#{pos.to_i+1})" would also work, but it would be nifty to
> know why.
>
> Thanks,
> Sarah

Hi Sarah - et al, I'm  a newb too - thanks for the sweet tools! The W3
explains the css selector syntax:
http://www.w3.org/TR/CSS2/selector.html#q2

HTH
Jeremiah
Pau C. (Guest)
on 2008-12-23 10:13
Sarah A. wrote:
> What if I wanted to destroy the lorry with "name 3" instead of the 3rd
> lorry?

I was trying to solve a similar problem a few weeks ago. You might be
interested in the response I got: http://www.ruby-forum.com/topic/171269

HTH
Paul
Rick D. (Guest)
on 2008-12-23 14:59
(Received via mailing list)
On Mon, Dec 22, 2008 at 11:30 PM, Jeremiah Heller
<removed_email_address@domain.invalid>wrote:

>
> Hi Sarah - et al, I'm  a newb too - thanks for the sweet tools! The W3
> explains the css selector syntax:
> http://www.w3.org/TR/CSS2/selector.html#q2


This might also be of help
http://reference.sitepoint.com/css/understandingnt...

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RubyRedRick
This topic is locked and can not be replied to.