0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

render_templateマッチャー

Posted at

レンダリンクされたかどうか

render_templateマッチャー

render_template matcher

render_templateマッチャーは与えられたテンプレートまたはレイアウトをレンダーする要求を明示するために使われる。assert_templateへ指名する

The render_template matcher is used to specify that a request renders a given template or layout. It delegates to assert_template

リクエスト仕様書とコントローラ仕様書で使えます

It is available in controller specs (spec/controllers) and request specs (spec/requests).

注意:ender_templateだけでなくリダイレクトに対してredirect_to(:action => 'new')を使う,

NOTE: use redirect_to(:action => 'new') for redirects, not render_template.

三つの可能なオプション付きrender_templateの使用

Using render_template with three possible options

Given a file named “spec/controllers/gadgets_spec.rb” with:

require "rails_helper"

RSpec.describe GadgetsController do
  describe "GET #index" do
    subject { get :index }

    it "renders the index template" do
      expect(subject).to render_template(:index)
      expect(subject).to render_template("index")
      expect(subject).to render_template("gadgets/index")
    end

    it "does not render a different template" do
      expect(subject).to_not render_template("gadgets/show")
    end
  end
  end

render_viewsでレンダリングされていないから内容まではわからない

require "rails_helper"

RSpec.describe UsersController,type: :controller do
  # render_views
    # createアクション
  describe "newアクション" do
    it "newページがレンダリングされる" do
      get "new"
      expect(response.body).to render_template(:new)
    end
    it "newページに新規登録が含まれている" do
      get "new"
      expect(response.body).to include("新規登録")
    end
  end
end
UsersController
  newアクション
    user/newページがレンダリングされる
    user/newページに新規登録が含まれている (FAILED - 1)

Failures:

  1) UsersController newアクション user/newページに新規登録が含まれている
     Failure/Error: expect(response.body).to include("新規登録")
       expected "" to include "新規登録"
     # ./spec/controllers/users_controller_spec.rb:13:in `block (3 levels) in <top (required)>'

Finished in 0.06515 seconds (files took 1.21 seconds to load)
2 examples, 1 failure

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?