Reputation: 539
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"
Upvotes: 5
Views: 3084
Reputation: 1
Put this <% provide(:title, "Home") %> in static_pages/(home/about/contact).html.erb file. I hope this solve your problem
Upvotes: 0
Reputation: 11
I ran across this same problem too. It came from a copy/paste of the html views from the tutorial.
Even if the text is the same between your view and your test, if you copy/paste from the Rails tutorial, you should re-write the text between title tags in your view (Home, About, Help, etc) yourself and the text should pass. Hope this help, it passed for me with this.
I'm using vim. Don't know if it matters.
Upvotes: 1
Reputation: 1
I had the same problem with three failures, home, about and help.
It turned out to be a simple typo in static_pages/home(about & help).html.erb I had misspelt "Tutorial" and copied pasted the same mistake into each html.erb. Corrected typo and re-ran rails test. Success :)
Upvotes: 0
Reputation: 1
I ran across this same problem. What I did was take the | Ruby on Rails Tutorial Sample App
part off, inside the end of the <title>
tag in your application.html.erb
file. Hope this helps!
Upvotes: 0
Reputation: 7779
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.
Upvotes: 4