RSpec初心者です。
RSpecのテストがどうしても通らないので、変数の中身を確認したい、という状況がありました。
調べてみるとexample中(it 'hoge' do
の中)でbinding.pry
が使えるらしいです。
しかし、NoMethodError
が出てデバッグできませんでした。
Failures:
1) DeviseSessions POST #sign_in パラメーターが有効な場合 ユーザー個別ページにリダイレクトされる(リクエストが成功する)こと
Failure/Error: binding.pry
NoMethodError:
undefined method `pry' for #<Binding:0x00007f9d27b2d9c0>
Did you mean? try
...
原因
spec/spec_helper.rb
にrequire 'pry'
が記載されていない。
参考:
対処法
spec/spec_helper.rb
にrequire 'pry'
を追加します。
spec/spec_helper.rb
RSpec.configure do |config|
require 'pry' <=ここ!
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
config.filter_run_when_matching :focus
end