Gurpreet
Gurpreet

Reputation: 81

rails test, getting Failure:..Expected 0 to be >= 1

I am following Michael Hartl's Ruby on Rails Tutorial. In section 3.4.1 Testing Titles (Red) the author writes a minitest test using assert_select viz.

test "should get home" do
  get static_pages_home_url
  assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
end

Then he expects the following output on running rails test:

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips

However, when I run the exact same test on my local system I get this failure message instead:

# Running:

FF

Failure:
StaticPagesControllerTest#test_should_get_home [/Users/gurpreet/environment/sample_app/test/controllers/static_pages_controller_test.rb:7]:
<Home | Ruby on Rails Tutorial Sample App> expected but was
<SampleApp>..
Expected 0 to be >= 1.

Someone please explain why am I not getting the intended rails test result. Please note that the actual section in the tutorial has 3 tests and 6 assertions but I have just posted the relevant details for readability, using single test and single assertion inside it.

Here is full Controller Test Class:

require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test "should get home" do
    get static_pages_home_url
    assert_response :success
    assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
  end

  test "should get help" do
    get static_pages_help_url
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
  end

  test "should get about" do
    get static_pages_about_url
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App"
  end
end

As I mentioned earlier it contains extra tests of similar nature. I only posted a snippet of this class earlier.

The View part of controller deliberately omit the <title> tag to make the test to fail. For example in case of home.html.erb

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <h1>Sample App</h1>
    <p>
      This is the home page for the
      <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
      sample application
    </p>
  </body>
</html>

Upvotes: 1

Views: 952

Answers (1)

wondersz1
wondersz1

Reputation: 905

That's probably because you're using a default reporter that's built into Minitest. I saw a similar Minitest summary with minitest-reporters gem: https://github.com/kern/minitest-reporters

Upvotes: 1

Related Questions