測試首頁

在首頁加上一個 “Welcome” 來歡迎用戶,首先修改測試。

按下面修改 spec/features/homepage_spec.rb

diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb
index 67c80a4..a224cdf 100644
--- a/spec/features/home_spec.rb
+++ b/spec/features/home_spec.rb
@@ -1,6 +1,12 @@
 require "rails_helper"

 RSpec.describe "Home" do
+  scenario "welcomes user" do
+    visit root_url
+
+    expect(page).to have_text "Welcome"
+  end
+
   scenario "has navbar element" do
     visit root_url

錯誤訊息

Failures:

  1) Home welcomes user
     Failure/Error: expect(page).to have_text "Welcome"
       expected to find text "Welcome" in "Classroom Courses Login New course # Title Description"

修改 app/views/courses/index.html.erb

diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb
index 213b380..f2cb7c0 100644
--- a/app/views/courses/index.html.erb
+++ b/app/views/courses/index.html.erb
@@ -1,4 +1,5 @@
 <div class="col-md-12">
+  <h1>Welcome</h1>
   <div class="course">
     <%= link_to("New course", new_course_path , :class => "btn pull-right") %>
   </div>

再次執行測試,測試通過!

results matching ""

    No results matching ""