2016-09-30 170 views
0

想測試我的控制器Rails的測試控制器

static_pages_controller_spec.rb

require 'rails_helper' 

    RSpec.describe StatigPagesController, type: :controller do 
     it 'return home view' do 
     get '/' 
     expect(response).to render_template :home 
     end 

     it 'return about view' do 
     get :about 
     expect(response).to render_template :about 
     end 
    end 

的routes.rb

Rails.application.routes.draw do 
    devise_for :users 
    root 'static_pages#home' 
    get '/about', to: 'static_pages#about' 
end 

和我得到的錯誤

1) StatigPagesController return home view 
     Failure/Error: get '/' 

     ActionController::UrlGenerationError: 
      No route matches {:action=>"/", :controller=>"statig_pages"} 

    2) StatigPagesController return about view 
    Failure/Error: get :about 

    ActionController::UrlGenerationError: 
     No route matches {:action=>"about", :controller=>"statig_pages"} 

我寫了路線,我做錯了什麼?

回答

2

你有一個錯字在你static_pages_controller_spec.rb

RSpec.describe StatigPagesController 

嘗試:

RSpec.describe StaticPagesController 
+0

它是我的錯...謝謝treiff! –