質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

3702閲覧

Rails チュートリアル 13章テストが通らない

takuma-yoshida

総合スコア11

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/08/29 15:22

13.4 マイクロポストの画像投稿以降のrails testが通りません。
エラー内容を理解しテストをクリアしたいのでご教示お願いします。

エラーメッセージです。

sample_app (user-microposts) $ rails test Running via Spring preloader in process 4871 Started with run options --seed 23640 ERROR["test_micropost_interface", Minitest::Result, 0.017639254918321967] test_micropost_interface#Minitest::Result (0.02s) NameError: NameError: uninitialized constant Micropost::PictureUploader app/models/micropost.rb:4:in `<class:Micropost>' app/models/micropost.rb:1:in `<top (required)>' /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:27: warning: constant ::Fixnum is deprecated Time: 00:00:01, ETA: 00:00:05 /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:91: warning: constant ::Fixnum is deprecated FAIL["test_content_should_be_at_most_140_characters", Minitest::Result, 1.9332082569599152] test_content_should_be_at_most_140_characters#Minitest::Result (1.93s) Expected true to be nil or false test/models/micropost_test.rb:26:in `block in <class:MicropostTest>' FAIL["test_content_should_be_present", Minitest::Result, 1.9365493969526142] test_content_should_be_present#Minitest::Result (1.94s) Expected true to be nil or false test/models/micropost_test.rb:21:in `block in <class:MicropostTest>' FAIL["test_user_id_should_be_present", Minitest::Result, 1.9398503398988396] test_user_id_should_be_present#Minitest::Result (1.94s) Expected true to be nil or false test/models/micropost_test.rb:16:in `block in <class:MicropostTest>' /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:27: warning: constant ::Fixnum is deprecated Time: 00:00:02, ETA: 00:00:01 /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:91: warning: constant ::Fixnum is deprecated /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:27: warning: constant ::Fixnum is deprecated Time: 00:00:02, ETA: 00:00:00 /usr/local/rvm/gems/ruby-2.4.0/gems/will_paginate-3.1.5/lib/will_paginate/view_helpers/link_renderer.rb:91: warning: constant ::Fixnum is deprecated 51/51: [====================================================================================================================================] 100% Time: 00:00:02, Time: 00:00:02 Finished in 2.51917s 51 tests, 265 assertions, 3 failures, 1 errors, 0 skips

【errorが出ているファイル】
【test/integration/microposts_interface_test.rb】

require 'test_helper' class MicropostsInterfaceTest < ActionDispatch::IntegrationTest def setup @user = users(:michael) end test "micropost interface" do log_in_as(@user) get root_path assert_select 'div.pagination' # 無効な送信 assert_no_difference 'Micropost.count' do post microposts_path, params: { micropost: { content: "" } } end assert_select 'div#error_explanation' # 有効な送信 content = "This micropost really ties the room together" assert_difference 'Micropost.count', 1 do post microposts_path, params: { micropost: { content: content } } end assert_redirected_to root_url follow_redirect! assert_match content, response.body # 投稿を削除する assert_select 'a', text: 'delete' first_micropost = @user.microposts.paginate(page: 1).first assert_difference 'Micropost.count', -1 do delete micropost_path(first_micropost) end # 違うユーザーのプロフィールにアクセス (削除リンクがないことを確認) get user_path(users(:archer)) assert_select 'a', text: 'delete', count: 0 end end

【test/models/micropost_test】

require 'test_helper' class MicropostTest < ActiveSupport::TestCase def setup @user = users(:michael) @micropost = @user.microposts.build(content: "Lorem ipsum") end test "should be valid" do assert @micropost.valid? end test "user id should be present" do @micropost.user_id = nil assert_not @micropost.valid? end test "content should be present" do @micropost.content = " " assert_not @micropost.valid? end test "content should be at most 140 characters" do @micropost.content = "a" * 141 assert_not @micropost.valid? end test "order should be most recent first" do assert_equal microposts(:most_recent), Micropost.first end end

以上です。よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

同様と思われるエラーの対処方法が下記サイトに記載されてました。
Railsチュートリアル中にNameError: uninitialized constant Micropost::PictureUploaderが出た時の対処法 - Qiita

投稿2018/08/31 01:32

motikan

総合スコア19

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問