注意:この記事はガチの初心者がとりあえずの解決法を書いてるだけです.参考にはなりませんからね
毎回書いておくことにします笑
なにか「間違えたこと書かないでくれ」な点がありましたら教えていただけると幸いです...
1. 今回のエラー
コントローラのテストについて勉強してたよ.
前回と同じくRuby on Rails 4.2 に基づいた本でやってるからこういったエラーが出るんだよね...
今回は変数@articlesを取り出そうとassignsメソッドを使おうとしたよ.
myapp/test/controllers/articles_controller_test.rb
# 前略
test "index" do
5.times { FactoryGirl.create(:article) }
get :index
assert_response :success
assert_equal 5, assigns(:articles).count
end
# 後略
実行したコマンド
bin/rake test TEST=test/controllers/articles_controller_test.rb
返答
DEPRECATION WARNING: Using a dynamic :action segment in a route is deprecated and will be removed in Rails 6.0. (called from block in <main> at /Users/xxx/Rails/myapp/config/routes.rb:4)
Run options: --seed 43305
# Running:
E
Error:
ArticlesControllerTest#test_index:
NoMethodError: assigns has been extracted to a gem. To continue using it,
add `gem 'rails-controller-testing'` to your Gemfile.
test/controllers/articles_controller_test.rb:8:in `block in <class:ArticlesControllerTest>'
bin/rails test test/controllers/articles_controller_test.rb:4
E
Error:
(中略)
Finished in 0.406940s, 4.9147 runs/s, 2.4574 assertions/s.
2 runs, 1 assertions, 0 failures, 2 errors, 0 skips
もう一個エラーがあるのですがそれは別の件なのでここでは触れないよ.
2. 原因
やっぱり非推奨になってるっぽい.
これを入れろって言われた.
gem 'rails-controller-testing'
3.変更
てことで書き込み書き込み.
myapp/Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.0'
# 中略
group :test do
#中略,最後に追加
gem 'rails-controller-testing'
end
# 後略
4.結果
これで無事に行った...はず.とりあえずエラーは消えた!