Rails测试控制器

时间:2016-09-30 18:59:33

标签: ruby ruby-on-rails-4 rspec

尝试测试我的控制器

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"}

我写了路线,我做错了什么?

1 个答案:

答案 0 :(得分:2)

您的static_pages_controller_spec.rb

中有拼写错误
RSpec.describe StatigPagesController

尝试:

RSpec.describe StaticPagesController