Ruby on rails Can';t让routes{MyEngine::Engine.routes}使用rspecrails3.1.0和rails4.2.0处理共享示例
我正在尝试将我在rails 4.1中编写的引擎更新为rails 4.2。这在我的控制器规范中引入了关于使用:use_route的弃用警告 我已经删除了我正在使用的每个地方:use_route,并将其替换为将routes{MyEngine::Engine.routes}放在控制器规范的顶部。这对于控制器规范中的所有测试都起到了预期的作用,除了处理共享示例的测试 我的共享示例均未通过,我得到以下结果:Ruby on rails Can';t让routes{MyEngine::Engine.routes}使用rspecrails3.1.0和rails4.2.0处理共享示例,ruby-on-rails,rspec,Ruby On Rails,Rspec,我正在尝试将我在rails 4.1中编写的引擎更新为rails 4.2。这在我的控制器规范中引入了关于使用:use_route的弃用警告 我已经删除了我正在使用的每个地方:use_route,并将其替换为将routes{MyEngine::Engine.routes}放在控制器规范的顶部。这对于控制器规范中的所有测试都起到了预期的作用,除了处理共享示例的测试 我的共享示例均未通过,我得到以下结果: Failure/Error: action ActionController::UrlGenera
Failure/Error: action
ActionController::UrlGenerationError:
No route matches {:action=>"destroy", :controller=>"foo/roles", :id=>"1"}
我想知道如何让我的共享示例通过这种方式添加路由到我的控制器规格
我拥有的其中一个规格的示例是:
spec/controllers/roles_controller_spec.rb
require 'rails_helper'
module Foo
describe RolesController do
routes {Foo::Engine.routes}
before { sign_in_user FactoryGirl.create(:user, admin: true)}
it_behaves_like 'requires admin privilege' do
let(:action) {get :show, id: role.id}
end
end
end
spec/support/shared_examples.rb
shared_examples "requires admin privilege" do
routes { Foo::Engine.routes }
it 'redirects to main app root if user is not an admin' do
session[:user_id] = FactoryGirl.create(:user)
action
expect(response).to redirect_to main_app.root_path
end
end
非常感谢您的任何想法或帮助
谢谢这件事解决过吗?我也遇到了同样的问题。看看我发布这篇文章时可能正在使用的引擎。看看下面的要点,看看我是如何解决的:希望这有帮助