ruby-on-rails - 在不调用开发环境的情况下运行 Rails 测试的正确方法是什么?

标签 ruby-on-rails testing environment

我有一个 Rails 应用程序,其中包含一些必须在应用程序以开发模式运行时执行的初始化代码。但是,在运行测试时不得执行此初始化程序代码。

我已经确定了

$ rake test

使应用程序在开发模式下运行,这会调用初始化程序代码并因此中断我的测试。这显然是预期的行为(请参阅:https://github.com/rails/rails/issues/9801)。

在不以开发模式启动应用程序的情况下运行我的 Rails 应用程序测试的正确命令是什么?

最佳答案

你的 test_helper.rb 文件看起来像 default 吗? ?它应该以:

ENV["RAILS_ENV"] = "test"

关于ruby-on-rails - 在不调用开发环境的情况下运行 Rails 测试的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501486/

相关文章:

ruby-on-rails - 将变量从 Controller 传递到局部 View rails

ruby-on-rails - 如何从 Controller stub 参数?

node.js - Node js : I to get the output of an (child) exec and set a variable to be retuned?

javascript - 如何在 Protractor 中的 ng-repeat 中使用 isElementPresent/isPresent?

spring - 当我尝试 Autowiring 时环境为空

ruby-on-rails - OmniAuth::NoSessionError - 您必须提供 session 才能使用 OmniAuth。 (在设计中配置)

ruby-on-rails - 将 redirect_to 格式更改为 :js in Rails

python - IronPython windows 7 python路径

php - GMail SMTP 测试邮件发送失败

php - mysqli_fetch_assoc()需要参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误?