Skip to content

NameError: undefined local variable or method 'magic_test'

Andrew Culver edited this page Mar 1, 2021 · 1 revision

Magic Test tries to automatically inject its MagicTest::Support helper into common test libraries for ease of setup, but there may be cases where we're not doing this properly. This is probably the problem if you're receiving an error like this:

NameError: undefined local variable or method `magic_test' for #<BasicsTest:0x00007f908b374a88>

If that's the case, you can still manually include MagicTest::Support support manually. How you have to do this will depend on whether you're using Minitest, RSpec, or another test library, but here are some examples of how people have accomplished this:

For Minitest, you can add the following in test/application_system_test_case.rb:

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  include MagicTest::Support if ENV["MAGIC_TEST"].present?
end

For RSpec, you can apparently add include MagicTest::Support in your test file.

Clone this wiki locally