我想测试该应用程序响应404错误并且有代码:
require 'spec_helper'
describe Admin::UsersController do
describe "GET new" do
before { get :new }
it { should respond_with(404) }
end
end
我的路线:
namespace :admin, module: :admin do
resources :users, except: [:new, :create]
end
当我在生产模式下运行本地服务器时,它确实以404错误响应,但是当我运行rspec测试时,它给了我以下内容:
1) Admin::UsersController GET new shold not be successful
Failure/Error: get :new
ActionController::UrlGenerationError:
No route matches {:action=>"new", :controller=>"admin/users"}
# ./spec/controllers/admin_users_spec.rb:7:in `block (3 levels) in <top (required)>'
如何正确测试?
更新了正确答案:
describe "GET new" do
it "should not route to new" do
expect(get: :new).not_to be_routable
end
end
答案 0 :(得分:4)
我认为您可以使用帮助{ get :new }.should_not be_routable
according to this
评论更新:
应为expect(:get => :new).not_to be_routable