【发布时间】:2016-08-15 15:41:20
【问题描述】:
我是 StackOverflow 的新手,因为我最近开始通过 Michael Hartl 的教程学习 Ruby on Rails。我似乎无法通过清单 8.25 的测试(“此时,测试套件应该仍然是绿色的:”$ bundle exec rake test):
我的测试是RED,错误如下:
~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Started
ERROR["test_layout_links", SiteLayoutTest, 2016-04-14 23:15:47 +0000]
test_layout_links#SiteLayoutTest (1460675747.92s)
NoMethodError: NoMethodError: undefined method `full_title' for # <SiteLayoutTest:0x0000000a30bad8>
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
22/22: [======================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.30261s
tests, 49 assertions, 0 failures, 1 errors, 0 skips
我再次浏览了第 7 章和第 8 章中的所有最新变化; 8.20、8.21、8.24的测试刚刚通过。
错误中提到的文件 site_layout_test 如下所示:
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 signup_path
assert_select "title", full_title("Sign up")
end
end
补充:
1) 这是我正在做的教程:https://www.railstutorial.org/book/log_in_log_out
2) 这是错误引用的文件:
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 signup_path
assert_select "title", full_title("Sign up")
end
end
如果我取出最后一个 assert_select,我就不会再收到错误了。
这是 application_helper:
module ApplicationHelper
# Returns the full title on a per-page basis.
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
非常感谢您的帮助。提前致谢!
【问题讨论】:
-
能否请您发布相关教程的链接?我找不到你在第 8 章提到的规格。
-
您的
test_helper中是否定义了full_title方法? -
感谢您的 cmets,我添加了更多信息
标签: ruby-on-rails railstutorial.org