Trying to run unit test in a new rails 3 project. When I follow instructions recommended by ruby on rails guides page (http://guides.rubyonrails.org/testing.html) I get the following: ruby test/unit/schedule_weekly_test.rb <internal:lib/rubygems/custom_require>:29:in `require'': no such file to load -- test_helper (LoadError) 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-12 17:49 UTC
Re: can''t run unit tests, not even with "ruby -I test"
Ben Porterfield wrote in post #960978:> Trying to run unit test in a new rails 3 project.RSpec''s a lot nicer; I''d recommend that instead. But...> When I follow > instructions recommended by ruby on rails guides page > (http://guides.rubyonrails.org/testing.html)How are you following those instructions? I think that page recommends using the rake tasks, not running the tests as you''ve indicated.> I get the following: > > ruby test/unit/schedule_weekly_test.rb > <internal:lib/rubygems/custom_require>:29:in `require'': no such file to > load -- test_helper (LoadError) > > 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. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Nov-12 21:33 UTC
Re: Re: can''t run unit tests, not even with "ruby -I test"
On 12 November 2010 17:49, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Ben Porterfield wrote in post #960978: >> Trying to run unit test in a new rails 3 project. > > RSpec''s a lot nicer; I''d recommend that instead. But... > >> When I follow >> instructions recommended by ruby on rails guides page >> (http://guides.rubyonrails.org/testing.html) > > How are you following those instructions? I think that page recommends > 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) Colin> >> I get the following: >> >> ruby test/unit/schedule_weekly_test.rb >> <internal:lib/rubygems/custom_require>:29:in `require'': no such file to >> load -- test_helper (LoadError) >> >> After much googling, everyone seems to recommend that the ''fix'' is to >> run a test like so: >> >> ruby -I test test/unit/whatever.rb-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-12 21:55 UTC
Re: Re: can''t run unit tests, not even with "ruby -I test"
Colin Law wrote in post #961100:> On 12 November 2010 17:49, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > 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)I just looked. It seems to only show -I.> > ColinBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Nov-12 22:11 UTC
Re: Re: Re: can''t run unit tests, not even with "ruby -I test"
On 12 November 2010 21:55, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #961100: >> On 12 November 2010 17:49, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> 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) > > I just looked. It seems to only show -I. >From http://guides.rubyonrails.org/testing.html#running-tests 3.2 Running Tests Running a test is as simple as invoking the file containing the test cases through Ruby: $ cd test $ ruby unit/post_test.rb Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Nov 12, 2010 at 8:53 AM, Ben Porterfield <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Trying to run unit test in a new rails 3 project. When I follow > instructions recommended by ruby on rails guides page > (http://guides.rubyonrails.org/testing.html) I get the following: > > ruby test/unit/schedule_weekly_test.rb > <internal:lib/rubygems/custom_require>:29:in `require'': no such file to > load -- test_helper (LoadError) > > 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? >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.> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ben Porterfield
2010-Nov-13 03:32 UTC
Re: can''t run unit tests, not even with "ruby -I test"
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. Any other ideas? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ben Porterfield
2010-Nov-13 21:21 UTC
Re: can''t run unit tests, not even with "ruby -I test"
Update. 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-13 22:24 UTC
Re: can''t run unit tests, not even with "ruby -I test"
Ben Porterfield wrote in post #961247:> Update. > > 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. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ben Porterfield
2010-Nov-13 22:35 UTC
Re: can''t run unit tests, not even with "ruby -I test"
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Nov-14 01:36 UTC
Re: can''t run unit tests, not even with "ruby -I test"
Ben Porterfield wrote in post #961261:> 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.Just use namespaces properly! Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.