Step tables


#1

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.


#2

¿Where is the method raw defined?
Sorry this is stupid.
Forget my last question


#3

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.


#4

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 C.


#5

On Fri, Jan 16, 2009 at 12:14 PM, Juanma C.
removed_email_address@domain.invalidwrote:

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