我正在使用Rails 4.0.8。當我跑bundle exec rspec spec/
,這裏是我從教程得到了錯誤(http://www.railstutorial.org/book/filling_in_the_layout):Michael Hartle第5章:「無路由匹配」錯誤
Pending: StaticPagesHelper add some examples to (or delete) /Users/Desktop/sample_app/spec/helpers/static_pages_helper_spec.rb # No reason given # ./spec/helpers/static_pages_helper_spec.rb:14
Failures:
1) StaticPagesController GET '...' returns http success Failure/Error: get '...' ActionController::UrlGenerationError: No route matches {:action=>"...", :controller=>"static_pages"} # ./spec/controllers/static_pages_controller_spec.rb:7:in `block (3 levels) in '
Finished in 0.20849 seconds 19 examples, 1 failure, 1 pending
Failed examples:
rspec ./spec/controllers/static_pages_controller_spec.rb:6 # StaticPagesController GET '...' returns http success
這裏是我的route.rb
文件:
SampleApp::Application.routes.draw do
resources :users
root to: 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
end
這裏是我的static_pages_helper_spec.rb
文件:
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the StaticPagesHelper. For example:
#
# describe StaticPagesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end describe StaticPagesHelper do pending "add some examples to (or delete) #{__FILE__}" end
這是我的static_pages_controller_spec.rb
文件:
require 'spec_helper'
describe StaticPagesController do
describe "GET '...'" do
it "returns http success" do
get '...'
response.should be_success
end
end
end
應用程序/控制器/ static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def contact
end
end
我不知道是否我得到的錯誤,因爲我的版本是不是與他的教程兼容。我應該看看這個教程而不是http://rails-3-2.railstutorial.org/book/filling_in_the_layout#sec-rails_routes?
它說你的錯誤是在'static_pages_controller_spec.rb'行7.您可以在您的問題這個文件?實際上整個'static_pages_controller_spec.rb'。 – SteveTurczyn
我已經添加了整個static_pages_controller_spec.rb。 –