如何为路由编写规范测试 - Rails 4

时间:2015-08-24 08:01:31

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

我正在尝试为SessionsController编写测试,我写了以下内容:

我使用Spec 3.3

    RSpec.describe SessionsController, type: :controller do

        describe SessionsController do

            describe "POST create" do 

                it "sign in should have a valid route" do
                    post('/api/signin').should route_to('api/sessions#create')
                end

            end

        end

    end

此应用主要用作API,因此目前无需观看。

在我的路线中,我有以下内容:

match     '/api/signin',                          to: 'api/sessions#create',

然而,测试没有通过。

有什么建议吗?

编辑:错误:

rspec ./spec/controllers/sessions_controller_spec.rb:27 # SessionsController SessionsController POST create sign in should have a valid route
rspec ./spec/controllers/sessions_controller_spec.rb:31 # SessionsController SessionsController POST create creates a new session

EDIT2:添加了完整的测试代码

0 个答案:

没有答案