Hi again Trey -

Yeah, you'll definitely need to modify the line copied from Rails'
main test_helper so that it does actually point to the main
environment.rb file - I should've spotted that earlier! If you have
RAILS_ROOT/vendor/plugins/my_plugin/test/test_helper.rb, it should
contain

require File.expand_path(File.dirname(__FILE__) +
"/../../../../config/environment")

You might need to double-check that, but that should be the key. Once
this file loads, all the plugins (and in particular the engines
testing extensions) will be available.

- james

On 1/28/07, Trey Bean <[EMAIL PROTECTED]> wrote:
> Okay,  I verified that I am running the tests with the engines task
> test:plugins:units (I inserted a puts statement in
> /vendor/plugins/engines/tasks/engines.rake and it was
> outputted).
>
> I then have two files in /vendor/plugins/tandem/test/unit/:
> page_test.rb and user_test.rb
>
> Both of these files are structured like:
>
> require File.dirname(__FILE__) + '/../test_helper'
>
> class UserTest < Test::Unit::TestCase
>   #some test methods
> end
>
> I have verified that
> /vendor/plugins/tandem/test/test_helper.rb is getting
> called by placing puts $LOAD_PATH at the very top of the file.
>
> It outputs:
>
> lib
> /usr/local/lib/ruby/site_ruby/1.8
> /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.5.2
> /usr/local/lib/ruby/site_ruby
> /usr/local/lib/ruby/1.8
> /usr/local/lib/ruby/1.8/i686-darwin8.5.2
> .
>
> Below the $LOAD_PATH put, my test_helper.rb has:
>
> #ENV["RAILS_ENV"] = "test"
> #require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
> require 'test/unit'
> require File.dirname(__FILE__) +
> '/../lib/authenticated_test_helper'
> include AuthenticatedTestHelper
>
> The top two lines are commented out because if they aren't, then I get the
> error:
>
> ./vendor/plugins/tandem/test/unit/../test_helper.rb:5:in
> `require': no such file to load --
> /Users/treybean/Sites/project/vendor/plugins/tandem/config/environment
> (LoadError)
>         from
> ./vendor/plugins/tandem/test/unit/../test_helper.rb:5
>         from
> ./vendor/plugins/tandem/test/unit/page_test.rb:1
>         from
> /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5
>         from
> /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5
> rake aborted!
> Command failed with status (1): [/usr/local/bin/ruby -Ilib
> "/usr/local/lib/...]
>
>
> And if I put Engines:: Testing.set_fixture_path on line 2 (just below the
> LOAD_PATH line), I get this error:
>
> ./vendor/plugins/tandem/test/unit/../test_helper.rb:2:
> uninitialized constant Engines (NameError)
>         from
> ./vendor/plugins/tandem/test/unit/page_test.rb:1
>         from
> /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5
>         from
> /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5
> rake aborted!
> Command failed with status (1): [/usr/local/bin/ruby -Ilib
> "/usr/local/lib/...]
>
>
> Man, I feel like I'm so close, but either Rails or Engines (more likely
> both) isn't being initialized prior to the tests.  Maybe the line
>
> require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
>
> needs to be modified to actually point at the config/environment in the main
> application, rather than looking for it in my engine?
>
> Does this shed any light on what might be going on here?
>
> Thanks for you help on this.  I am so excited to get this last piece in
> place.  It looks like you've done some great work here.
>
> Trey
>
> On 1/27/07, James Adam <[EMAIL PROTECTED]> wrote:
> >
> > Hi Trey,
> >
> > On 1/27/07, Trey Bean <[EMAIL PROTECTED]> wrote:
> > > 1). Fixtures don't seem to be loading.  I read in the docs that I need
> to
> > > call Engines::Testing.set_fixture_path first, but a) I couldn't get it
> to
> > > recognize Engines, and b) it looks like the rake plugins:units task does
> > > this for me—I think.
> >
> > The provided rake tasks will call
> > Engines::Testing.setup_plugin_fixtures , but you need to call
> > Engines::Testing.set_fixture_path yourself in your tests to redirect
> > Test::Unit to the new temporary fixture directory.
> >
> > However, more troubling is the fact that your code doesn't find the
> > engines plugin. Are you running the tests with the supplied rake
> > tasks, or manually (i.e. ruby /path/to/my/test.rb)?
> >
> > > 2).  I had a file in my engine's lib folder that I need to include.  I
> > > couldn't get it to include normally.  I ended up getting it to work
> with:
> > >
> > > require File.dirname(__FILE__) +
> > > '/../lib/authenticated_test_helper'
> > > include AuthenticatedTestHelper
> > >
> > > where I used to be able to call include AuthenticatedTestHelper by
> itself.
> > > Are files in lib not automatically loaded?
> >
> > I believe a change in the way that Rails works means that some classes
> > aren't automagically loaded when they are referenced. Lib directories
> > are certainly available in the load path (you can check this yourself
> > by puts-ing $LOAD_PATH at the top of your tests), so a simple "require
> > 'file'" should be sufficient. Again - this seems like it might be
> > related to your not being able to reference the Engines module.
> >
> > > 3).  In my original test_helper.rb there is the TestCase section, where
> you
> > > set certain options like self.use_transactional_fixtures,  I was unable
> to
> > > get this to work.  So, right now, I've commented them out.
> > >
> > >
> > > 4).  What requires should be where?  In the original files, there's
> > >
> > > ENV["RAILS_ENV"] = "test"
> > > require File.expand_path(File.dirname(__FILE__) +
> "/../config/environment")
> > > require 'test_help'
> > >
> > > in test_helper.rb - Do these still need to be in my engine's
> test_helper.rb?
> >
> > If your tests require the Rails environment to be loaded, yes.
> >
> > Actually, this might relate to a possible source of problems - you
> > won't be able to work with any of the engines functionality until you
> > load the rails environment (and so all the plugins) - are you trying
> > to reference anything within any plugins before these lines?
> >
> > Does any of the above help?
> >
> > --
> > * J *
> >   ~
> > _______________________________________________
> > engine-users mailing list
> > [email protected]
> >
> http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
> >
>
>
> _______________________________________________
> engine-users mailing list
> [email protected]
> http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
>
>
>


-- 
* J *
  ~
_______________________________________________
engine-users mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

Reply via email to