lundi 14 décembre 2015

Testing to make sure response.body contains the right tags in the head of the page

Im writing a test to check that there are OpenGraph meta tags present on a certain page. The test has been written as below.

test "og tags are present" do
  get :bid, id: auctions(:name)
  assert_response :success
  assert_select "head" do
    assert_select "meta" do
      assert_match /og:title/, response.body
      assert_match /og:type/, response.body
      assert_match /og:url/, response.body
      assert_match /og:image/, response.body
      assert_match /og:description/, response.body
    end
  end
end

I think there is an easier way to do this possibly without looking at the whole response.body in the assert_match calls. I just want to look at what is within the meta tags nested in the head tags. Any help is much appreciated

Aucun commentaire:

Enregistrer un commentaire