聞きたいこと
Ruby on Rails Tutorialの第5章にて、Applicationヘルパーで使用しているfull_title
ヘルパーをテストで使用できるようにする際の実装にて疑問がいくつかあります。
- リスト5-35に
test/test_helper.rb
に、include ApplicationHelper
を実装するように記載されています。このApplicationHelper
は何者なのでしょうか?test/
配下に入っているtest_helper.rb
がapp/helpers/application_helper.rb
をincludeするという意味でしょうか - リスト5-36に
require 'test_helper'
と記載されていますが、これはtest/integration/site_layout_test.rb
からtest/test_helper.rb
をincludeしているという意味でしょうか?test/test_helper.rb
にてApplicationHelper
をincludeしているので、結果的にApplicationヘルパーがtest/integration/site_layout_test.rb
にて使用できるようになっているということでしょうか?
参考資料
Ruby on Rails Tutorial 第5章から必要部分を抽出して下記に記載します。
- リスト5-35 test/test_helper.rb
ruby
1ENV['RAILS_ENV'] ||= 'test' 2. 3. 4. 5class ActiveSupport::TestCase 6 fixtures :all 7 include ApplicationHelper 8 . 9 . 10 . 11end
- リスト5-36 test/integration/site_layout_test.rb
require 'test_helper' class SiteLayoutTest < ActionDispatch::IntegrationTest test "layout links" do get root_path assert_template 'static_pages/home' assert_select "a[href=?]", root_path, count: 2 assert_select "a[href=?]", help_path assert_select "a[href=?]", about_path assert_select "a[href=?]", contact_path get contact_path assert_select "title", full_title("Contact") end end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/22 14:12