【问题标题】:how do i print the description of every rspec to the Rails.logger?如何将每个 rspec 的描述打印到 Rails.logger?
【发布时间】:2013-01-17 04:26:14
【问题描述】:

我想在调试期间在 Rails 日志中显示每个示例的描述。我不太清楚这是怎么做到的。我看过使用 RSpec.configure 做这样的事情:

RSpec.configure do |config|
  config.before(:each) do |example|
    Rails.logger.debug example.description
  end
end

但这只会给出一个 NoMethodError ,因为此时它无法找到描述。我认为它可能会像#around 那样工作,但我猜不是。

【问题讨论】:

  • 这应该会有所帮助:stackoverflow.com/a/10199575/429758
  • @PrakashMurthy 实际上,一点也不。我知道如何使用 Rails 记录器,这不是问题。我想要的是在运行时将每个测试的描述写入 Rails 日志。我特别希望必须编辑每个规范文件才能做到这一点。

标签: ruby-on-rails-3 rspec


【解决方案1】:

你已经很接近了,以下将在运行时输出你的测试描述:

RSpec.configure do |config|
   config.before(:each) do
     Rails.logger.debug self.class.description         
   end
end

来源:http://benmabey.com/2008/07/04/global-setup-in-rspec-or-how-to-add-logging-for-specs.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多