特定のレイアウトがRSpecで使用されていることをテストするにはどうすればよいですか?私は幸運とtemplate.layout、response.layout、およびresponse.should render_template( "レイアウト")を試みました。 RSpecの2でRspecテストレイアウト
答えて
、コントローラの仕様では、あなたが推測として、あなたはrender_templateを使用しますが、ビューのディレクトリからの相対パスを含める必要があります。あなたのレイアウトがアプリ/ビュー/レイアウト/ mylayout.html.erbがあるのであれば、あなたのスペックは次のようになります。
response.should render_template "layouts/mylayout"
# rspec-rails-1.3.x for rails-2
describe HomeController do
describe "the home page" do
it "should use the :home_page layout" do
get :index
response.layout.should == "layouts/home_page"
end
end
end
# rspec-2 for rails-3
describe "GET index" do
it "renders the page within the 'application' layout" do
get :index
response.should render_template 'layouts/application' # layout
response.should render_template 'index' # view
end
end
https://gist.github.com/11080d61648aaee51840私はrspec 2、レール3です。私はresponse.layoutと推奨されないtemplate.layoutエラーで廃止されました。 –
私はあなたのフィードバックに基づいて私の答えを更新しました。 –
をまた、あなたは両方をテストすることができ、ワンライナーでレイアウトとアクションレンダリング、中RSpecの-2:
response.should render_template(%w(layouts/application name_of_controller/edit))
RSpecの3のための更新構文:
expect(response).to render_template(:index) # view
expect(response).to render_template(layout: :application) # layout
それとも、@Flov's one-linerを好む、あなたが書くことができる場合:
expect(response).to render_template(:index, layout: :application)
注意をassert_template
からrender_template
委譲すること。これらのドキュメントはActionController assert_templateにあります。
ちょうどメモ、これはもう働かないし、ドキュメントもsavagely古いです。 – Sebastialonso
- 1. レール/ RSpecのは:RSpecのメタデータ
- 2. (rspec)?
- 3. Rspecテストヘルパー
- 4. RSpec +ジャスミンノード
- 5. RSpec Cookbook?
- 6. RSpecの
- 7. RSpecテストモデルメソッド
- 8. Capybara&RSpec
- 9. RSpec:スタブプライベートメソッド
- 10. RSpecの:
- 11. RSpecコントローラテストエラー
- 12. RSpec - as_null_object?
- 13. オートテストのrspecスタックトレース
- 14. rspec letメソッド+ループ
- 15. RSpecのとカピバラ
- 16. RSpec Railsシンタックスヘルパー
- 17. RSPEC:オブジェクトが
- 18. RSpec autotestとbundler
- 19. エイリアス 'it' in rspec
- 20. RSPECのバグ(?)
- 21. RSpecとActiveModel
- 22. IntelliJのRunnin rspec
- 23. アリュール、RSpecの
- 24. 私はRSpecの
- 25. テストRSpecの
- 26. Rspecとjavascript
- 27. Rspec、test gem
- 28. Rails Pundit RSpec
- 29. RSpecが 'id' =
- 30. Rspec on lib + initializer
レイアウトが使用されていないことをどのようにテストしますか?例えば、コントローラが「render:layout => false」とします。それをどうやってテストするのですか? –