Cynthia Kiser
2008-May-12 23:17 UTC
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:in `require'' 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:in `new_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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cynthia Kiser 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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian Hartin
2009-Jan-20 21:15 UTC
Re: Require factory fails if I am not using rake to run tests
Phlip wrote:> Cynthia Kiser 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. > > -- > PhlipWhy 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. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---