如何抑制/禁用“高速缓存未命中”在 Rails 3.1 中运行 rspec 测试时的消息

发布于 2024-12-08 07:03:29 字数 216 浏览 0 评论 0原文

运行 request rspec 规范时,我开始看到以下输出:

cache: [GET /login] miss
cache: [GET /javascripts/jquery.min.js?1317513028] miss

通常,我会得到绿点表示通过测试,得到红色 F 以及一些错误消息信息。

有没有办法禁用输出中的缓存未命中消息?

I'm starting to see the following output when running request rspec specs:

cache: [GET /login] miss
cache: [GET /javascripts/jquery.min.js?1317513028] miss

Normaly I would get green dots for passing tests and red Fs with some info for error messages.

Is there a way to disable the cache miss messages from the output?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抚你发端 2024-12-15 07:03:29

我认为这与 rspec 无关,rspec 只是打印出 Rails 日志中的内容。我认为 Phusion Passenger 讨论组中 Brian Weaver 发布的帖子可能会给出答案你的问题:

您安装了机架缓存吗?我花了美好的一天+追踪乘客/轨道/机架和许多其他宝石,以找出为什么会出现与该线路类似的线路。
将以下内容添加到 Production.rb 或development.rb 文件中以删除“cache: ....”行

config.action_dispatch.rack_cache = {:metastore =>; “rails:/”,:entitystore => “rails:/”,:详细=>假}

我从 Rails 的“中间件”配置中提取了该行,只是将“详细”从 true 更改为 false。

就您而言,我想您想将其添加到您的测试环境文件中。

I think this has nothing to do with rspec and that rspec is just printing out what is in the rails log. I think this post by Brian Weaver on the Phusion Passenger discussion group might answer your question:

Do you have rack-cache installed? I spent a good day+ tracing through Passenger/Rails/Rack and lots of other gems to find out why lines similar to that one was appearing.
Add the following to your production.rb or development.rb file to get rid of the 'cache: ....' line

config.action_dispatch.rack_cache = {:metastore => "rails:/", :entitystore => "rails:/", :verbose => false}

I pulled that line from within the "middleware" configuration of Rails an just changed the 'verbose' from true to false.

In your case, I guess you want to add it your your test environment file.

夏尔 2024-12-15 07:03:29

除了 @RyanTM 之外,您还需要为测试环境打开缓存,以便 DragonFly 不会配置自己的 Rack::Cache (使用 :verbose => true),而是使用 Rails 的设置。

# set Rack::Cache verbose to false to prevent logging to rspec output         
config.action_controller.perform_caching = true                               
config.action_dispatch.rack_cache = {:metastore => "rails:/", :entitystore => "rails:/", :verbose => false}

In addition to @RyanTM you also need to turn caching on for the test environment so that DragonFly does not configure its own Rack::Cache (with :verbose => true) but instead uses the one setup by Rails.

# set Rack::Cache verbose to false to prevent logging to rspec output         
config.action_controller.perform_caching = true                               
config.action_dispatch.rack_cache = {:metastore => "rails:/", :entitystore => "rails:/", :verbose => false}
折戟 2024-12-15 07:03:29

我无法让上述任何一种解决方法为我工作,但将其添加到我的 'config/initializers/dragonfly.rb' 中有效:

if Rails.env.test?
  Rails.application.middleware.delete Rack::Cache
  Rails.application.middleware.insert 0, Rack::Cache, {
    :verbose     => false,
    :metastore   => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
    :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
  }
end

I couldn't get either of the above workarounds to work for me, but adding this to my 'config/initializers/dragonfly.rb' worked:

if Rails.env.test?
  Rails.application.middleware.delete Rack::Cache
  Rails.application.middleware.insert 0, Rack::Cache, {
    :verbose     => false,
    :metastore   => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
    :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
  }
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文