前提・実現したいこと
Railsチュートリアル第3章に取り組んでおります。
途中どうしてもテストがパスしないので、GREENになるようにしたいです。
順番にチュートリアル通りに進めてきて、リスト3.39のところ、リファクタリングをしてテストがGREENになるはずのところです。
$ rails test 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips
しかしこうはならず...
$ rails t Running via Spring preloader in process 6778 /home/ec2-user/environment/sample_app/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/ec2-user/environment/sample_app/config/application.rb to limit the frameworks that will be loaded. Run options: --seed 28115 # Running: FFF Finished in 0.180342s, 16.6351 runs/s, 33.2702 assertions/s. 1) Failure: StaticPagesControllerTest#test_should_get_home [/home/ec2-user/environment/sample_app/test/controllers/static_pages_controller_test.rb:13]: Expected at least 1 element matching "title", found 0.. Expected 0 to be >= 1. 2) Failure: StaticPagesControllerTest#test_should_get_about [/home/ec2-user/environment/sample_app/test/controllers/static_pages_controller_test.rb:25]: Expected at least 1 element matching "title", found 0.. Expected 0 to be >= 1. 3) Failure: StaticPagesControllerTest#test_should_get_help [/home/ec2-user/environment/sample_app/test/controllers/static_pages_controller_test.rb:19]: Expected at least 1 element matching "title", found 0.. Expected 0 to be >= 1. 3 runs, 6 assertions, 3 failures, 0 errors, 0 skips
何度やってもこうなってしまうのです。
どうやら見てみると、私のstatic_pages_controller_test.rbファイルの、
require 'test_helper' class StaticPagesControllerTest < ActionDispatch::IntegrationTest def setup @base_title = "Ruby on Rails Tutorial Sample App" end test "should get home" do get static_pages_home_url assert_response :success assert_select "title", "Home | #{@base_title}" end test "should get help" do get static_pages_help_url assert_response :success assert_select "title", "Help | #{@base_title}" end test "should get about" do get static_pages_about_url assert_response :success assert_select "title", "About | #{@base_title}" end end
home,help,aboutそれぞれ3つのテスト内にあるassert_select "title", "Home | #{@base_title}"
に相当する部分がいけないとのこと。
タイプミスの可能性も考えてチュートリアルのコードをそのままコピペして使ってみましたが改善せず...
テストだけではなく3つそれぞれのhtmlファイル、共通した処理をまとめたviews/layouts/application.html.erb
ファイルもコピペしてみました。
全くのお手上げ状態でして、何が悪いのかさっぱり分かりません。
どうかお力を貸していただけないでしょうか。
よろしくお願い致します。
[追記]
home.html.erb
<% provide(:title, "Home") %> <h1>Sample App</h1> <p> This is the home page for the <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> sample application. </p>
about.html.erb
<% provide(:title, "About") %> <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>
help.html.erb
<% provide(:title, "Help") %> <h1>Help</h1> <p> Get help on the Ruby on Rails Tutorial at the <a href="https://railstutorial.jp/help">Rails Tutorial help section</a>. To get help on this sample app, see the <a href="https://railstutorial.jp/#ebook"><em>Ruby on Rails Tutorial</em> book</a>. </p>
長くなり申し訳ありませんが、参考までに記載させていただきました。
補足情報(FW/ツールのバージョンなど)
cloud9使用
macOS使用
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/30 05:40
2019/05/30 06:23
2019/05/30 06:58
2019/05/30 07:02