I just lost an hour of my life on this issue, so hopefully I'll save someone else the waste!
require 'spec_helper' describe ExamsController do it "should present the user with the new exam form" do get :index response.should have_selector('form#new_practice_exam_form') end end
Failure/Error: response.should have_selector("") expected following output to contain a tag: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Firstly, ignore the weird form tag it suggests it's looking for - this is a red herring. Webrat just outputs error messages badly.
The actual issue is simply that the HTML is not being rendered. By default, the views are not rendered in controller tests. One line of code fixes this:
require 'spec_helper' describe ExamsController do render_views it "should present the user with the new exam form" do get :index response.should have_selector('form#new_practice_exam_form') end end
Hope that helps someone!!
Update:As Snuggs points out in his comment below, if you find yourself testing view code in the controller, you're probably doing something wrong. View tests and integration (or request) tests are the correct place for this.