# Using semantics in steps

**URL:** <https://www.ruby-forum.com/t/using-semantics-in-steps/156012>\
**Category:** RSpec\
**Created:** [December 19, 2008, 7:38am UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012 "2008-12-19T07:38:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 7:38am UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/1 "2008-12-19T07:38:36Z")

</div>

Hi All,

Wanted to put this idea forward, see what you think of it. I’m using  
Aslaks  
lorry feature to illustrate this. See  
[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)  
.

In particular

within(“table \> tr:nth-child(#{pos.to\_i+1})”) do  
click\_link “Destroy”

and

Then /^I should see the following lorries:$/ do |lorries|  
lorries.raw[1…-1].each\_with\_index do |row, i|  
row.each\_with\_index do |cell, j|  
response.should have\_selector(“table \> tr:nth-child(#{i+2}) \>  
td:nth-child(#{j+1})”) { |td|  
td.inner\_text.should == cell  
}  
end  
end

Now imagine this is a real project, and your designer comes along and  
decides that lorries really should be shown in a horizontal scrolling  
zoomable javascript widgity thing. Now out go the tables and the  
scenario  
breaks.

However if we use something like

within("#lorries \> .lorry:nth-child # not tested this syntax,  
hope the meaning is clear

then we have

1. Defined semantic tags that the designer should not touch
2. Not relied on any html elements that a designer might change
3. Created a step that works with the meaning of the UI not its  
presentation

So what do you think?

Andrew

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/2 "2008-12-19T16:08:03Z")

</div>

On Fri, Dec 19, 2008 at 1:09 AM, Andrew P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> then we have
> 
> 1. Defined semantic tags that the designer should not touch
> 2. Not relied on any html elements that a designer might change
> 3. Created a step that works with the meaning of the UI not its presentation
> 
> So what do you think?

100% agree. The more semantic your test code is, the less likely it  
is to break, and the more likely it ought to when it does. If there’s  
no longer a #lorries element on the page, the step will fail, but  
that’s a lot like saying that if the lorries aren’t on the page the  
step will fail. And that’s a good thing.

Peter

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 5:34pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/3 "2008-12-19T17:34:25Z")

</div>

On Fri, Dec 19, 2008 at 1:09 AM, Andrew P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> and  
> Now imagine this is a real project, and your designer comes along and
> 
> 1. Defined semantic tags that the designer should not touch
> 2. Not relied on any html elements that a designer might change
> 3. Created a step that works with the meaning of the UI not its presentation
> 
> So what do you think?

I agree with your sentiments. It’s how I access (and encourage others  
to access) the views (both in step definitions and in view specs).

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/4 "2008-12-19T19:15:56Z")

</div>

Is this a feature request or a style thing?

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/5 "2008-12-19T18:04:17Z")

</div>

> > In particular  
> > td.inner\_text.should == cell
> > 
> > So what do you think?

Feel free to submit a patch.

Aslak

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/6 "2008-12-19T20:01:05Z")

</div>

Was just using your code as an example, not being critical of it. Sorry  
if  
it came out that way :). In its context it makes its point very clearly.

Andrew

2008/12/19 Aslak HellesÃ¸y [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/7 "2008-12-19T20:17:31Z")

</div>

A style thing, just exploring interactions between features and UI

2008/12/19 David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![diabolist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@diabolist](https://www.ruby-forum.com/u/diabolist)\
**Post date:** [December 19, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/using-semantics-in-steps/156012/8 "2008-12-19T19:34:05Z")

</div>

On Fri, Dec 19, 2008 at 1:13 PM, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is this a feature request or a style thing?

I believe strictly style. Webrat supports within already, ie:

within “#my-css-selector” do |scope|  
scope.should have\_selector(“child element”)  
end

> > > > lorry feature to illustrate this. See  
> > > > lorries.raw[1..-1].each\_with\_index do |row, i|  
> > > > breaks.  
> > > > 3) Created a step that works with the meaning of the UI not its  
> > > > I agree with your sentiments. It’s how I access (and encourage others
> > 
> > * * *
> > 
> > rspec-users mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.
