mardi 23 juin 2015

Rails: Minitest tests fails when they should pass

Following the Rails Tutorial by Michael Hartl, I am testing for the <title> of my static pages with Minitest in Rails.

Here is the static_pages_controller_test.rb file:

require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase
  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Home | Microblog"
  end

  test "should get help" do
    get :help
    assert_response :success
    assert_select "title", "Help | Microblog"
  end

  test "should get about" do
    get :about
    assert_response :success
    assert_select "title", "About | Microblog"
  end

end

Here is the Home page home.html.erb file:

<!DOCTYPE html>
<html>
  <head>
    <title>Home | Microblog</title>
  </head>
  <body>
    <h1>Microblog</h1>
    <p>
        This is the homepage for Microblog, a brand new microblogging app.
    </p>
  </body>
</html>

help.html.erb and about.html.erb basically contain the same content, with slight variations.

So, from my understanding, tests should pass.

However, when I run rake, I get:

Run options: --seed 47355

# Running:

FFF

Finished in 0.112314s, 26.7109 runs/s, 53.4217 assertions/s.

  1) Failure:
StaticPagesControllerTest#test_should_get_home [/Users/TXC/code/microblog/test/controllers/static_pages_controller_test.rb:7]:
<Home | Microblog> expected but was
<Home | Microblog>..
Expected 0 to be >= 1.


  2) Failure:
StaticPagesControllerTest#test_should_get_help [/Users/TXC/code/microblog/test/controllers/static_pages_controller_test.rb:13]:
<Help | Microblog> expected but was
<Help | Microblog>..
Expected 0 to be >= 1.


  3) Failure:
StaticPagesControllerTest#test_should_get_about [/Users/TXC/code/microblog/test/controllers/static_pages_controller_test.rb:19]:
<About | Microblog> expected but was
<About | Microblog>..
Expected 0 to be >= 1.

3 runs, 6 assertions, 3 failures, 0 errors, 0 skips

In particular, I don't understand why I get:

<Home | Microblog> expected but was
    <Home | Microblog>..

What am I missing?

Aucun commentaire:

Enregistrer un commentaire