[rspec-users] Autotest and subclasses / namespaces

Ben Mabey ben at benmabey.com
Sat Aug 16 15:32:04 EDT 2008


Matt Wynne wrote:
> I am writing a controller admin/cities_controller.rb
>
> it inherits from AdminController, so it's defined like
>
> class Admin::CitiesController > AdminController
>
> Whenever I save the controller file, autotest freaks out:
>
> uninitialized constant Admin::AdminController (NameError)
>
> I'm pretty used to just hitting CTRL-C to get autotest to re-load all
> the files, or flicking to the spec file, and saving it to get a
> similar effect.
>
> But it is fairly irritating.
>
> Any suggestions for how to hack autotest to get this to flow more nicely?


Hmm... I am using namedspaced controllers on my current project and I am
not running into those issues.  I am using rspec edge, ZenTest 3.9.1,
and rails 2.1.0.

Have you copied your code exactly in your original email?  If so, I
might see a difference in how we are doing things and that might be your
problem.
My base controller is also namedspaced.. So in my app/controllers/admin
dir I have the following:

base_contoller.rb:
module Admin
  class BaseController < ::ApplicationController
  ....
  end
end

Then:

other_controller.rb:
module Admin
  class OtherController < BaseController
    ...
  end
end

Note that I could also do:

base_contoller.rb:
class Admin::BaseController < ApplicationController

other_controller.rb:
class Admin::OtherController < Admin::BaseController




So.. If your AdminController is namespaced you should change your other
controllers to:
class Admin::CitiesController < Admin::AdminController

If it is not namespaced (but, it really should be IMO) then you could
try this:
class Admin::CitiesController < ::AdminController

Hope that helps,
Ben


More information about the rspec-users mailing list