多个 Rails 引擎 rspec 控制器测试不起作用 [英] Multiple Rails engine rspec controller test not work

查看:35
本文介绍了多个 Rails 引擎 rspec 控制器测试不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have multiple Rails engines in my Rails 4 beta1 application. I'm installed rspec-rails gem to every engines. And I created my engine following command:

rails plugin new store_frontend --dummy-path=spec/dummy -d postgresql --skip-test-unit --mountable

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

In my engine's dummy application I configured database and routes. Here is example routes.rb file:

Rails.application.routes.draw do

  mount StoreFrontend::Engine => "/store"
end

当我在第一个引擎中运行 rspec 时,出现以下错误:

When I run rspec inside first engine I get following errors:

  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>'

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

And here is my controller test /It's generated from 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

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

It seems like controller test is not working. I have model tests and it's working fine. Any idea?

更新 1:我的应用结构:

bin/
config/
db/
lib/
log/
public/
tmp/
engine1/
engine2/
engine3/

推荐答案

解决方案很简单.将 use_route 添加到您的控制器测试中.这是示例.

The solution is very simple. Add use_route to your controller test. Here is the example.

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

这篇关于多个 Rails 引擎 rspec 控制器测试不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆