2011-10-25 1 views
1

何か他のものを使用することができますが、私はRiot(https://github.com/thumblemonks/riot)をテストに使用しています。Ruby/Rails/Riotプログラムでテスト結果にアクセスする

私はこのようなテスト出力を得る:私はプログラムでこの情報にアクセスしたい

> ruby my_test_file.rb

Running a test 
    + something works 
    + something else works 
    - something failed 

を。次のようなもの:

test = TestClass.load("my_test_file.rb") 
result = test.run 
result.errors # some array 

答えて

2

自分の質問に答える。誰かが興味があれば、より詳細な回答を投稿することができます。

それの要旨は、評価テストからコンテキストを取得し、テストファイルを評価している:MyReporterが合格/検査結果を不合格扱い、あなたの実装です

Riot.alone! # so Riot doesn't automatically run the tests 

["/path/to/test/file"].each do |test_file| 
    eval(IO.read(path), binding, test_file) # load test file 

    Riot.root_contexts.each do |context| 
    reporter = MyReporter.new 
    context.run reporter 
    # do something cool with reporter results 
    end 

    Riot.root_contexts.clear # clean out root_contexts so it's clean for the next run 
end 

https://github.com/thumblemonks/riot/blob/master/lib/riot/reporter.rb

関連する問題