After much googling, everyone seems to recommend that the ‘fix’ is to
run a test like so:
ruby -I test test/unit/whatever.rb
That it’s impossible to run an autogenerated test using the method
recommended on the guides page is pretty annoying. At any rate, when I
run it with -I test, I no longer get the test_helper errors, but I get a
different one:
activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’:
no such file to load – app/models/users/user (LoadError)
I have a users folder in my model path, that I load with:
config.autoload_paths += %W(/app/model/users)
in application.rb. Any ideas for what I can do to let my tests find the
files within this folder?
After much googling, everyone seems to recommend that the ‘fix’ is to
run a test like so:
ruby -I test test/unit/whatever.rb
That it’s impossible to run an autogenerated test using the method
recommended on the guides page is pretty annoying. At any rate, when I
run it with -I test, I no longer get the test_helper errors, but I get a
different one:
activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’:
no such file to load – app/models/users/user (LoadError)
I have a users folder in my model path, that I load with:
config.autoload_paths += %W(/app/model/users)
in application.rb. Any ideas for what I can do to let my tests find the
files within this folder?
Use the Rake tasks. They should set up everything correctly. I also
highly recommend the use of Autotest.
On 12 November 2010 17:49, Marnen Laibow-Koser [email protected]
wrote:
using the rake tasks, not running the tests as you’ve indicated.
The OP is correct, section 3.2 of the guide shows tests being run
directly by ruby (without -I)
On 12 November 2010 17:49, Marnen Laibow-Koser [email protected]
wrote:
using the rake tasks, not running the tests as you’ve indicated.
The OP is correct, section 3.2 of the guide shows tests being run
directly by ruby (without -I)
On Fri, Nov 12, 2010 at 8:53 AM, Ben Porterfield [email protected]wrote:
I have a users folder in my model path, that I load with:
config.autoload_paths += %W(/app/model/users)
in application.rb. Any ideas for what I can do to let my tests find the
files within this folder?
This is a shot in the dark, but I recently upgraded an project to Rails
3
and the tests would just not run - no error, just a new command prompt
after
a pause. I solved by using the process of elimination to comment out
gems in
my gem file — I think if I remember right I found the culprit to be
‘cucumber’ (not ‘cucumber_rails’). Once I commented this my tests
started
working. And ‘cucumber’ is not necessary to run ‘cucumber_rails’, so all
ended well. So just an idea to look at your gemfile if you have added
anything.
So, Colin, you are correct, I’m reading the instructions exactly from
the rails guide. Like I said, following their instructions exactly gives
me a ridiculous error, modifying them slightly lets the test at least
try to run.
Regardless of whether I run rake test or ruby -I test test/unit/blah.rb,
I still receive the same error I’ve mentioned above - rails says:
in `require’: no such file to load – app/models/users/user (LoadError)
Strange to me that it manages to know where the model is
(app/models/users/user) but then when trying to load says ‘no such file
to load’.
David, thanks for the attempt but this is a really fresh project, all
rails 3 from the start, and without either of those gems.
On 12 November 2010 21:55, Marnen Laibow-Koser [email protected]
wrote:
Colin L. wrote in post #961100:
On 12 November 2010 17:49, Marnen Laibow-Koser [email protected]
wrote:
using the rake tasks, not running the tests as you’ve indicated.
The OP is correct, section 3.2 of the guide shows tests being run
directly by ruby (without -I)
So upon further investigation it appears as though the issue comes from
my model directory structure. I have a lot of models, so I’ve placed
some into folders (but not namespaced),
This may be your problem, but in any case, it’s terrible practice. If
you’re using directories, you should always use namespaces to match.
There’s no advantage to breaking Rails’ conventions here.
So I’m new to rails but most of what I read actually point the other way
that namespaced models are mostly broken in rails, and to never use
them. As such, I’m following a few other suggestions I’ve read to use
autoload to load models organized into subdirectories. This is the cause
of my issues, however, so I suppose I’ll pull all my models into the
models folder.
So upon further investigation it appears as though the issue comes from
my model directory structure. I have a lot of models, so I’ve placed
some into folders (but not namespaced), and auto-loaded the models using
something like:
config.autoload_paths += %W(app/models/users/)
Apparently, this works great in development, but breaks down in test or
production environments. My first question is - does anyone know why?
Although the users folder contains quite a few models, the only one that
appears to break anything is the User model. If I pull the user.rb class
up one level into app/models, not only does everything seem to run, but
I can also still access the other models that are in the
app/models/users directory. So, my second question is - why just the
users model?
So I’m new to rails but most of what I read actually point the other way
that namespaced models are mostly broken in rails, and to never use
them.
Then you’ve got bad advice.
As such, I’m following a few other suggestions I’ve read to use
autoload to load models organized into subdirectories. This is the cause
of my issues, however, so I suppose I’ll pull all my models into the
models folder.