我是StackOverflow的新手,因为我最近开始使用Michael Hartl的教程学习Ruby on Rails。我似乎无法通过上市8.25的测试("此时,测试套件仍然应该是GREEN:" $ bundle exec rake test):
我的测试是红色,错误如下:
~/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
非常感谢您的帮助。提前谢谢!
答案 0 :(得分:1)
我打赌原因是因为你没有执行Listing 5.37中的步骤,其中包含ApplicationHelper
test_helper.rb
中的class ActiveSupport::TestCase
fixtures :all
include ApplicationHelper
.
.
.
end
:
<ul class="inbox-message-list">
<li class="message-suject">
This is some long text that will not fit in the box
</li>
</ul>