前提・実現したいこと
rails test をした際にでるエラーメッセージを解決したい。
以下のエラーメッセージが発生しました。
StaticPagesControllerTest#test_should_get_about: NoMethodError: undefined method `document' for nil:NilClass
該当のソースコード
Ruby on Rails
試したこと
エラーの意味を調べ、documentに何らかのミスがあるということはわかったのですが、そもそもdocumentという文字がどこにもないので、どこを直せば良いのかが分からない。
補足情報(FW/ツールのバージョンなど)
controllers/static_pages_controller.test.rbは下記の通りです。
require 'test_helper' class StaticPagesControllerTest < ActionDispatch::IntegrationTest test "should get home" do get static_pages_home_url assert_response :success assert_select "title", "Home | Ruby on Rails Tutorial Sample App" end test "should get help" do get static_pages_help_url assert_response :success assert_select "title", "Help | Ruby on Rails Tutorial Sample App" end test "should get about" do get static_pages_about_url assert_response :success assert_select "title", "About | Ruby on Rails Tutorial Sample App" end end
config/routes.rbは下記の通りです
Rails.application.routes.draw do get 'static_pages/home' get 'static_pages/help' get 'static_pages/about' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'application#hello' end
views/static_pages/about.html.erbは下記の通りです
<!DOCTYPE html> <html> <head> <title>About | Ruby on Rails Tutorial Sample App</title> </head> <body> <h1>About</h1> <p> <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> is a <a href="https://railstutorial.jp/#ebook">book</a> and <a href="https://railstutorial.jp/#screencast">screencast</a> to teach web development with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This is the sample application for the tutorial. </p> </body> </html>
この他に載せるべき情報があれば教えてください。
お時間ある時にどなたかアドバイスをいただければと思います。
よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/16 12:00
2019/04/16 12:09