質問編集履歴

2 誤字の修正

Shara

Shara score 113

2018/01/07 19:30  投稿

[Rails] Minitest のエラーの見方について
###前提・実現したいこと
Railsのチュートリアルを見ながら、勉強中の初心者です。
初歩な質問かもしれませんが、Rails test で、単体テストを行った際、テストに記載していない内容のエラーが発生し、エラーの原因がわからず困ってます。
初歩な質問かもしれませんが、Rails test で、単体テストを行った際、テストに記載していない内容のエラーが発生し、エラーの原因がわからず困ってます。
どのソースが実行されているのか(どのソースでエラーになっているのか)確認する方法を教えて欲しいです。
###発生している問題・エラーメッセージ
rails test test/controllers/users_controller_test.rb
を実行したときに、以下のエラーが発生してます。
```bash
Running via Spring preloader in process 759
Run options: --seed 14248
# Running:
E
Error:
UsersControllerTest#test_should_get_index:
ActiveRecord::ValueTooLong: Mysql2::Error: Data too long for column 'phase_id' at row 1: INSERT INTO `testphases` (`created_at`, `updated_at`, `phase_id`) VALUES ('2018-01-07 09:51:16', '2018-01-07 09:51:16', '298486374')
Traceback (most recent call last):
   27: from -e:1:in `<main>'
   26: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
   25: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
   24: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
   23: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
   22: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
   21: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
   20: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
   19: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
   18: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:63:in `block in autorun'
   17: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:136:in `run'
   16: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `__run'
   15: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `map'
   14: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `block in __run'
   13: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
   12: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:319:in `run'
   11: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:347:in `with_info_handler'
   10: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:360:in `on_signal'
    9: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `block in run'
    8: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `each'
    7: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:321:in `block (2 levels) in run'
    6: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:334:in `run_one_method'
    5: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `record'
    4: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `each'
    3: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:786:in `block in record'
    2: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:23:in `record'
    1: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
/Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_get_index' for class `Minitest::Result' (NameError)
```
INSERTを発行するテストは行っていないにも関わらず、INSERTのエラーが発生しています。
テスト範囲を、test/controllers/users_controller_test.rb で指定しており、このソース内には、CREATEのイベント発行は行っていません。
###該当のソースコード
test/controllers/users_controller_test.rb
```Ruby
 1 require 'test_helper'
 2
 3 class UsersControllerTest < ActionDispatch::IntegrationTest
 4  setup do
 5    @user = users(:one)
 6  end
 7
 8  test "should get index" do
 9    get users_path
10    assert_response :success                                                                                       
11  end
12 end
```
config/routes.rb
```Ruby
 1 Rails.application.routes.draw do                                                                                   
 2  resources :projects
 3  resources :testids
 4  get 'sessions/new'
 5
 6    root  'static_pages#home'
 7    get   '/home',   to: 'static_pages#home'
 8    get   '/signup', to: 'users#new'
 9    get   '/login',  to: 'sessions#new'
10    post  '/login',  to: 'sessions#create'
11    delete '/logout', to: 'sessions#destroy'
12
13    resources :users
14
15  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
16 end
```
###試したこと
1  8行目〜11行目をコメントアウトしてテストをすると、エラーは出ず、何も処理がされずに終了します。
```bash
Running via Spring preloader in process 815
Run options: --seed 48142
# Running:
Finished in 0.001560s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
```
2  test/controllers 内の他のテストファイルをコメントアウトしても状況は変わりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
MacOSX 10.13.2 (High Sierra)
MySQL 5.7.19
Ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
rails (5.1.4)
minitest (5.11.1, 5.10.3)
1 初心者マークの追加

Shara

Shara score 113

2018/01/07 19:26  投稿

[Rails] Minitest のエラーの見方について
###前提・実現したいこと
Railsのチュートリアルを見ながら、勉強中の初心者です。
初歩滴な質問かもしれませんが、Rails test で、単体テストを行った際、テストに記載していない内容のエラーが発生し、エラーの原因がわからず困ってます。
どのソースが実行されているのか(どのソースでエラーになっているのか)確認する方法を教えて欲しいです。
###発生している問題・エラーメッセージ
rails test test/controllers/users_controller_test.rb
を実行したときに、以下のエラーが発生してます。
```bash
Running via Spring preloader in process 759
Run options: --seed 14248
# Running:
E
Error:
UsersControllerTest#test_should_get_index:
ActiveRecord::ValueTooLong: Mysql2::Error: Data too long for column 'phase_id' at row 1: INSERT INTO `testphases` (`created_at`, `updated_at`, `phase_id`) VALUES ('2018-01-07 09:51:16', '2018-01-07 09:51:16', '298486374')
Traceback (most recent call last):
27: from -e:1:in `<main>'
26: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
25: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
24: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
23: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
22: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
21: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
20: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
19: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
18: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:63:in `block in autorun'
17: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:136:in `run'
16: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `__run'
15: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `map'
14: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `block in __run'
13: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
12: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:319:in `run'
11: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:347:in `with_info_handler'
10: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:360:in `on_signal'
9: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `block in run'
8: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `each'
7: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:321:in `block (2 levels) in run'
6: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:334:in `run_one_method'
5: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `record'
4: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `each'
3: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/minitest-5.11.1/lib/minitest.rb:786:in `block in record'
2: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:23:in `record'
1: from /Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
/Users/shara/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_get_index' for class `Minitest::Result' (NameError)
```
INSERTを発行するテストは行っていないにも関わらず、INSERTのエラーが発生しています。
テスト範囲を、test/controllers/users_controller_test.rb で指定しており、このソース内には、CREATEのイベント発行は行っていません。
###該当のソースコード
test/controllers/users_controller_test.rb
```Ruby
1 require 'test_helper'
2
3 class UsersControllerTest < ActionDispatch::IntegrationTest
4 setup do
5 @user = users(:one)
6 end
7
8 test "should get index" do
9 get users_path
10 assert_response :success
11 end
12 end
```
config/routes.rb
```Ruby
1 Rails.application.routes.draw do
2 resources :projects
3 resources :testids
4 get 'sessions/new'
5
6 root 'static_pages#home'
7 get '/home', to: 'static_pages#home'
8 get '/signup', to: 'users#new'
9 get '/login', to: 'sessions#new'
10 post '/login', to: 'sessions#create'
11 delete '/logout', to: 'sessions#destroy'
12
13 resources :users
14
15 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
16 end
```
###試したこと
1 8行目〜11行目をコメントアウトしてテストをすると、エラーは出ず、何も処理がされずに終了します。
```bash
Running via Spring preloader in process 815
Run options: --seed 48142
# Running:
Finished in 0.001560s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
```
2 test/controllers 内の他のテストファイルをコメントアウトしても状況は変わりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
MacOSX 10.13.2 (High Sierra)
MySQL 5.7.19
Ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
rails (5.1.4)
minitest (5.11.1, 5.10.3)

思考するエンジニアのためのQ&Aサイト「teratail」について詳しく知る