代码之家  ›  专栏  ›  技术社区  ›  Tek

TypeError:ActiveSupport不是类

  •  2
  • Tek  · 技术社区  · 7 年前

    我有一个新的rails 5.0.4项目(ruby 2.3.4p301(2017-03-30修订版58214)[x86\u 64-darwin15]),在运行我的第一个minitest pass时遇到了一个问题。

    bin/rails test
    

    错误

    TypeError: ActiveSupport is not a class
    <sanatized>/ps/tekkedout-dnd-tools/test/test_helper.rb:5:in `<top (required)>'
    <sanatized>/.rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `require'
    <sanatized>/.rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `block in require'
    <sanatized>/.rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:259:in `load_dependency'
    <sanatized>/.rvm/gems/ruby-2.3.4/gems/activesupport-5.0.4/lib/active_support/dependencies.rb:293:in `require'
    <sanatized>/ps/tekkedout-dnd-tools/test/models/spell_test.rb:1:in `<top (required)>'
    

    test_helper.rb

    ENV["RAILS_ENV"] ||= "test"
    require File.expand_path("../../config/environment", __FILE__)
    require "rails/test_help"
    
    class ActiveSupport
      class TestCase
        # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
        fixtures :all
    
        # Add more helper methods to be used by all tests here...
      end
    end
    

    使现代化

    区别如下:

    -class ActiveSupport::TestCase
    -  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
    -  fixtures :all
    +class ActiveSupport
    +  class TestCase
    +    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
    +    fixtures :all
    
    -  # Add more helper methods to be used by all tests here...
    +    # Add more helper methods to be used by all tests here...
    +  end
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Mate Solymosi    7 年前

    ActiveSupport 不是一个班级 但是 单元

    ActiveSupport.class
    #=> Module
    

    修补 ActiveSupport::TestCase 同学们,试试这个:

    module ActiveSupport
      class TestCase
        # ...
      end
    end
    
        2
  •  0
  •   hoffm    7 年前

    我认为你想要的是:

    class ActiveSupport::TestCase
      [...]
    end
    

    ActiveSupport 是一个 ,不是一个类。它在这里被用作 TestCase 班下面是中的相关代码位 active_support https://github.com/rails/rails/blob/v5.0.2/activesupport/lib/active_support/test_case.rb#L14