RSpec 2.13 發佈了!

Myron Marston

2013年2月23日

我剛發佈了 RSpec 2.13。這是一個小版本,包含一些向後相容的增強功能和大量的錯誤修復。 建議所有使用者都升級。

感謝所有幫助實現這次 RSpec 發佈的貢獻者。

值得注意的新功能

分析超過 10 個範例

RSpec 長期以來都具有 --profile 選項。 它會顯示最慢的 10 個範例的報告。 現在您可以傳遞數字選項,使其列印超過 10 個範例。

要列印最慢的 15 個範例,您可以使用

rspec --profile 15

letsubject 宣告可以使用 super

使用者要求這個功能已經有一段時間了。 這允許在巢狀群組中覆寫 letsubject 宣告,同時委託給父群組的原始定義。只需使用 super()

describe Array do
  let(:numbers) { [1, 2, 3, 4] }

  context "when evens are filtered out" do
    let(:numbers) { super().reject(&:even?) }
  end
end

請注意,要使用此功能,您必須在對 super 的呼叫中使用明確的括號; 否則,ruby 會給您一個醜陋的 implicit argument passing of super from method defined by define_method() is not supported 錯誤。

be_within 匹配器支援百分比差異

最好用一個例子來說明

# The existing `be_within` matcher (which still works):
expect(account.balance).to be_within(10).of(500)

# Now you can do this, too:
expect(account.balance).to be_within(2).percent_of(500)

include 匹配器可以接受匹配器清單

當您想要驗證列表中項目的某些內容,而不是簡單地驗證項目的身分時,這會很方便。

RSpec::Matchers.define :a_user_named do |name|
  match do |user|
    user.name == name
  end
end

expect(users).to include(a_user_named("Coen"), a_user_named("Daphne"))

文件

RDoc

Cucumber 功能

發行說明

rspec-core 2.13.0

完整變更日誌

增強功能

錯誤修復

rspec-expectations 2.13.0

完整變更日誌

增強功能

錯誤修復

rspec-mocks 2.13.0

完整變更日誌

錯誤修復

rspec-rails 2.13.0

完整變更日誌

增強功能