warning: toplevel constant XYZ referenced Admin:XYZ Options under spork

320 views
Skip to first unread message

dblock

unread,
May 6, 2011, 9:53:12 AM5/6/11
to sporkgem
This only happens under spork and doesn't happen if I run without
spork (tried rc4, rc5). It happens consistently with every run,
including first.

I got controllers in a namespace and controllers outside of the
namespace. For example, I have a PagesController and a
Admin::PagesController. I have 20+ of those.

When I run rspec under spork, I get the following warning:

warning: spec/controllers/admin/pages_controller_spec.rb:4:
warning: toplevel constant PagesController referenced by
Admin::PagesController

This makes no sense. I do have a PagesController and an
Admin::PagesController and specs for both that are declared properly.
I get this for 4 out of 20 controllers, consistently.

This causes the controller not to be loaded (?) and all controller
specs for these 4 controllers fail complaining that routes are
missing.

Any ideas?

dblock

unread,
May 25, 2011, 2:27:22 PM5/25/11
to sporkgem
Following up on my own thread. We never found the solution to this,
but found a workaround. The controller loading order is the culprit,
so loading admin controllers first helps.

Added this to spec_helper.rb.

Spork.each_run do

# warning: toplevel constant ExampleController referenced by
Admin::ExampleController
# admin controllers must load first to avoid global namespace
controllers to pollute the admin namespace
Dir[File.expand_path("app/controllers/admin/*.rb")].each do |file|
require file
end

...
end
Reply all
Reply to author
Forward
0 new messages