Mathieu
Mathieu

Reputation: 4787

Rspec/capybara - test html lang

I have scripts that define dynamically the html lang="XX" at the top of the html code.

For example even in guatemala, I have for certain pages with htl lang="de", as they depend not on the country of the IP but on some other model's data.

Anyway, how can I assert in a test with rspec and capybara that the lang attribute of the html is "XX", which would be along the line of:

expect(find('html')).to have_css('[lang="es"]')

The actual html on the page is

<html lang="XX" class="deal-page turbolinks-progress-bar" xmlns:fb="http://ogp.me/ns/fb#">  

I get this error:

expected to find css "[lang=\"es\"]" but there were no matches

Upvotes: 0

Views: 185

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

The have_css matcher checks for descendants of the current scope (in your example the html element) that match the given CSS. You could use the match_css matcher which checks whether the current scope element matches the given CSS

expect(find('html')).to match_css('[lang="es"]')

or (assuming you have no other use for html element) just do

expect(page).to have_css('html[lang="es"]')

which would be more performant.

Upvotes: 2

Related Questions