0

在我们应用程序的 config/environments/development.rb 我们有

Rails.application.configure do
  # ...
  if ENV['REDIS_URL']
    config.cache_store = :redis_store, ENV['REDIS_URL'], { expires_in: 90.minutes }
  end
end

在 config/environments/test.rb 中:

Rails.application.configure do
  # ...
  config.cache_store = :null_store
end

我们在应用程序中使用了一些后台进程方法,例如:

class UserMailer < ApplicationMailer
  # stuff
end

# ...and elsewhere:

class ProfilesController < ApplicationController
  # stuff
  def amend_confirmation
    # more stuff
    UserMailer.increased_pledge(amendment).deliver_later
  end
end

当这在测试中遇到时,如果我没有主动让 Redis 在后台运行(这似乎很难安排并且在我们的 CI 环境中设置可能有问题),我会收到错误

Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)

目前我将通过模拟/测试 Deliver_later 消息来解决这个问题,但我怀疑这不是一个很好的功能测试策略,因为它显然不是用户将要做的事情。有更好的方法吗?

4

0 回答 0