Forum: RSpec Step tables

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Juanma C. (Guest)
on 2009-01-15 13:22
I am having some trouble using step tables.

I am trying with an step similar to the sample step generarated by the
cucumber generator

Then /^I should see the following froobles:$/ do |froobles|
  froobles.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

This works, and I understand the sintaxis, but the problem is that it
works even if I make an error with the data, because it seems that the
block of have_selector is never entered in, and I can't check nothing
inside the block.

And another question.
I have seen that Cucumber::Model::Table has a 'rows' method for
accessing the rows of the table, but is not still in cucumber 0.1.15.
¿Where is the method raw defined?

Juanma C. (Guest)
on 2009-01-15 13:38
> ¿Where is the method raw defined?
Sorry this is stupid.
Forget my last question
Juanma C. (Guest)
on 2009-01-16 00:57
Can somebody confirm that the have_selector method yields to the block?
In all the test I have done it seems it does not work.

I even have try an step like this

when /whatever ..../ do
  response.should have_selector("table > tr:nth-child(#{2}) >
td:nth-child(#{1})") { |td|
  td.inner_text.should == cell
  "foo".should == "bar"     # I think this would fail no?

but the step pass without failing.
Juanma C. (Guest)
on 2009-01-16 13:14

I have solved my problem.

Because I am using spanish for wrinting my features, I didn't paste the
exact sentences of the code I was using, and pasted instead a
"manual-translated similar" code.
And nobody could see the problem. Never more.

The problem was that I was writing the block for the have_selector with
do...end instead of {...}
And it didn't work in these case.
Is this a bug or is it a special feature of this construct.

Juanma C.
Aslak H. (Guest)
on 2009-01-16 13:28
(Received via mailing list)
On Fri, Jan 16, 2009 at 12:14 PM, Juanma C.

> do...end instead of {...}
> And it didn't work in these case.
> Is this a bug or is it a special feature of this construct.

You have to use {} in this case. {} and do..end have different
rules in the Ruby language.

In this case, when you use do..end, the block gets sent to the #should
method (the leftmost), but if you use {} it gets sent to the
method (the rightmost).

This topic is locked and can not be replied to.