`have_meta` selector

63 views
Skip to first unread message

Artur

unread,
Jan 29, 2021, 9:18:42 AM1/29/21
to Capybara
Capybara has `have_title`, but there is no built-in matchers to assert `<meta>` tags. Surely it is a no-brainer to just use `assert_selector 'meta[name=robots][content=noindex]', visible: false`, but it involves some effort and a pitfall with `visible: false` being mandatory.

I wonder if there is any interest towards having something similar like `assert_meta name: 'robots', content: 'noindex'. I couldn't find anything related here not at Github.

Artur

unread,
Jan 29, 2021, 11:06:57 AM1/29/21
to Capybara
Or is the absence of such matcher intentional and I should consider using other tool than Capybara?

Thomas Walpole

unread,
Jan 29, 2021, 12:24:41 PM1/29/21
to Capybara
Capybara generally tries to stick to built-in matchers that look for user visible things.  In general `meta` tags aren't visible to the user, and only tangentially (if at all) actually affect the users interaction with the page.
If you do need to check for them then they're generally better checked for in a view test/spec purely for performance reasons.  If you use Capybara matchers in your view tests/specs, or still want to test for `meta` tags in your feature/system tests/specs then I would suggest looking into writing your own custom selector using `Capybara.add_selector` which would allow you do `assert_selector :meta, ...` or with a helper function `assert_meta ..`
Reply all
Reply to author
Forward
0 new messages