[rspec-users] Rails View spec testing for content in <head>

Michael Kintzer rockrep at gmail.com
Fri Aug 20 13:16:52 EDT 2010


Hi,
Was trying to verify content in a title tag within a head tag using
RSpec2/Rails3 and a view spec, but it seems that render/rendered API's
only return the html within the body tag.   In my case the head tag is
defined in a Rails layout file, with a yield :title, and the title tag
content is set via a content_for :title section within the view, ala
http://railscasts.com/episodes/30-pretty-page-title.

Is there a way to validate head content in a view spec?

Thanks,

-Michael

Example
---
require "spec_helper"
describe "users/sessions/new.html.erb" do
  describe "head" do
    it "should have a head" do
      render
      rendered.should have_selector("head")
    end
  end
end

  Failure/Error: rendered.should have_selector("head")
    expected following output to contain a <head/> tag:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
    <html><body>...


More information about the rspec-users mailing list