我正在尝试构建正确的 rspec 测试来验证我的 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 <top (required)>'
关于如何通过此测试的任何想法?我知道该路线将不存在,但我无法尝试使用get
它来使其工作......