在我的引擎'Utilizer'中,我试图用Rspec 3.2测试路由。 命名空间被隔离无法在Rails 3.2下测试引擎路由+ Rspec 2.13
# lib/utilizer/engine.rb
module Utilizer
class Engine < ::Rails::Engine
isolate_namespace Utilizer
...
end
end
发动机被安装到虚设应用程式:
# spec/dummy/config/routes.rb
Rails.application.routes.draw do
mount Utilizer::Engine => "/utilizer", as: 'utilizer'
end
要我已经添加了几个提供配置的作为(来自here)以下spec_helper.rb:
# spec/spec_helper.rb
RSpec.configure do |config|
...
config.before(:each, type: :routing) { @routes = Utilizer::Engine.routes }
...
end
当我定义路线时:
# config/routes.rb
Utilizer::Engine.routes.draw do
resources :auths, id: /\d+/, only: [:destroy]
end
瑞克显示它适当的虚设应用程式:
$ spec/dummy > bundle exec rake routes
$ utilizer /utilizer Utilizer::Engine
$ Routes for Utilizer::Engine:
$ auth DELETE /auths/:id(.:format) utilizer/auths#destroy {:id=>/\d+/}
但两者Rspec的测试
# spec/routing/auths_routing_spec.rb
require 'spec_helper'
describe "Auths page routing" do
let!(:auth) { create(:utilizer_auth) } # factory is working properly by itself
describe "#destroy" do
let!(:action) { { controller: "utilizer/auths", action: "destroy", id: auth.id } }
specify { { delete: "/auths/#{ auth.id }" }.should route_to(action) }
specify { { delete: auth_path(auth) }.should route_to(action) }
end
end
失败,错误(用于第一和第二试验相应):
No route matches "/auths/1"
No route matches "/utilizer/auths/1"
但是,福尔摩斯,为什么?
为我工作。 config.before在rails 4.0.2下无法运行。谢谢! – Marcelo