Trying out rspec-rails. I get a weird error – no routes are supposedly found, even though I can access them fine in the browser when running rails s.
I even tried it with just /
Failure/Error: get "/"
ActionController::RoutingError:
No route matches {:controller=>"action_view/test_case/test", :action=>"/"}
I can definitely access / and other resources in the browser, though. Is there something I could’ve missed when setting rspec up? I put it into the Gemfile and ran rspec:install.
Thank you,
MrB
edit: Here’s my test
1 require 'spec_helper'
2
3 describe "resource" do
4 describe "GET" do
5 it "contains /" do
6 get "/"
7 response.should have_selector("h1", :content => "Project")
8 end
9 end
10 end
Here’s my route file:
myApp::Application.routes.draw do
resources :groups do
resources :projects
end
resources :projects do
resources :variants
resources :steps
member do
get 'compare'
end
end
resources :steps do
resources :costs
end
resources :variants do
resources :costs
end
resources :costs
root :to => "home#index"
end
My spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.include RSpec::Rails::ControllerExampleGroup
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
end
Didn’t really change anything here, I think.
As far as i know, you are trying to combine two tests into one. In rspec this should be solved in two steps. In one spec you test the routing, and in another you test the controller.
So, add a file
spec/routing/root_routing_spec.rbAnd then add a file
spec/controllers/home_controller_spec.rb, and I am using the extended matchers defined by shoulda or remarkable.Actually, I almost never use
render_viewsbut always test my components as isolated as possible. Whether the view contains the correct title I test in my view-spec.Using rspec i test each component (model, controller, views, routing) separately, and i use cucumber to write high level tests to slice through all layers.
Hope this helps.