产量和收益率的耙测试出错提供

时间:2015-04-05 02:01:50

标签: ruby-on-rails ruby

我在Ruby on Rails上有点新,目前正在关注Rails的Michael Hartl教程。

当我使用'Guard'测试时,它说,

After running bundle exec rake test below are the results:

1) Failure:
StaticPagesControllerTest#test_should_get_home [c:/Usrs/Code Box/workspace/feed/test/static_pages_controller_test.rb:7]:
<Home | Ruby on Rails Sample App> expected but was <Feed>..
Expected 0 to be >= 1.
  
  3 runs, 6 assertions, 1 failures, 0 errors, 0 sips.

我希望每个页面上的标题动态更改,所以这是我的应用程序视图,

<!DOCTYPE html>
<html>
<head>
  <title><%= yield(:title) %> | Ruby on Rails Sample App</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
  <body>
    <%= yield %>
  </body>
</html>

这里是错误信息中所述的主页视图,

<% provide(:title, "Home") %>
<h1>Lipsum</h1>
<p>
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime, distinctio! Quidem eaque labore eos ipsam a aliquam, eius. Distinctio quo reprehenderit nostrum commodi quod assumenda consequatur officia, placeat sit fugit.
</p>

最后,这是测试控制器,

class StaticPagesControllerTest < ActionController::TestCase
  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Home | Ruby on Rails Sample App"
  end

2 个答案:

答案 0 :(得分:0)

您的视图中的代码是“Ruby on Rails教程示例应用程序”,但您的测试期待“Ruby on Rails示例应用程序”。这是一个错字还是问题?

答案 1 :(得分:0)

&#34;啊哈!&#34;时刻。我似乎正在从另一个文件夹编辑错误的Application.html.erb文件导致错误,因为原始Application.html.erb上的声明没有&#39; Yield&#39;在标题上。

解决。谢谢!