我正在尝试构建正确的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
endRspec错误消息:
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来使它工作。
发布于 2014-06-13 04:36:58
我想知道这里是否有人有更好的主意……但是,我就是这样解决的:
首先我安装了水豚。
然后,我调整了路线,使之更具描述性:
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
endhttps://stackoverflow.com/questions/24197661
复制相似问题