[rspec-users] Using semantics in steps

Andrew Premdas apremdas at gmail.com
Fri Dec 19 01:09:31 EST 2008

Hi All,

Wanted to put this idea forward, see what you think of it. I'm using Aslaks
lorry feature to illustrate this. See

In particular

  within("table > tr:nth-child(#{pos.to_i+1})") do
    click_link "Destroy"


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

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

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081219/ec6774f3/attachment.html>

More information about the rspec-users mailing list