是否应该在测试环境中打开或关闭预先加载?

时间:2015-03-11 17:54:25

标签: ruby-on-rails testing rspec

这是标准的test.rb:

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false

此建议是否适用于运行整个测试套件,或仅适用于运行单个测试?

如何决定是打开还是关闭?

在运行单个测试时是否有一个漂亮的配方让它变为假,而在运行整个套件时是否为真?

(我怀疑我得到的某些类型的错误是关闭的结果)

1 个答案:

答案 0 :(得分:0)

每次测试都需要提前加载,因此即使您运行整个测试套件也要进行扩展。

通常,注释中引用的工具是测试工具(如水豚),非常需要将eager_loading加载到true,否则会丢失常量错误。

如果您需要将eager_loading设置为false来运行某些测试,而将其他true设置为# config/environments/test.rb config.eager_load = !!(ENV['ENABLE_SPRING'] == 'true') 时可以运行以下测试:

$ ENABLE_SPRING=true bundle exec rspec spec/test_name.rb

您可以像这样运行那批特定的测试

{{1}}

来源:个人经历+ https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-in-the-test-environment