コントローラーやページの動作を別々のテストとしてテストしたいのですが、テストをスピードアップしますが、コントローラーやcapybaraページを複数回実行するだけで1回ロードするだけです。一例として、コントローラ試験で:RSpecで1つのコントローラ負荷またはCapyparaページの負荷に対して複数のテストを実行するにはどうすればよいですか?
it "should include all videos in the list of all videos" do
get :show, id: event.id
response.should be_somehow
end
it "should set the main video to be the paid video" do
get :show, id: event.id
response.should be_somehow_else
end
私はこのなりたい:
before :all do
get :show, id: event.id
end
it "should include all videos in the list of all videos" do
response.should be_somehow
end
it "should set the main video to be the paid video" do
response.should be_somehow_else
end
問題はRSpecの応答オブジェクト(または、カピバラのために、ページオブジェクトをきれいにすることです)。だから私は、コントローラのテスト、response
オブジェクト、またはカピバラ中page
結果でassigns
をチェックしてるかどうか、この作品のようなもの:
before :all do
get :show, id: event.id
@response = response
end
example "it should do something" do
@response.should be_somehow # test works
end
example "it should do something else" do
@response.should be_somehow_else # test fails; @response has been flushed by Rails testing facilities
end
だから、テストのスピードアップのためのソリューションは、単一のテストで複数のチェックを持っているではありません。
example "it should be totally correct in every way" do
get :show, id: event.id
response.should be_somehow # test works
response.should be_somehow_else # test works
end
しかし、これはテストの命名に関する私の感性を悪化させます。
これは、私が多段階セットアップ(ログイン、許可)プロセスを持つかもしれないCapybaraではるかに悪化しており、1ページの負荷をチェックする15のことがあります。他の醜いものは見せなかったのですか? javascriptのアクションは正しいものに縛られましたか?右のバックボーンテンプレートはレンダリングされましたか?これらのテストはすぐにRubyのコメントインラインでshould
文の20の連続した行になるので、私がテストしていることを思い出すことができます。
テスト状態をテストからテストまで維持しないように指示する前に、それは私がやっていることではありません。単一の状態に関連付けられた独立変数をチェックしたいと思います。
おかげ
これは私のサイトの出力を一度記録してから変更しないでしょうか? – bhuga
VCRは実際に多くの方法を記録できます。はい、あなたが望むなら、それを行うことができます、または毎回それを行うことができます。または一度青い月ごとに! – krainboltgreene
これはlocalhostの場合とは違います。 VCRはlocalhost上ではまったく動作しないか、完全にオフになります。私はこれが動作するとは思わない:/ – bhuga