rails/rails — Issue #4364: Tests failing for helpers (and possibly views) when run within a mountable engine.
Author: t3hpr1m3
Created: 2012-01-06 21:08:15+00:00
State: open

I have an app that is a namespaced, mountable engine. When writing specs for helpers, none of the named route helpers are available within the helpers themselves. For example:

```ruby
module Booker
module BookHelper
def new_book_link(book)
link_to book.title, new_book_path(book)
end
end
end
```

Yes, the example is rediculous, but should illustrate my point. When running tests within the engine, it appears that view/helper specs use an instance of **ActionView::TestCase::TestController** for the environment. Since the standard way of testing engines these days is with an embedded dummy app, it appears that when *new_book_path* above is run from the test suite, *new_book_path* must exist in the dummy app's routes, which it won't.

To prove this, changing *new_book_path* above to *booker.new_book_path* causes the test to pass (but fail at runtime).

My solution to this thus far has been to add:

```ruby
ActionView::TestCase::TestController.send :include, Booker::Engine.routes.url_helpers
```

to my test suite's helper file.

I apologize for poorly explaining the problem, but hopefully the monkeypatch might point someone to a more permanent fix.