views:

16

answers:

1

How do I get Rails to load my lib folder during tests?? Rails 2.3.8. I have this:

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

require "ruby-debug"
gem 'test-unit'
require "test/unit"
require 'active_support'
require 'active_support/test_case'
require 'active_record'
require 'active_record/fixtures'
require 'shoulda'
require 'shoulda/active_record'
require 'test_help'
require 'shoulda'

ActiveSupport::Dependencies.load_paths << File.join(Rails.root, 'lib')

class ActiveSupport::TestCase
  fixtures :all
end

But then if I have something like acts_as_x in a model, and acts_as_x is defined in Rails.root/lib/*, and I run rake test:units, it throws an error. Here's a test skeleton:

require 'test_helper'
class BusinessTest < ActiveSupport::TestCase
  # ...  
end

What am I missing here? Thanks so much.

A: 

You need made the require of file to implement your act_as_x. If you don't made, you can't have this feature.

The autoloading in Rails works only with Class or Module doesn't already define and require the file if not. But Rails can't know with file require by a act_as.

shingara