2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rspec】エラー文 undefined local variable or method `response' for RSpecの解決法

Last updated at Posted at 2020-04-14

以下のようにテストを書いたところ、次のエラー。

spec/features/gyms_spec.rb
require 'rails_helper'

describe "indexメソッドが動く" do

expect(response).to render_template :index

end

###エラー文

 undefined local variable or method `response' for RSpec::ExampleGroups::Gyms::Index:Class

##原因
そもそもfeature_specにはresponseオブジェクトがないからfeature_spec内ではresponseは使えない。

##解決法

controller_specでrenderオブジェクトを確認するテストをすればOK.
responseオブジェクトはcontroller_specのためだけにあります。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?