A recent discussion here has brought konacha, an engine for testing JavaScript code, to my attention. In the meantime, I have extracted common code from several applications into an engine and there I would like to add some tests for the scripts. With current versions of Rails, when I create an engine with $ rails new plugin my_engine --mountable among all the other niceties I get is an dummy application for testing purposes in test/dummy. Unfortunately, things are not set-up properly for testing. Dependencies specified in my_engine.gemspec are not loaded, or if they are they are loaded too late. As a consequence, the asset paths from the jquery-rails engine are not added to the dummy application''s asset paths. In order to get those engines loaded at the right time, I need to add explicit requires in test/dummy/config/application.rb, just below the generated require "my_engine". Ideally, none of these requires would be necessary and Bundler.require (that''s already there) would automatically load all dependencies from the enclosing engine''s gemspec. For the specific case of konacha that still would not be enough (on top of this, it needs to set different additional asset paths, then when in an app environment), but it would be a good start. Michael -- Michael Schuerig mailto:michael@schuerig.de http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On 11 June 2012 19:10, Michael Schuerig <michael.lists@schuerig.de> wrote:> > A recent discussion here has brought konacha, an engine for testing > JavaScript code, to my attention. In the meantime, I have extracted > common code from several applications into an engine and there I would > like to add some tests for the scripts. > > With current versions of Rails, when I create an engine with > > $ rails new plugin my_engine --mountable > > among all the other niceties I get is an dummy application for testing > purposes in test/dummy. Unfortunately, things are not set-up properly > for testing. Dependencies specified in my_engine.gemspec are not loaded, > or if they are they are loaded too late. As a consequence, the asset > paths from the jquery-rails engine are not added to the dummy > application''s asset paths. > > In order to get those engines loaded at the right time, I need to add > explicit requires in test/dummy/config/application.rb, just below the > generated require "my_engine". Ideally, none of these requires would be > necessary and Bundler.require (that''s already there) would automatically > load all dependencies from the enclosing engine''s gemspec. >I believe you can also add the dependancies to the Gemfile of the engine. In fact, I think jquery-rails is specified in the Gemfile but commented out. I''m not saying this is ideal or anything, but I think that''s the "accepted" way to get it working. Jeremy> > For the specific case of konacha that still would not be enough (on top > of this, it needs to set different additional asset paths, then when in > an app environment), but it would be a good start. > > Michael > > -- > Michael Schuerig > mailto:michael@schuerig.de > http://www.schuerig.de/michael/ > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Schuerig
2012-Jun-11 19:55 UTC
Re: Engines in engines: not loaded in dummy test app
On Monday 11 June 2012, Jeremy Walker wrote:> On 11 June 2012 19:10, Michael Schuerig <michael.lists@schuerig.de>wrote:> > A recent discussion here has brought konacha, an engine for testing > > JavaScript code, to my attention. In the meantime, I have extracted > > common code from several applications into an engine and there I > > would like to add some tests for the scripts. > > > > With current versions of Rails, when I create an engine with > > > > $ rails new plugin my_engine --mountable > > > > among all the other niceties I get is an dummy application for > > testing purposes in test/dummy. Unfortunately, things are not > > set-up properly for testing. Dependencies specified in > > my_engine.gemspec are not loaded, or if they are they are loaded > > too late. As a consequence, the asset paths from the jquery-rails > > engine are not added to the dummy application''s asset paths. > > > > In order to get those engines loaded at the right time, I need to > > add explicit requires in test/dummy/config/application.rb, just > > below the generated require "my_engine". Ideally, none of these > > requires would be necessary and Bundler.require (that''s already > > there) would automatically load all dependencies from the > > enclosing engine''s gemspec. > > I believe you can also add the dependancies to the Gemfile of the > engine. In fact, I think jquery-rails is specified in the Gemfile > but commented out. I''m not saying this is ideal or anything, but I > think that''s the "accepted" way to get it working.Yes, I can do that and now I did. What I didn''t expect is that gems specifified in the Gemfile are treated differently than those specified in the gemspec. Gems from the gemspec are not automatically required, while those from the Gemfile are (unless the require: false option is used). As far as Rails concerned, case closed. Thanks! Michael -- Michael Schuerig mailto:michael@schuerig.de http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2012-Jun-11 21:21 UTC
Re: Engines in engines: not loaded in dummy test app
Em 11-06-2012 15:10, Michael Schuerig escreveu:> ... > In order to get those engines loaded at the right time, I need to add > explicit requires in test/dummy/config/application.rb, just below the > generated require "my_engine". Ideally, none of these requires would be > necessary and Bundler.require (that''s already there) would automatically > load all dependencies from the enclosing engine''s gemspec.What I usually do to work around such issues is to explicitly require the required gems in my Engine main file: https://github.com/rosenfeld/oojs/blob/master/lib/oojs.rb -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2012-Jun-11 21:23 UTC
Re: Engines in engines: not loaded in dummy test app
Em 11-06-2012 18:21, Rodrigo Rosenfeld Rosas escreveu:> Em 11-06-2012 15:10, Michael Schuerig escreveu: >> ... >> In order to get those engines loaded at the right time, I need to add >> explicit requires in test/dummy/config/application.rb, just below the >> generated require "my_engine". Ideally, none of these requires would be >> necessary and Bundler.require (that''s already there) would automatically >> load all dependencies from the enclosing engine''s gemspec. > > What I usually do to work around such issues is to explicitly require > the required gems in my Engine main file: > > https://github.com/rosenfeld/oojs/blob/master/lib/oojs.rbAs you can see, just setting the gem dependency in the gemspec is not enough for automatically requiring them: https://github.com/rosenfeld/oojs/blob/master/oojs.gemspec -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Michael Schuerig
2012-Jun-11 22:09 UTC
Re: Engines in engines: not loaded in dummy test app
On Monday 11 June 2012, Rodrigo Rosenfeld Rosas wrote:> Em 11-06-2012 15:10, Michael Schuerig escreveu: > > ... > > In order to get those engines loaded at the right time, I need to > > add explicit requires in test/dummy/config/application.rb, just > > below the generated require "my_engine". Ideally, none of these > > requires would be necessary and Bundler.require (that''s already > > there) would automatically load all dependencies from the > > enclosing engine''s gemspec. > > What I usually do to work around such issues is to explicitly require > the required gems in my Engine main file: > > https://github.com/rosenfeld/oojs/blob/master/lib/oojs.rbThat''s another way, but you wouldn''t want to use it for development dependencies. Say you''re using capybara-wekbit for testing your engine, you still don''t want to have it as a runtime dependency. Michael -- Michael Schuerig mailto:michael@schuerig.de http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2012-Jun-12 00:10 UTC
Re: Engines in engines: not loaded in dummy test app
Em 11-06-2012 19:09, Michael Schuerig escreveu:> On Monday 11 June 2012, Rodrigo Rosenfeld Rosas wrote: >> Em 11-06-2012 15:10, Michael Schuerig escreveu: >>> ... >>> In order to get those engines loaded at the right time, I need to >>> add explicit requires in test/dummy/config/application.rb, just >>> below the generated require "my_engine". Ideally, none of these >>> requires would be necessary and Bundler.require (that''s already >>> there) would automatically load all dependencies from the >>> enclosing engine''s gemspec. >> What I usually do to work around such issues is to explicitly require >> the required gems in my Engine main file: >> >> https://github.com/rosenfeld/oojs/blob/master/lib/oojs.rb > That''s another way, but you wouldn''t want to use it for development > dependencies. Say you''re using capybara-wekbit for testing your engine, > you still don''t want to have it as a runtime dependency.Sure, that doesn''t apply for development dependencies. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.