【问题标题】:Make RSpec print "context" descriptions before the descriptions in the "it" blocks使 RSpec 在“it”块中的描述之前打印“上下文”描述
【发布时间】:2013-05-01 14:37:41
【问题描述】:

出于好奇,有没有办法让 rspec 在失败消息中的“it”块中的文本之前打印上下文块中的文本?例如:

describe Array do
  context "when created with new" do
    it "is empty" do
      array = Array.new
      array << 1 # trigger a failure to demonstrate the message
      array.should be_empty
    end
  end
end

现在这会在失败消息中打印“Array when created with new is empty”。 这对我来说听起来有点尴尬。有没有办法让 rspec 说“使用 new 创建时数组为空”?在我看来,这听起来更自然。只是好奇...

【问题讨论】:

    标签: rspec rspec2


    【解决方案1】:

    我不知道有一种方法可以让 RSpec 反转描述字符串的顺序,但如果你使用 the documentation formatter,你的输出会更有意义——比如:

    Array
      when created with new
        is empty
    

    至少这样,缩进清楚地界定了描述中的重要短语。

    【讨论】:

      猜你喜欢
      • 2017-12-14
      • 1970-01-01
      • 2014-01-01
      • 2012-07-23
      • 2013-02-10
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多