多个Rails引擎rspec控制器测试不起作用

Zec*_*eck 4 rspec ruby-on-rails rails-engines rspec-rails ruby-on-rails-3

我的Rails 4 beta1应用程序中有多个Rails引擎.我rspec-rails为每个引擎安装了gem.我按照命令创建了我的引擎:

rails plugin new store_frontend --dummy-path=spec/dummy -d postgresql --skip-test-unit --mountable
Run Code Online (Sandbox Code Playgroud)

在我的引擎的虚拟应用程序中,我配置了数据库和路由.以下是routes.rb文件的示例:

Rails.application.routes.draw do

  mount StoreFrontend::Engine => "/store"
end
Run Code Online (Sandbox Code Playgroud)

当我在第一个引擎内运行rspec时,我得到以下错误:

  1) StoreAdmin::DashboardController GET 'index' returns http success
     Failure/Error: get 'index'
     ActionController::UrlGenerationError:
       No route matches {:action=>"index", :controller=>"store_admin/dashboard"}
     # ./spec/controllers/store_admin/dashboard_controller_spec.rb:8:in `block (3 levels) in <module:StoreAdmin>'
Run Code Online (Sandbox Code Playgroud)

这是我的控制器测试/它是从Rails /生成的:

require 'spec_helper'

module StoreFrontend
  describe HomeController do

    describe "GET 'index'" do
      it "returns http success" do
        get 'index'
        response.should be_success
      end
    end

  end
end
Run Code Online (Sandbox Code Playgroud)

似乎控制器测试不起作用.我有模型测试,它工作正常.任何的想法?

更新1: 我的申请结构:

bin/
config/
db/
lib/
log/
public/
tmp/
engine1/
engine2/
engine3/
Run Code Online (Sandbox Code Playgroud)

Zec*_*eck 14

解决方案非常简单.添加use_route到您的控制器测试.这是一个例子.

module StoreFrontend
  describe HomeController do

    describe "GET 'index'" do
      it "returns http success" do
        get 'index', use_route: 'store_frontend' # in my case
        response.should be_success
      end
    end

  end
end
Run Code Online (Sandbox Code Playgroud)