Update (2013-10-31)
RSpec 2.14 now fully supports machine routes :
module MyEngine describe ExampleController do routes { MyEngine::Engine.routes } end end
Add it to all routing specifications:
# spec/spec_helper.rb config.include Module.new { def self.included(base) base.routes { Reportr::Engine.routes } end }, type: :routing
The best solution I could find explicitly defines the set of routes that will be used during the tests:
RSpec.configure do |config| config.before(:each, type: :controller) { @routes = Licensing::Engine.routes } config.before(:each, type: :routing) { @routes = Licensing::Engine.routes } end
Then I had to rewrite my routing examples to omit the namespace:
it 'routes to #index' do get('/licenses').should route_to('licensing/licenses#index') end
It seems a bit hacky, but it makes sense. I do not check if Rails can mount the engine in a specific way. I am only testing that my engine correctly configured its own routes. However, I would prefer not to rewrite the instance variable for this to happen.
Here are a couple of good topics on this topic:
- How to test routes in a Rails 3.1 mounted engine
- How to write a Rails 3.1 engine controller test in rspec?
Brandan
source share