4

Rails 4 beta1 アプリケーションに複数の Rails エンジンがあります。私はrspec-railsすべてのエンジンにgemをインストールしています。そして、次のコマンドでエンジンを作成しました。

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

エンジンのダミー アプリケーションで、データベースとルートを構成しました。以下は、routes.rb ファイルの例です。

Rails.application.routes.draw do

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

最初のエンジン内で 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>'

そして、これが私のコントローラーテストです/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

コントローラーのテストが機能していないようです。モデルテストがあり、正常に動作しています。何か案が?

更新 1: 私のアプリケーション構造:

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

3 に答える 3

15

解決策は非常に簡単です。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
于 2013-05-04T10:04:55.120 に答える
3

表示されている構成と仕様は 用ですStoreFrontendが、エラーは 用StoreAdmin::DashboardControllerです。そのため、テストしているエンジンや失敗しているエンジンについて混乱しているようです。

もちろん、簡単な解決策は、不足しているルートを作成することです{:action=>"index", :controller=>"store_admin/dashboard"}

于 2013-04-29T06:24:10.433 に答える