Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Rails engine rspec controller test not work

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

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

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

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?

UPDATE 1: My application structure:

bin/
config/
db/
lib/
log/
public/
tmp/
engine1/
engine2/
engine3/
like image 621
Zeck Avatar asked Nov 30 '22 04:11

Zeck


1 Answers

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
like image 97
Zeck Avatar answered Dec 06 '22 06:12

Zeck