TypeError: ActiveSupport is not a class
TypeError: ActiveSupport is not a class
大家好,在此先感谢您的反馈。
我有一个新的 rails 5.0.4 项目(ruby 2.3.4p301(2017-03-30 修订版 58214)[x86_64-darwin15]),我遇到了一个问题运行 我的第一个迷你测试通过。
命令:
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
更新
看起来在实施 rubocop 时我做了一些仓促的更改并且还没有开始我的规范。
差异如下:
-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
ActiveSupport
是 不是 class 而是 模块:
ActiveSupport.class
#=> Module
要修补 ActiveSupport::TestCase
class,试试这个:
module ActiveSupport
class TestCase
# ...
end
end
我想你想要的是:
class ActiveSupport::TestCase
[...]
end
ActiveSupport
是 模块 ,而不是 class。它在这里用作 TestCase
class 的命名空间。这是 active_support
5.0.2 中的相关代码:https://github.com/rails/rails/blob/v5.0.2/activesupport/lib/active_support/test_case.rb#L14
大家好,在此先感谢您的反馈。
我有一个新的 rails 5.0.4 项目(ruby 2.3.4p301(2017-03-30 修订版 58214)[x86_64-darwin15]),我遇到了一个问题运行 我的第一个迷你测试通过。
命令:
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
更新
看起来在实施 rubocop 时我做了一些仓促的更改并且还没有开始我的规范。
差异如下:
-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
ActiveSupport
是 不是 class 而是 模块:
ActiveSupport.class
#=> Module
要修补 ActiveSupport::TestCase
class,试试这个:
module ActiveSupport
class TestCase
# ...
end
end
我想你想要的是:
class ActiveSupport::TestCase
[...]
end
ActiveSupport
是 模块 ,而不是 class。它在这里用作 TestCase
class 的命名空间。这是 active_support
5.0.2 中的相关代码:https://github.com/rails/rails/blob/v5.0.2/activesupport/lib/active_support/test_case.rb#L14