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 コード
はminitestなのですがrspec でテストコードを書いたらどうなりますか?
require 'rails_helper' RSpec.describe "SiteLayouts", type: :request do describe "GET /site_layouts" do it "works! (now write some real specs)" do get root_path expect(subject).to render_template("static_pages/home") expect(page).to have_css('a', text: 'href') expect(page).to have_css('a', text: 'href') expect(page).to have_css('a', text: 'href') expect(page).to have_css('a', text: 'href') end end end コード
こんな感じで書くのかなと思ったのですがうまくいかなかったので投稿しました!よろしくお願いします
「うまく行かなかった」、とはどういう状況でしょうか? テスト実行時の具体的なエラー内容はありますか?
あなたの回答
tips
プレビュー