Help us understand the problem. What is going on with this article?

RSpecでpartialのrenderをテストする

More than 5 years have passed since last update.

render partial: 'partial_name'をテストする

多分gem 'webrat'が必要です。

require 'spec_helper'

describe SampleController do
  render_views

  context 'GET show' do
    it 'renders patial with given name' do
      get :show, id: 1
      expect(response).to render_template(partial: '_partial_name')
    end
  end
end

ポイントはrender_viewsrender_template(patial: '_partial_name')の部分。
render_viewsを記述しないとviewのコンテキスト以下は無視するっぽいです。
_がファイル名に入っている場合は記述する必要があります。

foloinfo
foloinfo / CEO at byus&co.ltd // Vimmer, 最近はめっきりReact
https://drip.ink
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away