Я просто пишу пару тестов, и я хочу убедиться, что могу проверить, что некоторые метатеги находятся на странице.RSpec Rails не найдет мои метатеги
describe "article", :type => :feature do
it "has correct meta tags", js: true do
love_article = FactoryGirl.create(:love_article, title: 'Kitten Takes Over the World!', created_at: "Sat, 30 May 2015 12:12:21 -0400", updated_at: "Mon, 01 Jun 2015 12:12:44 -0400")
visit "/articles/#{love_article.slug}"
page.source.should have_selector('title', text: 'Kitten Takes Over the World!', visible: false) # this is found
expect(page).to have_selector('pubdate', text: '05/30/15 12:12:21 PM', visible: false) # This is not found
# ERROR
# page.source.should have_selector('pubdate', text: '5/30/15 12:12:21 PM', visible: false)
# RSpec::Expectations::ExpectationNotMetError: expected to find css "pubdate" with text "5/30/15 12:12:21 PM" but there were no matches from /Users/moiseszaragoza/.rvm/gems/ruby-2.1.2/gems/rspec-expectations-3.0.4/lib/rspec/expectations/fail_with.rb:30:in `fail_with'
end
end
теперь, когда я добавить отладчик и я page.source
я получаю
<!DOCTYPE html>
<html>
<head>\n
<title>Kitten Takes Over the World!</title>\n
<link rel=\ "stylesheet\" media=\ "all\" href=\ "/assets/application.css\">\n
<meta content=\ "Kitten Takes Over the World!\" property=\ "og:title\">\n
<meta content=\ "http://127.0.0.1:51840/articles/2015/05/30/kitten-takes-over-the-world\" property=\ "og:url\">\n
<meta content=\ "Tell on Me is enabling parents to phone in complaints on unsuspecting teen drivers.\" property=\ "og:description\">\n
<meta content=\ "/uploads/test/article/hero_image/42/test-image-file-employee.png\" property=\ "og:image\">\n
<meta content=\ "article\" property=\ "og:type\">\n
<meta content=\ "IE=edge,chrome=1\" http-equiv=\ "X-UA-Compatible\">\n
<meta charset=\ "utf-8\">\n
<meta content=\ "text/html\" http-equiv=\ "Content-Type\">\n
<meta name=\ "section\">\n
<meta content=\ "05/30/15 12:12:21 PM\" property=\ "og:pubdate\">\n
<meta content=\ "05/30/15 12:12:21 PM\" name=\ "pubdate\">\n
<meta content=\ "06/01/15 12:12:44 PM\" name=\ "lastmod\">\n
<meta content=\ "Joe Shmoe\" name=\ "author\">\n
Я думаю, чтобы прояснить мне нужно найти эту строку из исходного кода
<meta content=\ "05/30/15 12:12:21 PM\" name=\ "pubdate\">\n
Спасибо это выручить, но если бы я хотел, чтобы проверить для значения мета [имя = «описание»] будет ли способ для того или должен ли я просто быть счастлив, что есть тег – MZaragoza
Я отредактировал, чтобы включить, как проверить содержание. –
Также обратите внимание, что добавленная часть использует синтаксис 'expect(). To' вместо устаревшего синтаксиса' object.should'. –