How to load all models when testing?

I do something like the following in my models:

class NoDeleteCompanyError < RuntimeError; end

class Company < ActiveRecord::Base
# model code
end

When I try to do:

assert_rais(NoDeleteCompanyError) { some_block }

It says that NoDeleteCompanyError is an uninitialized constant.

To fix this I just do fixtures :companies.

Is there anyway to default load all models when testing so I dont have
to do this?

Thanks.

assert_rais(NoDeleteCompanyError) { some_block }

It says that NoDeleteCompanyError is an uninitialized constant.

To fix this I just do fixtures :companies.

Is there anyway to default load all models when testing so I dont have
to do this?

Probably :wink: But another way would be to put your NoDeleteCompanyError
into no_delete_company_error.rb in your models directory…

Philip H. wrote:

assert_rais(NoDeleteCompanyError) { some_block }

It says that NoDeleteCompanyError is an uninitialized constant.

To fix this I just do fixtures :companies.

Is there anyway to default load all models when testing so I dont have
to do this?

Probably :wink: But another way would be to put your NoDeleteCompanyError
into no_delete_company_error.rb in your models directory…

Or it will probably work if you put the exception class inside your
model

class Model
class MyException < RuntimeError; end
end

Also, check out the all_fixtures pluign I wrote:
http://beautifulpixel.com/all_fixtures/index.html

It makes fixture management quite painless.

Ben J. wrote:

The problem I have with that is that I cant catch that specific class
outside of that model because it gives me an unititalized constant
error. That’s why I put it outside the class.

Try it inside the class, and use Company::NoDeleteCompanyError to
identify the Exception class.

assert_raise(Company::NoDeleteCompanyError) do
some_block
end

Alex W. wrote:

Philip H. wrote:

assert_rais(NoDeleteCompanyError) { some_block }

It says that NoDeleteCompanyError is an uninitialized constant.

To fix this I just do fixtures :companies.

Is there anyway to default load all models when testing so I dont have
to do this?

Probably :wink: But another way would be to put your NoDeleteCompanyError
into no_delete_company_error.rb in your models directory…

Or it will probably work if you put the exception class inside your
model

class Model
class MyException < RuntimeError; end
end

Also, check out the all_fixtures pluign I wrote:
http://beautifulpixel.com/all_fixtures/index.html

It makes fixture management quite painless.

The problem I have with that is that I cant catch that specific class
outside of that model because it gives me an unititalized constant
error. That’s why I put it outside the class.