Rspec-tags

提供:Dev Guides
移動先:案内検索

RSpec-タグ

RSpecタグは、specファイルで特定のテストを実行する簡単な方法を提供します。 デフォルトでは、RSpecは実行するspecファイル内のすべてのテストを実行しますが、実行する必要があるのはそれらのサブセットのみです。 非常に高速に実行されるテストがいくつかあり、アプリケーションコードに変更を加えたばかりで、クイックテストを実行したい場合、このコードはRSpecタグでそれを行う方法を示します。

describe "How to run specific Examples with Tags" do
   it 'is a slow test', :slow = > true do
      sleep 10
      puts 'This test is slow!'
   end

   it 'is a fast test', :fast = > true do
      puts 'This test is fast!'
   end
end

次に、上記のコードをtag_spec.rbという新しいファイルに保存します。 コマンドラインから次のコマンドを実行します。rspec --tag slow tag_spec.rb

この出力が表示されます-

実行オプション:\ {:slow ⇒ true}を含める

This test is slow!
.
Finished in 10 seconds (files took 0.11601 seconds to load)
1 example, 0 failures

次に、次のコマンドを実行します:rspec --tag fast tag_spec.rb

この出力が表示されます-

Run options: include {:fast = >true}
This test is fast!
.
Finished in 0.001 seconds (files took 0.11201 seconds to load)
1 example, 0 failures

ご覧のとおり、RSpecタグを使用すると、テストのサブセットを非常に簡単に作成できます。