如果您想要生成報告,可以在(:all){puts「report goes here」}之後或之後使用全局報告(:each)。如果您希望某些數據爆炸您的測試,您可以測試.should raise_exception。我想你會寫很多異常處理,以防止輸出中的預期故障。將結果記錄到數據庫或文件可能也很煩人。如果可以的話,描述你對數據進行的測試,然後在最後解析rspec的輸出。
class Car
attr_accessor :doors
end
describe "Car" do
it "should have doors" do
Car.new.should respond_to(:doors)
fail("failing intentionally")
end
it "should pass this easily" do
Car.new should_not be nil
end
after(:all) { puts "report here" }
end
您可以在下面看到我對測試失敗的描述。
$ rspec rspec_fail.rb
F.report here
Failures:
1) Car should have doors
Failure/Error: fail("failing intentionally")
RuntimeError:
failing intentionally
# ./rspec_fail.rb:9:in `block (2 levels) in <top (required)>'
Finished in 0.00052 seconds
2 examples, 1 failure
如果這是測試文本和正則表達式,我會很容易就做出失敗的報告。 Failure/Error: fail("Data has spaces")
等
感謝您的反饋意見。關於這種情況有趣的是數據不會被保存。目標是從文件讀取數據,驗證數據,然後丟棄它。這項建議仍然存在嗎? – wadesworld
@wadesworld - 如果數據無效會發生什麼? –
是的,它依然存在。我不會爲你的測試使用1個正則表達式,我會使用驗證的組合 - 對我的口味來說,正則表達式最終會變得太複雜,以致於在將來不可讀。 –