イマイチちゃんとしたやり方が見つからなかったので、取り敢えず現状のテスト状態を記述。
ちゃんとした方法が知りたい。
render file: 'file_name', layout: false
Controller部分はこんな感じで
def show
@object = Object.find(params[:id])
render file: 'file_name.html', layout: false
end
単純にファイルを表示して、
可能ならspec内に
# bra bra bra...
get :show, id: test_object
expect(response).to render_template(file: "some_file.html", layout: false)
と言う感じでテストしたいのだけど、出来ない。
1) ObjectsController GET #show renders file
Failure/Error: expect(response).to render_template(file: "some_file.html", layout: false)
Expected [] to include "some_file.html".
となってしまう。
色々調べるとインスタンス変数@templates
とか@layouts
があるらしくそれでテスト出来るっぽいのだが見つからない。なんだか@_templates
とか@_layouts
は見つかったのでそれでテストすることに。
# bra bra bra...
get: show, id: test_object
expect(@_layouts).to be_blank
expect(@_templates.keys.first).to eq('some_file.html')
一応ちゃんとテスト出来てるけど、適当に見つけた方法なのでちゃんとした方法がありそうで知りたい。
参考
ruby on rails - Rspec test to render no layout - Stack Overflow