Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Cannot require ActionDispatch SelectorAssertions

#3470

I tried to load and mix in ActionDispatch::Assertions::SelectorAssertions in my specs:

require 'action_dispatch/testing/assertions/selector'

This fails with "ActionDispatch::Assertions::SelectorAssertions is an undefined constant". Of course it's undefined; I'm trying to require a file that defines it! This weird error seemed to originate from the very second line of code in that file:

module ActionDispatch
  module Assertions # <-- this one
    ...
  end
end

Turns out, ActionDisplatch has set "Assertions" constant to autoload 'action_dispatch/testing/assertions', which in turn tries to load all its submodules, which tries to mix in ActionDispatch::Assertions::SelectorAssertions before it's even defined. The solution was to simply load the complete assertions module:

require 'action_dispatch/testing/assertions'

I have no idea how to solve this without getting rid of the autoload, but Rails 3 should make every independent component of it loadable and I think this should definitely fall under that category.

Reported by Mislav · November 9th, 2009 @ 12:00 AM

State: resolved
Milestone: 3.0.2
Assigned to: josh josh
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • Assigned user set to josh

    November 9th, 2009 @ 05:17 AM

  2. josh
    josh
    • State changed from new to open

    November 9th, 2009 @ 08:50 PM

  3. Repository
  4. josh
    josh

    Try that.

    Also, you should not be using require here. Just reference that const and let the autoload work. Requiring 'action_dispatch/testing/assertions/selector' is not "public api".

    November 10th, 2009 @ 03:39 AM

  5. Jeremy Kemper