我正在完成練習以添加聯繫人頁面,但測試在頁面標題上失敗。Hartl Rails教程 - 第3章
這裏是我的測試文件:
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
def setup
@base_title = "Ruby on Rails Tutorial Sample App"
end
test "should get root" do
get root_url
assert_response :success
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
test "should get contact" do
get static_pages_about_url
assert_response :success
assert_select "title", "Contact | #{@base_title}"
end
end
這裏是contact.html.erb文件:
<% provide(:title, "Contact") %>
<h1>Contact</h1>
<p>
Contact the Ruby on Rails Tutorial about the sample app at the
<a href="http://www.railstutorial.org/contact">contact page</a>.
</p>
我也完成以下任務:
- 添加了適當的路線
- 增加適當的動作
不過,我收到此錯誤信息:
test_should_get_contact#StaticPagesControllerTest (0.45s)
<Contact | 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:35:in `block in <class:StaticPagesControllerTest>'
也請注意,
- 該頁面顯示正常,與預期的網頁標題(聯繫不是)
- 我再次測試使用全新頁面,但與頁面標題中返回'About'的結果相同
真的不知道爲什麼它會返回這個,因爲我仔細地跟隨了教程。我想在教程中取得進展,但如果我無法解決這個基本的測試問題,我不確定我會變得很遠!
謝謝!這真是太神奇了,我盯着這段代碼,看起來很像一個小時,而且這是一件很簡單的事情! –