2014-07-21 20 views
0

我正在使用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

+0

它說你的錯誤是在'static_pages_controller_spec.rb'行7.您可以在您的問題這個文件?實際上整個'static_pages_controller_spec.rb'。 – SteveTurczyn

+0

我已經添加了整個static_pages_controller_spec.rb。 –

回答

0

static_pages_controller_spec

describe "GET '...'" do 
    it "returns http success" do 
     get '...' 
     response.should be_success 
    end 
    end 

"..."在這方面廢話和教程可能包括它作爲「標本」條目。

註釋掉上面的紋路,或在您的static_pages_controller.rb一個真正的方法取代「...」。你可能有一個index方法,以便你可以做...

describe "GET index" do 
    it "returns http success" do 
     get :index 
     response.should be_success 
    end 
    end 

乾杯

+0

我這樣做了,我仍然得到這個錯誤:StaticPagesController GET索引返回http成功 失敗/錯誤:得到:索引 ActionController :: UrlGenerationError: 沒有路由匹配{:action =>「index」,:controller =>「 static_pages「} #./spec/controllers/static_pages_controller_spec.rb:7:in ' –

+0

好的,對,所以你沒有'索引'動作在你的static_pages_controller ...我剛剛檢查了你的routes.rb,我可以看到。試試這個'get'/ about'' 這應該工作。 – SteveTurczyn

+0

我在route.rb上輸入「'/ about'」,它給了我一個巨大的錯誤,說:「丟失:路由上的操作鍵...」 –

相關問題