Forum: RSpec Step tables

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.
F1e1789ff9e7fc3032fa6cf15382a1e8?d=identicon&s=25 Juanma Cervera (jmcervera)
on 2009-01-15 12: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
      }
    end
  end
end

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?

Thanks.
F1e1789ff9e7fc3032fa6cf15382a1e8?d=identicon&s=25 Juanma Cervera (jmcervera)
on 2009-01-15 12:38
> ¿Where is the method raw defined?
Sorry this is stupid.
Forget my last question
F1e1789ff9e7fc3032fa6cf15382a1e8?d=identicon&s=25 Juanma Cervera (jmcervera)
on 2009-01-15 23: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?
 }
end

but the step pass without failing.
F1e1789ff9e7fc3032fa6cf15382a1e8?d=identicon&s=25 Juanma Cervera (jmcervera)
on 2009-01-16 12:14
Ok.

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 Cervera
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-01-16 12:28
(Received via mailing list)
On Fri, Jan 16, 2009 at 12:14 PM, Juanma Cervera
<lists@ruby-forum.com>wrote:

> 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
precedence
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
#have_selector
method (the rightmost).

Aslak
This topic is locked and can not be replied to.