Require factory fails if I am not using rake to run tests

I am trying to reuse some code from a Rails 1.2.6 app in edge rails.
In the old app, I can run all my tests with ‘rake’ or I can run
individual tests using ‘ruby test/functionals/foo_controller_test.rb’.
But in my edge rails app, I have to use ‘rake’. If I try to run
individual tests, I get the error below. How can include my factory
module in a way that lets me run tests via rake AND individually with
‘ruby $filename’?

/usr/bin/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require': no such file to load -- factory (MissingSourceFile) from /usr/bin/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
from
/rails/cms/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:495:in
require' from /rails/cms/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:innew_constants_in’
from
/rails/cms/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:495:in
`require’
from ./test/unit/…/test_helper.rb:5
from test/unit/user_test.rb:1

The desired Factory module is in test/factory.rb - right next to
test_helper.rb. The offending includes are:

From test/unit/user_test.rb

require File.dirname(FILE) + ‘/…/test_helper’
class UserTest < Test::Unit::TestCase

From tests/test_helper.rb

ENV[“RAILS_ENV”] = “test”
require File.expand_path(File.dirname(FILE) +
“/…/config/environment”)
require ‘test_help’
require ‘factory’
class Test::Unit::TestCase

And test/factory.rb starts

module Factory …


Cynthia

Cynthia K. wrote:

require File.expand_path(File.dirname(FILE) + “/…/config/environment”)
require ‘test_help’
require ‘factory’

I thought newer Railses reduced their file lookup paths. Use the
dirname(FILE) trick you see right above your factory!

require File.expand_path(File.dirname(FILE) + “/…/factory.rb”)

Alternately, use RAILS_ROOT, because environment.rb sets that.


Phlip

Phlip wrote:

Cynthia K. wrote:

require File.expand_path(File.dirname(FILE) + “/…/config/environment”)
require ‘test_help’
require ‘factory’

I thought newer Railses reduced their file lookup paths. Use the
dirname(FILE) trick you see right above your factory!

require File.expand_path(File.dirname(FILE) + “/…/factory.rb”)

Alternately, use RAILS_ROOT, because environment.rb sets that.


Phlip

Why does it fail to find ‘factory.rb’, though? Shouldn’t a ‘require’,
written in file A, find a co-located file B, regardless of the loadpath?

It may be desirable to avoid the RAILS_ROOT and FILE versions of
‘require’ to avoid loading the file multiple times, unnecessarily. For
example, you might get warnings about ‘redefined’ constants.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs