[rspec-users] cucumber, finding a row in a table

Zach Dennis zach.dennis at gmail.com
Tue Jan 6 19:53:55 EST 2009


On Tue, Jan 6, 2009 at 4:08 PM, James Byrne <lists at ruby-forum.com> wrote:
> Zach Dennis wrote:
>>
>> Does your outputted HTML properly include a tbody in the table? If so
>> the selector you are using won't work. You would need to make match
>> any descendant rather than any direct child, ie:  "table
>> tr#entity_id_1"
>>
>
> I cannot find one if there is.
>
>> On a related note (although not specific your problem at hand) to
>> generate an id on an ActiveRecord model you can use the dom_id helper
>> method provided by Rails. ie: "dom_id(entity)". You can use this both
>> in your template and your steps/specs. And rather than hardcoding
>> "table tr" CSS selectors why not just give your table an id like
>> "entities" and then use dom_id to give your rows ids? Should you
>> change the display to a ul or ol you wouldn't have to go back and
>> change your CSS selectors,
>
> Could you provide a reference to an example of how this is done?  I am
> afraid that the API was insufficient to clarify this for me.
>

When constructing HTML ids you can avoid concatenating strings, ie:
   "entity_id_" + my_entity.to_s

Instead you can use this:
   dom_id(entity)

You can also pass in additional identifiers:
   dom_id(entity, "show")

If you use this in your steps and in your views themselves it cleans
generating html ids up. In my cucumber env.rb I have added so the dom
helpers are available throughout my steps

  Cucumber::Rails::World.class_eval do
    include ActionView::Helpers::RecordIdentificationHelper
  end

Hope this helps,

-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list