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. -- Posted via http://www.ruby-forum.com/.
> ?Where is the method raw defined?Sorry this is stupid. Forget my last question -- Posted via http://www.ruby-forum.com/.
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. -- Posted via http://www.ruby-forum.com/.
Juanma Cervera
2009-Jan-16 11:14 UTC
[rspec-users] Step tables - Writing the block for a have_selector matcher
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 -- Posted via http://www.ruby-forum.com/.
aslak hellesoy
2009-Jan-16 11:26 UTC
[rspec-users] Step tables - Writing the block for a have_selector matcher
On Fri, Jan 16, 2009 at 12:14 PM, Juanma Cervera <lists at ruby-forum.com>wrote:> 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. >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> > Juanma Cervera > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Aslak (::) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090116/43989240/attachment-0001.html>