Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure: Expected 0 to be >= 1 on ruby on rails

I'm doing Hartle tutorial and see this failure every time I run rake test I see this failure:

  1) Failure:
StaticPagesControllerTest#test_should_get_help [.../sample_app/test/controllers/static_pages_controller_test.rb:14]:
<Help | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.

What does it mean? And how can I solve it? This is my 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", "Ruby on Rails Tutorial Sample App"   end

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

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

  test "should get contact" do
    get :contact
    assert_response :success
    assert_select "title", "Contact | Ruby on Rails Tutorial Sample App"   end end

And here is line 14.

assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
like image 458
Hanna Avatar asked Apr 29 '15 13:04

Hanna


1 Answers

The issue is that there is no html matching "Help | Ruby on Rails Tutorial Sample App".

if you look at the definition of assert_select, it accepts :count as (optional) argument. If the count is not specified, it sets the minimum occurrence of the html to 1. This is why the error you are getting is Expected 0 to be >= 1.. In your case there were 0 matches where the test expected at least 1 match.

like image 99
AbM Avatar answered Oct 10 '22 22:10

AbM