我试图为我在Front
命名空间下定义的控制器操作之一编写一个控制器规范(并且生活在root rails app中的Front
引擎中)。我一直在关注这件事:https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/engine-routes-for-controllers
这是我的代码:
# config/routes/rb
Rails.application.routes.draw do
mount Front::Engine => '/', as: 'front'
end
# modules/front/config/routes.rb
Front::Engine.routes.draw do
resources :items
end
# modules/front/app/controllers/front/items_controller.rb
class Front::ItemsController < Front::ApplicationController
def index
# ...
end
end
# spec/controllers/front/items_controller_spec.rb
require 'rails_helper'
RSpec.describe Front::ItemsController, type: :controller do
routes { Front::Engine.routes }
describe "GET index" do
it "assings @items" do
item = FactoryGirl.create(:item)
get :index
expect(assigns(:items)).to eq([item])
end
end
end
运行以上规格给我:
Front::ItemsController
GET index
assings @items (FAILED - 1)
Failures:
1) Front::ItemsController GET index assings @items
Failure/Error: get :index
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"front/items"}
一切都在规格之外工作正常,我可以完全访问该端点。任何想法在这里有什么不对?提前谢谢。