I''ve discovered that application.rb is being loaded twice in a couple situations. It is not when simply running script/server, but it is when running script/console and specs with rspec. The first place it is always loaded is in the #to_prepare callback in dispatcher.rb, using #require_dependency. The second time it''s being loaded is simply using "require ''application''" in console_with_helpers: 19, and in rspec_on_rails/lib/spec/rails.rb:3 I don''t think it''s expected behavior that requiring ''application'' loads it a second time. Looking at the code, it appears that #require_dependency (which calls #require_or_load) has two different mechanisms: :load or :require. I''m curious if anyone knows the reasoning for this, and why :load is the default. But even if it did use #require, #require_or_load expands the path of the filename, so simply requiring application would still re-load it. I''m also wondering if #require_dependency is necessary in the dispatcher. Would simply using #require do the trick? I''m willing to pursue a patch to fix this, I just wanted to see if anyone had any insights. Thanks, Brandon
> I don''t think it''s expected behavior that requiring ''application'' loads it a > second time.No, double requiring isn''t expected.> Looking at the code, it appears that #require_dependency (which calls > #require_or_load) has two different mechanisms: :load or :require. I''m > curious if anyone knows the reasoning for this, and why :load is the > default. But even if it did use #require, #require_or_load expands the path > of the filename, so simply requiring application would still re-load it. > > I''m also wondering if #require_dependency is necessary in the dispatcher. > Would simply using #require do the trick?require_dependency has two different load mechanisms to support the reloading we do in development mode. But some of that code (including require_dependency) is so old it predates active support, and I''m sure there''s some cruft in there. Perhaps it can be simplified.> I''m willing to pursue a patch to fix this, I just wanted to see if anyone > had any insights.The correct fix is to use require_dependency ''application'' as it works with reloading. The double require is probably happening because require_dependency normalises the path. What are you doing in the console which triggers this? It''s probably a bug in rspec too.> Thanks, > Brandon >-- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I''m experiencing the same exact problem (application.rb is loaded twice when using script/console and running rspec). Using the latest stable Rails (2.1.0) and RSpec (1.1.4). I''m looking into it but have nothing helpful to contribute at the moment. This is on a project that we''re bringing up to speed after it''s been dormant for a few months. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I also have been puzzled by this. It can be reproduced in one minute: Create a fresh rails app named ''fred'': rails fred Edit apps/controller/application.rb and insert a constant: X = 2 Type: script/console --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> I''m experiencing the same exact problem (application.rb is loaded > twice when using script/console and running rspec). Using the latest > stable Rails (2.1.0) and RSpec (1.1.4). I''m looking into it but have > nothing helpful to contribute at the moment. This is on a project that > we''re bringing up to speed after it''s been dormant for a few months.http://github.com/rails/rails/commit/292501c7e01993faadfd953fd1b3154c470b65e2 That was easy :). Does this fix it for everyone here? -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
It fixes it in script/console but not when I run rake spec. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
That sounds like an rspec problem. Is there a require ''application'' somewhere in their source? On Fri, Jul 11, 2008 at 10:36 PM, randy <randy.j.parker@gmail.com> wrote:> > It fixes it in script/console but not when I run rake spec. > > >-- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, the same line does appear in rspec-rails/lib/spec/rails.rb And when I make Koz''s fix, it does fix it for "rake spec" Thanks!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Jul 11, 2008 at 10:48 PM, randy <randy.j.parker@gmail.com> wrote:> > Yes, the same line does appear in rspec-rails/lib/spec/rails.rb > And when I make Koz''s fix, it does fix it for "rake spec"awesome. Remember to submit it upstream :) -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 11, 2008, at 4:50 PM, Michael Koziarski wrote:> On Fri, Jul 11, 2008 at 10:48 PM, randy <randy.j.parker@gmail.com> > wrote: >> >> Yes, the same line does appear in rspec-rails/lib/spec/rails.rb >> And when I make Koz''s fix, it does fix it for "rake spec" > > awesome. Remember to submit it upstream :)http://rspec.lighthouseapp.com/projects/5645/tickets/440-before-filter-are-executed-twice Thanks Koz. Brandon