rails 4 api rspec test http状态码410
我正在尝试构建正确的rspec测试以validation我的410状态代码处理程序是否正常工作。 以下是路线捕获的所有内容:
match '*not_found', to: 'error#error_404', via: :all
我的简单错误控制器:
class ErrorController < ApplicationController def error_404 head status: 410 end end
我目前的rspec:
require 'spec_helper' describe ErrorController do context "Method #error_404 handling missing routes =>" do it "Should have the 410 status code.." do get :error_404 expect(response.status).to be(410) end end end
Rspec错误消息:
1) ErrorController Method #error_404 handling missing routes => Should have the 410 status code.. Failure/Error: get :error_404 ActionController::UrlGenerationError: No route matches {:action=>"error_404", :controller=>"error"} # ./spec/controllers/error_controller_spec.rb:7:in `block (3 levels) in '
有关如何通过此测试的任何想法? 我知道这条路线不会存在,但是我很难尝试使用get
来使它工作……
我想知道是否有人在这里有更好的想法…..但是,这是我如何解决它:
首先我安装了水豚 。
然后我调整了路线以更具描述性:
match '*not_found', to: 'error#error_status_410', via: :all
然后我调整了我的错误控制器:
class ErrorController < ApplicationController def error_status_410 head status: 410 end end
最后我调整了我的错误控制器规范:
require 'spec_helper' describe ErrorController do context "Method #error_status_410 handling missing routes =>" do it "Should have the 410 status code.." do visit '/will-never-be-a-route' page.status_code == 410 end end end