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

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.