{"id":3519,"date":"2023-08-14T18:55:39","date_gmt":"2023-08-14T09:55:39","guid":{"rendered":"https:\/\/www.kinryo.net\/?p=3519"},"modified":"2024-06-19T17:59:23","modified_gmt":"2024-06-19T08:59:23","slug":"%ef%bc%95%ef%bc%9a%e6%9c%80%e5%88%9d%e3%81%ae%e3%83%86%e3%82%b9%e3%83%88","status":"publish","type":"post","link":"https:\/\/www.kinryo.net\/?p=3519","title":{"rendered":"\uff15\uff1a\u6700\u521d\u306e\u30c6\u30b9\u30c8"},"content":{"rendered":"<p>rails generate controller\u3092\u5b9f\u52b9\u3057\u305f\u6642\u70b9\u3067\u30c6\u30b9\u30c8\u304c\u51fa\u6765\u3066\u3044\u308b<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">ls test\/controllers\/<\/span><br \/>\n<span style=\"color: #ff6600;\">static_pages_controller_test.rb<\/span><br \/>\n\u898b\u3066\u307f\u3088\u3046<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">cat test\/controllers\/static_pages_controller_test.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">require &#8220;test_helper&#8221;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">class StaticPagesControllerTest &lt; ActionDispatch::IntegrationTest<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000test &#8220;should get home&#8221; do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000get static_pages_home_url<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000assert_response :success<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000end<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u3000test &#8220;should get help&#8221; do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000get static_pages_help_url<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000\u3000assert_response :success<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000end<\/span><br \/>\n<span style=\"color: #ff6600;\">end<br \/>\n$<\/span> <span style=\"color: #008000;\">rails test<\/span><br \/>\n<span style=\"color: #ff6600;\">Running 2 tests in a single process (parallelization threshold is 50)<br \/>\nRun options: &#8211;seed 6539<br \/>\n<\/span><span style=\"color: #ff6600;\"># Running:<br \/>\n..<br \/>\nFinished in 0.506600s, 3.9479 runs\/s, 3.9479 assertions\/s.<br \/>\n2 runs, 2 assertions, 0 failures, 0 errors, 0 skips<\/span><br \/>\ndb\/test.sqlite3\u304c\u51fa\u6765\u3066\u3044\u308b\u306e\u3067\u3001Git\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u767b\u9332\u3055\u308c\u308b\u3068\u90aa\u9b54\u306a\u306e\u3067\u3059\u304c\u3001.gitignore\u306b\u65e2\u306b\u30a4\u30b0\u30ce\u30a2\u30fc\u3055\u308c\u308b\u8a18\u8ff0\u304c\u5165\u3063\u3066\u3044\u308b<br \/>\n.gitignore\u30d5\u30a1\u30a4\u30eb\u306e\u629c\u7c8b<br \/>\n<span style=\"color: #0000ff;\"># Ignore the default SQLite database.<\/span><br \/>\n<span style=\"color: #0000ff;\">\/db\/*.sqlite3<\/span><br \/>\n<span style=\"color: #0000ff;\">\/db\/*.sqlite3-*<\/span><br \/>\n\u30c6\u30b9\u30c8\u99c6\u52d5\u958b\u767a\u306e\u30b5\u30a4\u30af\u30eb\u306f\u300c\u5931\u6557\u3059\u308b\u30c6\u30b9\u30c8\u3092\u6700\u521d\u306b\u66f8\u304f\u300d\u300c\u6b21\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u6210\u529f\u3055\u305b\u308b\uff08\u30d1\u30b9\u3055\u305b\u308b\uff09\u300d\u300c\u5fc5\u8981\u306a\u3089\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u300d\u306e\u3088\u3046\u306b\u9032\u307f\u307e\u3059\u3002\u591a\u304f\u306e\u30c6\u30b9\u30c8\u30c4\u30fc\u30eb\u3067\u306f\u3001\u30c6\u30b9\u30c8\u306e\u5931\u6557\u3092 <span><span class=\"sc\"><\/span><span style=\"color: #ff0000;\"><span class=\"sc\"><strong>red<\/strong><\/span><span class=\"sc\"><\/span><\/span><\/span> \u3001\u6210\u529f\u3057\u305f\u3068\u304d\u3092 <span><span class=\"sc\"><\/span><span class=\"sc\"><strong>green<\/strong><\/span><span class=\"sc\"><\/span><\/span> \u3067\u8868\u3057\u307e\u3059\u3002\u3053\u3053\u304b\u3089\u3001\u3053\u306e\u30b5\u30a4\u30af\u30eb\u3092\u300c <span><span class=\"sc\"><\/span><span class=\"sc\"><strong>red<\/strong><\/span><span class=\"sc\"><\/span><\/span> \u30fb <span><span class=\"sc\"><\/span><span class=\"sc\"><strong>green<\/strong><\/span><span class=\"sc\"><\/span><\/span> \u30fbREFACTOR\u300d\u3068\u547c\u3076\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306b\u5f93\u3063\u3066\u6700\u521d\u306e\u30b5\u30a4\u30af\u30eb\u3092\u5b8c\u4e86\u3055\u305b\u307e\u3057\u3087\u3046\u3002\u307e\u305a\u5931\u6557\u3059\u308b\u30c6\u30b9\u30c8\u3092\u66f8\u3044\u3066 <span><span class=\"sc\"><\/span><span class=\"sc\"><strong>red<\/strong><\/span><span class=\"sc\"><\/span><\/span> \u306b\u306a\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">gedit test\/controllers\/static_pages_controller_test.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">require &#8220;test_helper&#8221;<\/span><\/p>\n<p><span style=\"color: #ff6600;\">class StaticPagesControllerTest &lt; ActionDispatch::IntegrationTest<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0 test &#8220;should get home&#8221; do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 get static_pages_home_url<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 assert_response :success<\/span><br \/>\n<span style=\"color: #ff6600;\">end<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u00a0 test &#8220;should get help&#8221; do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 get static_pages_help_url<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 assert_response :success<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0 end<\/span><\/p>\n<p><span style=\"color: #ff6600;\">\u00a0 test &#8220;should get about&#8221; do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 get static_pages_about_url<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0\u00a0\u00a0 assert_response :success<\/span><br \/>\n<span style=\"color: #ff6600;\">\u00a0 end<\/span><br \/>\n<span style=\"color: #ff6600;\">end<\/span><br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">rails test<\/span><br \/>\n<span style=\"color: #ff6600;\">\u524d\u7565<\/span><br \/>\n<span style=\"color: #ff6600;\">NameError: undefined local variable or method `static_pages_about_url&#8217; <\/span><br \/>\n<span style=\"color: #ff6600;\">\u4e2d\u7565<\/span><br \/>\n<span style=\"color: #ff6600;\">3 runs, 2 assertions, 0 failures, 1 errors, 0 skips<\/span><br \/>\n\u30a8\u30e9\u30fc\u3092\u898b\u308b\u3068static_pages_about_url\u306eURL\u304c\u7121\u3044\u3068\u8a00\u3063\u3066\u3044\u308b\u306e\u3067about\u7528\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u8ffd\u52a0\u3059\u308b<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">gedit test\/controllers\/static_pages_controller_test.rb<\/span><br \/>\n<span style=\"color: #ff6600;\">Rails.application.routes.draw do<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000get &#8216;static_pages\/home&#8217;<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000get &#8216;static_pages\/help&#8217;<\/span><br \/>\n<span style=\"color: #ff6600;\">\u3000get &#8220;static_pages\/about&#8221;\u3000<\/span>\u3000\u3000\u2190\u3053\u308c\u3092\u8ffd\u8a18<br \/>\n<span style=\"color: #ff6600;\">root &#8220;application#hello&#8221;<\/span><br \/>\n<span style=\"color: #ff6600;\">end<\/span><br \/>\n\u305d\u3057\u3066\u30c6\u30b9\u30c8<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">rails test<\/span><br \/>\n<span style=\"color: #ff6600;\">\u524d\u7565<\/span><br \/>\n<span style=\"color: #ff6600;\">AbstractController::ActionNotFound: The action &#8216;about&#8217; could not be found for StaticPagesController<\/span><br \/>\n<span style=\"color: #ff6600;\">\u4e2d\u7565<\/span><br \/>\n<span style=\"color: #ff6600;\">3 runs, 2 assertions, 0 failures, 1 errors, 0 skips<\/span><br \/>\n\u4eca\u5ea6\u306e\u30a8\u30e9\u30fc\u306fabout\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304c\u7121\u3044\u3068\u8a00\u3063\u3066\u3044\u308b\u306e\u3067<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">gedit app\/controllers\/static_pages_controller.rb<\/span><br \/>\n<span style=\"color: #0000ff;\">class StaticPagesController &lt; ApplicationController<\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0 def home<\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0 end<\/span><\/p>\n<p><span style=\"color: #0000ff;\">\u00a0 def help<\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0 end<\/span><\/p>\n<p><span style=\"color: #0000ff;\">\u00a0 def about\u3000\u3000\u3000<span style=\"color: #333333;\">\u2190 about\u3092\u8ffd\u8a18<\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">\u00a0 end<\/span><br \/>\n<span style=\"color: #0000ff;\">end<\/span><br \/>\n\u305d\u3057\u3066\u30c6\u30b9\u30c8<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">rails test<\/span><br \/>\n<span style=\"color: #ff6600;\">1) Error:<\/span><br \/>\n<span style=\"color: #ff6600;\">StaticPagesControllerTest#test_should_get_about:<\/span><br \/>\n<span style=\"color: #ff6600;\">ActionController::MissingExactTemplate: StaticPagesController#about is 3 runs, 2 assertions, 0 failures, 1 errors, 0 skips<\/span><br \/>\n\u4eca\u5ea6\u306fabout\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u7121\u3044\u3068\u3044\u3063\u3066\u3044\u308b\u306e\u3067<br \/>\n<span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">gedit app\/views\/static_pages\/about.html.erb<\/span><br \/>\n\u3053\u3093\u306a\u30d5\u30a1\u30a4\u30eb\u306f\u7121\u3044\u306e\u3067\u7a7a\u767d\u306e\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001\u4f5c\u308b<br \/>\n<span style=\"color: #0000ff;\">&lt;h1&gt;About&lt;h1&gt;<br \/>\n&lt;p&gt;<br \/>\n<span class=\"p\">&lt;<\/span><span class=\"nt\">a<\/span> <span class=\"na\">href<\/span><span class=\"o\">=<\/span><span class=\"s\">&#8220;https:\/\/railstutorial.jp\/&#8221;<\/span><span class=\"p\">&gt;<\/span>Ruby on Rails Tutorial<span class=\"p\">&lt;\/<\/span><span class=\"nt\">a<\/span><span class=\"p\">&gt;<br \/>\n<\/span> \u3000is a <span class=\"p\">&lt;<\/span><span class=\"nt\">a<\/span> <span class=\"na\">href<\/span><span class=\"o\">=<\/span><span class=\"s\">&#8220;https:\/\/railstutorial.jp\/#ebook&#8221;<\/span><span class=\"p\">&gt;<\/span>book<span class=\"p\">&lt;\/<\/span><span class=\"nt\">a<\/span><span class=\"p\">&gt;<\/span> and<\/span><br \/>\n<span style=\"color: #0000ff;\">\u3000<span class=\"p\">&lt;<\/span><span class=\"nt\">a<\/span> <span class=\"na\">href<\/span><span class=\"o\">=<\/span><span class=\"s\">&#8220;https:\/\/railstutorial.jp\/screencast&#8221;<\/span><span class=\"p\">&gt;<\/span>screencast<span class=\"p\">&lt;\/<\/span><span class=\"nt\">a<\/span><span class=\"p\">&gt;<br \/>\n<\/span> \u3000to teach web development with<\/span><br \/>\n<span style=\"color: #0000ff;\">\u3000<span class=\"p\">&lt;<\/span><span class=\"nt\">a<\/span> <span class=\"na\">href<\/span><span class=\"o\">=<\/span><span class=\"s\">&#8220;https:\/\/rubyonrails.org\/&#8221;<\/span><span class=\"p\">&gt;<\/span>Ruby on Rails<span class=\"p\">&lt;\/<\/span><span class=\"nt\">a<\/span><span class=\"p\">&gt;<\/span>.<\/span><br \/>\n<span style=\"color: #0000ff;\">\u3000This is the sample app for the tutorial.<\/span><br \/>\n<span style=\"color: #0000ff;\"><span class=\"p\">&lt;\/<\/span><span class=\"nt\">p<\/span><\/span><span class=\"p\"><span style=\"color: #0000ff;\">&gt;<\/span><br \/>\n\u3067\u3001\u30c6\u30b9\u30c8<br \/>\n<\/span><span style=\"color: #ff6600;\">$<\/span> <span style=\"color: #008000;\">rails test<\/span><br \/>\n<span style=\"color: #ff6600;\">\u524d\u7565<\/span><br \/>\n<span style=\"color: #ff6600;\">3 runs, 3 assertions, 0 failures, 0 errors, 0 skips<\/span><br \/>\n\u7121\u4e8b\u30a8\u30e9\u30fc\u304c\u30bc\u30ed\u306b\u306a\u3063\u305f\u3002\u305d\u3057\u3066\u30d6\u30e9\u30a6\u30b6\u306bhttp:\/\/localhost:3000\/static_pages\/about\u3068\u5165\u529b\u3059\u308b\u3068<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.kinryo.net\/wp-content\/uploads\/2023\/08\/Screenshot-from-2023-08-15-06-04-53.png\" alt=\"\" class=\"alignnone size-full wp-image-3524\" width=\"668\" height=\"265\" srcset=\"https:\/\/www.kinryo.net\/wp-content\/uploads\/2023\/08\/Screenshot-from-2023-08-15-06-04-53.png 668w, https:\/\/www.kinryo.net\/wp-content\/uploads\/2023\/08\/Screenshot-from-2023-08-15-06-04-53-300x119.png 300w, https:\/\/www.kinryo.net\/wp-content\/uploads\/2023\/08\/Screenshot-from-2023-08-15-06-04-53-150x60.png 150w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><br \/>\n\u3068\u8868\u793a\u3055\u308c\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>rails generate controller\u3092\u5b9f\u52b9\u3057\u305f\u6642\u70b9\u3067\u30c6\u30b9\u30c8\u304c\u51fa\u6765\u3066\u3044\u308b $ ls test\/controllers\/ static_pages_controller_test.rb \u898b\u3066\u307f\u3088\u3046 $ cat  &hellip; <a href=\"https:\/\/www.kinryo.net\/?p=3519\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"vkexunit_cta_each_option":"","footnotes":""},"categories":[28],"tags":[],"class_list":["post-3519","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails-almalinux9"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/3519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3519"}],"version-history":[{"count":4,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/3519\/revisions"}],"predecessor-version":[{"id":3525,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=\/wp\/v2\/posts\/3519\/revisions\/3525"}],"wp:attachment":[{"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kinryo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}