4

레일 4 베타 1 애플리케이션에 여러 개의 레일스 엔진이 있습니다. 모든 엔진에 rspec-rails 보석을 설치했습니다. 그리고 내 엔진 다음 명령을 만들었습니다 :다중 레일 엔진 rspec 컨트롤러 테스트가 작동하지 않습니다.

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

내 엔진의 더미 응용 프로그램에서 데이터베이스와 경로를 구성했습니다.

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

그리고 여기에/그것은/레일에서 내 컨트롤러 테스트 생성 된 것입니다 :

내가 먼저 엔진 내부 RSpec에 실행하면

Rails.application.routes.draw do 

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

나는 다음과 같은 오류를 얻을 : 다음 예제 routes.rb 파일입니다

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 

컨트롤러 테스트가 작동하지 않는 것 같습니다. 모델 테스트가 있는데 잘 작동합니다. 어떤 생각?

UPDATE 1 : 내 응용 프로그램 구조 :

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

은 사양 표시 및 사양 결과는 동일한 코드 관련이없는 – apneadiving

답변

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 
+0

어떻게'StoreFronted'가'StoreAdmin :: DashboardController'를 수정합니까? 이 방법은'경로 일치 없음 {: action => "index", : controller => "store_admin/dashboard"}'를 어떻게 수정합니까? –

+0

다음을 확인하십시오 : http://stackoverflow.com/questions/5200654/how-do-i-write-a-rails-3-1-engine-controller-test-in-rspec – Karan

+0

감사합니다. 'use_route'가 나를위한 UrlGenerationError 문제입니다. –

3

구성하고 StoreFrontend에 대한하지만 오류가 StoreAdmin::DashboardController입니다 보여 스펙. 그래서 당신은 당신이 테스트하고있는 엔진과/또는 어떤 엔진이 실패하고 있는지 혼란스러워하고있는 것처럼 보입니다. 물론

간단한 해결책이 누락 된 경로 {:action=>"index", :controller=>"store_admin/dashboard"}

2

라우팅 RSpec에와 레일 엔진 컨트롤러를 테스트 할 때, 나는 일반적으로 다음 코드를 추가 올바른 내 spec_helper.rb :

RSpec.configure do |config| 
    config.before(:each, :type => :controller) { @routes = YourEngineName::Engine.routes } 
    config.before(:each, :type => :routing) { @routes = YourEngineName::Engine.routes } 
end 
관련 문제