Disclaimer: Expected to be 0 = 1 on ruby on rails
I am following the Hartle tutorial and see this crash every time I run a 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 this? 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"
source to share
The problem is lack of html matching "Help | Ruby on Rails Tutorial Sample App"
.
if you look at the definition assert_select
it takes :count
as an (optional) argument. If the parameter is count
not specified, it sets the minimum occurrence html
to 1. This is why the error you are getting is Expected 0 to be >= 1.
. In your case, there were 0 matches in which the test was expected at least 1 time.
source to share
I faced this problem too. This came from copy / paste of html views from the tutorial.
Even if the text matches your view and your test, if you copy / paste from the Rails tutorial, you have to rewrite the text between the heading tags in your view (Home, About, Help, etc.) yourself and the text should get through. Hope for this help, it went through for me with this.
I am using vim. I don't know if this matters.
source to share
I had the same problem with three failures at home about help and assistance.
It turned out to be just a typo in static_pages / home (for help and assistance) .html.erb I skipped the "Tutorial" and copied the same error into every html.erb. Fixed typo and re-check of rails. Success:)
source to share
The answer above (Aaron Buhler) is correct. I'm working on this tutorial, and Mr. Hartl forgets to mention that you need to remove the text "| Sample Ruby on Rails Tutorial Application" from your application.html.erb - after adding the full_title function. This is because the full_title function returns "Sample Ruby on Rails Tutorial Application" in addition to the value already in the layout file. This way you get:
Sample Ruby on Rails Tutorial | Sample Ruby on Rails Tutorial
instead:
Sample Ruby on Rails Tutorial
and your test controller sees the difference and your test (s) fails ...
source to share