Using RSpec to test meta descriptions

A little code snippet to show you how to test meta descriptions in RSpec

How I went about testing the meta description on a view:

within('head', visible: false) do
  expect(page).to have_css("meta[name=description][content='The meta description for my webpage.']")
end

Something which helped me out a lot was using puts page.source in my test, this puts the HTML of the page out in my terminal so I could see exactly what was being put out.

Recent posts View all

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.