Forum: Ruby on Rails RSpec and Testing for the presence of css class

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.
Armand du Plessis (Guest)
on 2008-10-29 13:36
(Received via mailing list)
Hi there,

Hoping someone can help with this or point out alternative options for
testing for the presence of a css class on a specific element.

We're using rspec and I would like to check for the presence of a
specific css class ('current') on an element (link).

response.should have_tag('a#some_link')

I was hoping that the have_tag matcher might have some option to
specify a class to match but can't gleam anything from the docs.

Any suggestions would be really welcome?

Armand
Armand du Plessis (Guest)
on 2008-10-29 13:52
(Received via mailing list)
We've switched away from using current on the element in favour of
descendent selectors which makes the testing easier as well.

http://www.alistapart.com/articles/slidingdoors2/

Cheers,

Armand
Christian L. (Guest)
on 2008-10-29 20:12
(Received via mailing list)
Try:
have_tag('a.current')

Christian
Armand du Plessis (Guest)
on 2008-10-30 09:31
(Received via mailing list)
Thanks Christian. In hindsight that makes perfect sense :)

On Oct 29, 8:11 pm, Christian L. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.