James Adam
2006-Jul-22 16:02 UTC
test:plugins task dependency on :environment is pointless, surely?
Hello all, I''ve been doing quite a bit of rooting around the plugin system recently, and one thing in particularly has me puzzled and bemused. At the moment, the test:plugins task has a dependency on the :environment task, thus loading up Rails in all it''s resplendent glory. Once it''s done this it uses Rake::TestTask to load the tests for every plugin. However, because of the way that Rake::TestTask works (loading a new Ruby interpreter which churns through the test cases), the Rails environment is never actually made available to any plugins. If a plugin wants to deal with ActiveRecord, it needs to explicitly load Rails itself within it''s tests. The environment isn''t even used to determine which plugin tests to run. Basically, the dependency is pointless beyond introducing a delay before starting the plugin test tasks. Any esoteric side effect of environment.rb''s evaluation shouldn''t influence plugins while they are being tested (a plugin which relies on this is badly written, IMHO). Am I missing something obvious here? - James -- * J * ~
Caio Chassot
2006-Jul-22 16:14 UTC
Re: test:plugins task dependency on :environment is pointless, surely?
On 2006-07-22, at 13:02 , James Adam wrote:> However, because of the way that Rake::TestTask works (loading a new > Ruby interpreter which churns through the test cases), the Rails > environment is never actually made available to any plugins.Really? I think my plugins'' tests need the environment, and run fine.> Am I missing something obvious here?The fact is testing plugins suck. Plugins may interact with rails on many levels. Some just alter activerecord, others need the full stack and add stuff to numerous places, so, basically, the only sure fire way to test a plugin is to test it within an app. Right now, what I''m doing is developing my plugins inside a test app. I''m experimenting with creating the tests either inside the plugin dir, or using the app''s tests directly. That kinda sucks, though, because when I package the plugin, I won''t be packaging the test app along with it. I was wondering if it''s possible to make a tiny rails app contained within a single file, or at least a lot less files than a standard app, so that it could be placed inside the plugin test dir, and used for testing the plugin, instead of relying on the current app the plugin is installed into. But really, that was not related to your question, was it? Sorry about the rant/hijack :P
Tom Ward
2006-Jul-22 17:59 UTC
Re: test:plugins task dependency on :environment is pointless, surely?
On 22/07/06, Caio Chassot <lists@v2studio.com> wrote:> > On 2006-07-22, at 13:02 , James Adam wrote: > > > However, because of the way that Rake::TestTask works (loading a new > > Ruby interpreter which churns through the test cases), the Rails > > environment is never actually made available to any plugins. > > Really? I think my plugins'' tests need the environment, and run fine.If you require test_helper within your tests, environment will be loaded and tests will run fine. James'' point is that as well as test_helper, the rake task test:plugins also loads the environment but in a way in which it isn''t actually made available to the tests. This is unnecessary overhead. Tom
Caio Chassot
2006-Jul-22 18:35 UTC
Re: test:plugins task dependency on :environment is pointless, surely?
On 2006-07-22, at 14:59 , Tom Ward wrote:> If you require test_helper within your tests, environment will be > loaded and tests will run fine. James'' point is that as well as > test_helper, the rake task test:plugins also loads the environment but > in a way in which it isn''t actually made available to the tests. This > is unnecessary overhead.Thanks for the clarification. Indded I was requiring the test_helper in the plugin test I had in mind.