Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing (test-unit) a meta tag's name and content to make sure the content is not empty

I'm having a really hard time figuring out how to make sure a meta title's content attribute is not empty using either assert_select or assert_tag. I can't figure out how to get it to work together.

To give you a better idea, here's an example of how I would like the test to work:

This should pass:

[meta name="title" content="Hello" /]

This should fail:

[meta name="title" content="" /]

[note: Having no tag at all should also fail]

like image 827
AntelopeSalad Avatar asked Sep 14 '13 18:09

AntelopeSalad


1 Answers

I got it to work shortly after posting with a little help from IRC and the documentation example as a base. Rather than delete the post I'll keep it up because this was surprisingly annoying to track down.

Here's the code:

assert_select "meta[name=title]" do
  assert_select "[content=?]", /.+/
end
like image 115
AntelopeSalad Avatar answered Sep 23 '22 13:09

AntelopeSalad