我希望能夠寫一個規範,如RSpec的報告VS性能
describe Foo do
before :each do
@hash = some_very_expensive_setup_op
end
describe "hash" do
subject{@hash}
its([:a]){should == 10}
its([:b]){should == 20}
its([:c]){should == 30}
end
end
和RSpec的工作方式,相當合理,是每個其塊之前塊之前執行。在許多情況下,這是你想要的,但在上述情況下,在我的許多測試中,最後的葉其塊斷言沒有副作用。
我可以重寫規範爲
describe Foo do
before :each do
@hash = some_very_expensive_setup_op
end
describe "hash" do
it "should have some attributes" do
@hash[:a].should == 10
@hash[:b].should == 20
@hash[:c].should == 30
end
end
end
現在所有的斷言單個塊內進行。該規範在功能上是相同的,但我沒有得到第一個版本的詳細報告,列出了文檔格式化程序中的每個斷言。
輸出對我來說很重要,因爲我嘗試將輸出用作Web api消費者的文檔。例如,對於我的規格之一,我有一個像
GET /status.json?ago=:ago
it should behave like authenticated
GET /status.json
accepts a valid user
rejects an invalid user
request
request attributes
:ago - number of seconds of history to calculate statistics
:current_user (implicit)
response attributes
scale
downtime
points
nextlevel
輸出,但爲屬性的數量的增加它會減慢規格。
細粒度報告 輸出與測試性能之間是否存在這種張力的解決方案?