# Understanding "within"

**URL:** <https://www.ruby-forum.com/t/understanding-within/156226>\
**Category:** RSpec\
**Created:** [December 23, 2008, 1:03am UTC](https://www.ruby-forum.com/t/understanding-within/156226 "2008-12-23T01:03:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [December 23, 2008, 1:03am UTC](https://www.ruby-forum.com/t/understanding-within/156226/1 "2008-12-23T01:03:21Z")

</div>

So, I want to test clicking a link in a table and found this handy  
example by Aslak:

[http://github.com/aslakhellesoy/cucumber\_rails/tree/master/features/step\_definitions/lorry\_steps.rb](http://github.com/aslakhellesoy/cucumber_rails/tree/master/features/step_definitions/lorry_steps.rb)

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  
[gitrdoc.com](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

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [December 23, 2008, 9:13am UTC](https://www.ruby-forum.com/t/understanding-within/156226/2 "2008-12-23T09:13:13Z")

</div>

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: [Specifying which button webrat should press - RSpec - Ruby-Forum](http://www.ruby-forum.com/topic/171269)

HTH  
Paul

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [December 23, 2008, 5:43am UTC](https://www.ruby-forum.com/t/understanding-within/156226/3 "2008-12-23T05:43:58Z")

</div>

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](http://www.w3.org/TR/CSS2/selector.html#q2)

HTH  
Jeremiah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [December 23, 2008, 1:59pm UTC](https://www.ruby-forum.com/t/understanding-within/156226/4 "2008-12-23T13:59:26Z")

</div>

On Mon, Dec 22, 2008 at 11:30 PM, Jeremiah Heller  
[removed\_email\_address@domain.invalid](mailto: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:  
> [Selectors](http://www.w3.org/TR/CSS2/selector.html#q2)

This might also be of help

> **[Getting to Know CSS3 Selectors: Structural Pseudo-Classes — SitePoint](https://www.sitepoint.com/getting-to-know-css3-selectors-structural-pseudo-classes/)**
>
> In this two-part series, I’ll look at the new selectors in CSS3, starting with structural pseudo-classes.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RubyRedRick](http://twitter.com/RubyRedRick)
