Mountable Engine/App: gems from .gemspec not available in dummy app when started with "rails console/server"

I'm building a Rails 3.1 mountable engine (3.1.0.rc6) whose sole
purpose is to provides JavaScript assets (a client-side app built with
backbone.js). I generated the skeleton with "rails plugin new <name> --
full"

Piotr's posts have been very helpful, as has the Railscast on the
subject:
http://piotrsarnacki.com/2010/09/14/mountable-engines/
http://piotrsarnacki.com/2010/12/21/mountable-apps-tutorial/
http://railscasts.com/episodes/277-mountable-engines/

I'm specifying a number of dependencies in the .gemspec file:

  s.add_dependency "rails", "~> 3.1.0.rc6"
  s.add_dependency "jquery-rails", "~> 1.0.13"
  s.add_dependency "backbone-rails", "~> 0.5.2"

  s.add_dependency "coffee-rails", "~> 3.1.0.rc6"
  s.add_dependency "sass-rails", "~> 3.1.0.rc6"
  s.add_dependency "uglifier", "~> 1.0.1"

  # Needed to run test suite(s) or development server (which will
serve the app in spec/dummy)
  s.add_development_dependency "sqlite3", "~> 1.3.4"
  s.add_development_dependency "jasmine", "~> 1.1.0.rc3" # not getting
picked up?
  s.add_development_dependency "rspec-rails", "~> 2.6.1" # not
getting picked up?
  s.add_development_dependency "haml", "~> 3.1.2" # not getting
picked up?

The Gemfile looks like this:

  source "http://rubygems.org"
  gemspec

When I run the "rails s" or "rails c" to launch the dummy app, e.g.
the HAML gem is not available. If I explicitly add the HAML gem also
to the engine's Gemfile, then it is available. Same goes for the
Jasmine gem (which provides rake tasks).

When I check the load path $:, I do see that all the gem paths
from .gemspec are listed, however they don't seem to have been
require'd.

I'm wondering if this is a Rails bug. Somehow the gems listed
in .gemspec only aren't being initialized/loaded. I'm happy to dig
into this more, but I'm not sure if this is broken or intended
behavior.

Thanks,
Wolf

A short guess: Something is not calling “Bundler.require(Rails.env, :default)” as what would normally happen in Rails, like in the default config/application.rb. Does putting this line in your engine.rb make it work?

I'm having the same sort of problem, I have a mountable engine that
provides Javascript assets, but while I try testing AJAX calls
(provided by the Javascript I just mentioned) in Capybara and Spec.
The database doesn't seem to update.

Because of the cluster nature of testing, I can't have a clear
understanding of what exactly is being run and loaded on the Dummy
App. I was thinking about running the Dummy App as a standalone app
and verify what is being rendered via the web browser (sort of
manually checking things out). But that wasn't possible because of a
Gemfile not found error every time I try running 'rails s' within the
spec/dummy folder.

So my question: is there another way to check why the AJAX calls are
not working in my test cases(although when I run the app normally the
AJAX calls are working just fine).

Try running rails s from the root of the engine, rather than from within spec/dummy itself. There’s a script/rails file within the root of the engine that will make this possible.

I will be sure to mention this in the in-progress engines guide. https://github.com/lifo/docrails/blob/master/railties/guides/source/engines.textile

I'm having a similar problem. I have an engine with these in
the .gemspec file:

  s.add_dependency "rails", "~> 3.1.0"
  s.add_dependency "haml-rails" # <-- Doesn't seem to be seen in
dummy app?
  s.add_dependency "sass-rails"
  s.add_dependency "jquery-rails"

  s.add_development_dependency "rspec-rails", "~> 2.6.1"
  s.add_development_dependency "capybara"
  s.add_development_dependency "vcr", "~> 1.6.0"
  s.add_development_dependency "webmock", "~> 1.6.2"

In the dummy app I tried adding this to application.html.erb:

  = render :partial => 'passport/shared/topbar'

In my engine the file is located in "app/views/passport/shared/
_topbar.html.haml"

When I run rails s (from the engine root, not the dummy app root) I
get this error:

Missing partial passport/shared/topbar with
{:handlers=>[:erb, :builder], :formats=>[:html], :locale=>[:en, :en]}.
Searched in:
  * "/Users/nbenes/projects/passport/spec/dummy/app/views"
  * "/Users/nbenes/projects/passport/app/views"

It looks like it's only running erb, and not haml, do you know what
I'm doing wrong? =/