HTMLの記述のみですが、
testを実行すると以下の様に失敗してしまいます。
ubuntu:~/environment/sample_app (rails-flavored-ruby) $ rails test Running via Spring preloader in process 9215 Started with run options --seed 39178 FAIL["test_should_get_about", #<Minitest::Reporters::Suite:0x00005584bd8c6b48 @name="StaticPagesControllerTest">, 1.0102913549999357] test_should_get_about#StaticPagesControllerTest (1.01s) <About | Ruby on Rails Tutorial Sample App> expected but was <About|Ruby on Rails Tutorial Sample App>.. Expected 0 to be >= 1. test/controllers/static_pages_controller_test.rb:20:in `block in <class:StaticPagesControllerTest>' FAIL["test_should_get_contact", #<Minitest::Reporters::Suite:0x00005584bd93fde0 @name="StaticPagesControllerTest">, 1.0231368189997738] test_should_get_contact#StaticPagesControllerTest (1.02s) <Contact | Ruby on Rails Tutorial Sample App> expected but was <Contact|Ruby on Rails Tutorial Sample App>.. Expected 0 to be >= 1. test/controllers/static_pages_controller_test.rb:26:in `block in <class:StaticPagesControllerTest>' FAIL["test_should_get_help", #<Minitest::Reporters::Suite:0x00005584bd9be0a0 @name="StaticPagesControllerTest">, 1.0346855889993094] test_should_get_help#StaticPagesControllerTest (1.04s) <Help | Ruby on Rails Tutorial Sample App> expected but was <Help|Ruby on Rails Tutorial Sample App>.. Expected 0 to be >= 1. test/controllers/static_pages_controller_test.rb:14:in `block in <class:StaticPagesControllerTest>' FAIL["test_should_get_home", #<Minitest::Reporters::Suite:0x00005584bda67768 @name="StaticPagesControllerTest">, 1.0463882349995401] test_should_get_home#StaticPagesControllerTest (1.05s) <Home | Ruby on Rails Tutorial Sample App> expected but was <Home|Ruby on Rails Tutorial Sample App>.. Expected 0 to be >= 1. test/controllers/static_pages_controller_test.rb:8:in `block in <class:StaticPagesControllerTest>' 4/4: [==================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01 Finished in 1.05075s 4 tests, 8 assertions, 4 failures, 0 errors, 0 skips
テストファイル、helper、erbファイル、ルーティンングは以下の様に記述しています。
テストコード
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 test "should get contact" do get static_pages_contact_url assert_response :success assert_select "title", "Contact | Ruby on Rails Tutorial Sample App" end end
共通テンプレerbファイル
<html> <head> <title><%= full_title(yield(:title)) %></title> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> </head> <body> <%= yield %> </body> </html>
helper.rb
module ApplicationHelper def full_title(page_title='') base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else page_title + "|" + base_title end end end
ルーティング
Rails.application.routes.draw do root 'static_pages#home' get 'static_pages/home' get 'static_pages/help' get 'static_pages/about' get 'static_pages/contact' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end
試したこと
<Home | Ruby on Rails Tutorial Sample App> expected but was
<Home|Ruby on Rails Tutorial Sample App>..
とのことで、試しに以下の様に|の前後で半角スペースを消す様に記述してみました。
test "should get home" do 略 assert_select "title", "Home|Ruby on Rails Tutorial Sample App" end
しかし、
FAIL["test_should_get_home", #<Minitest::Reporters::Suite:0x00005584ba1984f0 @name="StaticPagesControllerTest">, 1.0933848129998296] test_should_get_home#StaticPagesControllerTest (1.09s) <Home|Ruby on Rails Tutorial Sample App> expected but was <Home|Ruby on Rails Tutorial Sample App>.. Expected 0 to be >= 1. test/controllers/static_pages_controller_test.rb:8:in `block in <class:StaticPagesControllerTest>'
とのことでした。expect通りでいいじゃないかと思いましたが、全然違う様です。
失敗の原因が分かる方いらっしゃいましたら、お助けください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/10/08 08:05