As far as I know, you are trying to combine two tests into one. In rspec, this should be allowed in two steps. In one specifier, you check the routing, and in the other you check the controller.
So add file spec/routing/root_routing_spec.rb
require "spec_helper" describe "routes for Widgets" do it "routes /widgets to the widgets controller" do { :get => "/" }.should route_to(:controller => "home", :action => "index") end end
And then add the spec/controllers/home_controller_spec.rb , and I use advanced matches defined by position or wonderful.
require 'spec_helper' describe HomeController do render_views context "GET index" do before(:each) do get :index end it {should respond_with :success } it {should render_template(:index) } it "has the right title" do response.should have_selector("h1", :content => "Project") end end end
In fact, I almost never use render_views , but I always test my components as isolated as possible. Is the view the correct title I'm testing in my view specification.
Using rspec i, I test each component (model, controller, views, routing) separately, and I use a cucumber to record high-level tests to trim all layers.
Hope this helps.
source share