hi i am presently on chapter 8 micheal hartl Learning Rails 3rd edition.
presently i am stucked in chapter 8 with above errors .I will highly appreciate if somebuddy help me out with it. Thanks in advance
when i run bundle exec rake test it comes up with
sample_app git:(log-in-log-out) ✗ bundle exec rake test
Run options: --seed 16515
# Running:
......E............
Finished in 0.944425s, 20.1181 runs/s, 40.2361 assertions/s.
1) Error:
SiteLayoutTest#test_layout_links:
NoMethodError: undefined method `full_title' for #<SiteLayoutTest:0x007ff8bea694b0>
test/integration/site_layout_test.rb:12:in `block in <class:SiteLayoutTest>'
19 runs, 38 assertions, 0 failures, 1 errors, 0 skips
whereas my file posses the following
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
get signup_path
assert_select "title", full_title("Sign up")
end
end
full_title is a helper method defined in application_helper.rb. Check out https://www.railstutorial.org/book/_single-page#code-title_helper
Related
I'm new on StackOverflow as I've recently begun to learn Ruby on Rails with Michael Hartl's Tutorial. I can't seem to pass the test of listing 8.25 ("At this point, the test suite should still be GREEN:" $ bundle exec rake test):
My test is RED and the error is as follows:
~/workspace/sample_app (log-in-log-out) $ bundle exec rake test
Started
ERROR["test_layout_links", SiteLayoutTest, 2016-04-14 23:15:47 +0000]
test_layout_links#SiteLayoutTest (1460675747.92s)
NoMethodError: NoMethodError: undefined method `full_title' for # <SiteLayoutTest:0x0000000a30bad8>
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
22/22: [======================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.30261s
tests, 49 assertions, 0 failures, 1 errors, 0 skips
I've gone through all the recent changes in chapter 7 and 8 again; the tests of 8.20, 8.21 and 8.24 just pass.
The file site_layout_test mentioned in the error looks like this:
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
get signup_path
assert_select "title", full_title("Sign up")
end
end
ADDITIONS:
1) This is the tutorial I'm doing: https://www.railstutorial.org/book/log_in_log_out
2) This is the file that the error refers to:
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
get signup_path
assert_select "title", full_title("Sign up")
end
end
If I take the last assert_select out, I don't get the error anymore.
And this is the application_helper:
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title = '')
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end
Your help is much appreciated. Thanks in advance!
I would wager the reason is because you haven't performed the step in Listing 5.37, where you include in the ApplicationHelper in your test_helper.rb:
class ActiveSupport::TestCase
fixtures :all
include ApplicationHelper
.
.
.
end
FAIL["test_test_login_with_valid_information", UsersLoginTest, 2015-08-27 20:00:02 +0000]
test_test_login_with_valid_information#UsersLoginTest (1440705602.54s)
Expected at least 1 element matching "a[href="/users.762146111"]", found 0..
Expected 0 to be >= 1.
test/integration/users_login_test.rb:18:in `block in '
2/2:
[=======================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.46825s 2 tests, 10 assertions, 1 failures, 0 errors, 0
skips
Here's user_login_test.rb
require 'test_helper'
class UsersLoginTest < ActionDispatch::IntegrationTest
def setup
#user = users(:michael)
end
test "test login with valid information" do
get login_path
post login_path, session: {email: #user.email, password: "password"}
assert_redirected_to #user
follow_redirect!
assert_template "users/show"
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", users_path(#user)
end
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, session: { email: "", password: "" }
assert_template 'sessions/new'
assert flash.any?
get root_path
assert flash.empty?
end
end
User.yml
michael:
name: michael
email: michael#example.com
password_digest: <%= User.digest("password") %>
I'd double-check your header template and confirm that the appropriate code is there for the "Profile" link (listing 8.16) as that appears what's failing the test.
I'm not super savvy with Rails, but this part of the error has me a little concerned: matching "a[href="/users.762146111"]". I'd expect that to be /users/762….
When I run bundle exec rake test it comes up with an error in the terminal. It can't seem to get passed this step
# Running:
.......EEE.......
Finished in 0.420936s, 40.3862 runs/s, 61.7672 assertions/s.
1) Error:
StaticPagesControllerTest#test_should_get_help:
NameError: uninitialized constant ApplicationController::TestCase
app/controllers/static_pages_controller.rb:1:in `<top (required)>'
2) Error:
StaticPagesControllerTest#test_should_get_home:
NameError: uninitialized constant ApplicationController::TestCase
app/controllers/static_pages_controller.rb:1:in `<top (required)>'
3) Error:
StaticPagesControllerTest#test_should_get_about:
NameError: uninitialized constant ApplicationController::TestCase
app/controllers/static_pages_controller.rb:1:in `<top (required)>'
17 runs, 26 assertions, 0 failures, 3 errors, 0 skips
I tried fixing the problem to the code but have not come up with a solution.
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
assert_select "title", "Home | 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
end
The first line of you test code should be:
class StaticPagesControllerTest < ActionController::TestCase
It's ActionController - not ApplicationController.
I am trying to complete exercise 4 in Chapter 5 of the Hartl tutorial and I am getting these two errors when I run $bundle exec rake test:
Started
ERROR["test_layout_links", SiteLayoutTest, 2015-03-31 09:33:35 +0000]
test_layout_links#SiteLayoutTest (1427794415.88s)
NoMethodError: NoMethodError: undefined method `full_title' for # <SiteLayoutTest:0x00000006cee338>
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
test/integration/site_layout_test.rb:13:in `block in <class:SiteLayoutTest>'
ERROR["test_full_title_helper", ApplicationHelperTest, 2015-03-31 09:33:35 +0000]
test_full_title_helper#ApplicationHelperTest (1427794415.99s)
ArgumentError: ArgumentError: wrong number of arguments (0 for 1)
app/helpers/application_helper.rb:2:in `full_title'
test/helpers/application_helper_test.rb:5:in `block in <class:ApplicationHelperTest>'
app/helpers/application_helper.rb:2:in `full_title'
test/helpers/application_helper_test.rb:5:in `block in <class:ApplicationHelperTest>'
7/7: [====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.57888s
7 tests, 14 assertions, 0 failures, 2 errors, 0 skips
What do these errors mean, and how do I go about fixing the errors?
This is my test/integration/site_layout_test.rb code:
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
get signup_path
assert_select "title", full_title("Sign up")
end
end
And this is my app/helpers/application_helper.rb code:
module ApplicationHelper
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
" #{page_title} | #{base_title}"
end
end
end
This is my test/helpers/application_helper_test.rb file:
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
test "full title helper" do
assert_equal full_title, "Ruby On Rails App"
assert_equal full_title("Help"), "Help | Ruby On Rails App"
end
end
What do these errors mean, and how do I go about fixing the errors?
NoMethodError: undefined method 'full_title' for #<SiteLayoutTest:0x00000006cee338>
test/integration/site_layout_test.rb:13
On line 13, you called a method that doesn't exist.
See http://ruby-doc.org/core-2.2.0/NoMethodError.html
ArgumentError: wrong number of arguments (0 for 1)
app/helpers/application_helper.rb:2:in 'full_title'
test/helpers/application_helper_test.rb:5
On line 5, you need to pass exactly one argument.
See http://ruby-doc.org/core-2.2.0/ArgumentError.html
See where the line numbers are in the error message?
I recommend reading an introductory ruby book, like http://ruby-doc.com/docs/ProgrammingRuby/ before (or while) learning rails.
Good luck!
In case anyone comes across the same error when they are going through the Michael Hartl 3rd edition...
I found the error in the app/helpers/application_helper.rb code. I needed to add an empty string for page_title, changing 'def full_title(page_title)' to 'def full_title(page_title= '')'
module ApplicationHelper
def full_title(page_title = '')
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{page_title} | #{base_title}"
end
end
end
I've just gone thru chapter 8 of the Hartl tutorial but keep getting an error when I try to run the tests. I'm getting 3 of the same error and the issue seems to stem from the user login test, where fixture :michael is not being found in the fixture set (users).
Here is my user_login_test
require 'test_helper'
class UsersLoginTest < ActionDispatch::IntegrationTest
def setup
#user = users(:michael)
end
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, session: { email: "", password: "" }
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end
test "login with valid information" do
get login_path
post login_path, session: { email: #user.email, password: 'password' }
assert_redirected_to #user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(#user)
end
end
Here is the error
ERROR["test_login_with_invalid_information", UsersLoginTest, 0.006789]
test_login_with_invalid_information#UsersLoginTest (0.01s)
StandardError: StandardError: No fixture named 'michael' found for fixture set 'users'
test/integration/users_login_test.rb:6:in `setup'
test/integration/users_login_test.rb:6:in `setup'
ERROR["test_login_with_valid_information", UsersLoginTest, 0.008174]
test_login_with_valid_information#UsersLoginTest (0.01s)
StandardError: StandardError: No fixture named 'michael' found for fixture set 'users'
test/integration/users_login_test.rb:6:in `setup'
test/integration/users_login_test.rb:6:in `setup'
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '#' after '[#<Nokogiri::CSS::Node:0x007fa642d4e870 #type=:ELEMENT_NAME, #value=["div"]>]' (called from block in <class:UsersSignupTest> at /Users/SamDavidoff/Documents/workspace/sample_app/test/integration/users_signup_test.rb:14)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '<' after '.' (called from block in <class:UsersSignupTest> at /Users/SamDavidoff/Documents/workspace/sample_app/test/integration/users_signup_test.rb:15)
ERROR["test_valid_signup_information", UsersSignupTest, 0.197435]
test_valid_signup_information#UsersSignupTest (0.20s)
NoMethodError: NoMethodError: undefined method `is_logged_in?' for #<UsersSignupTest:0x007fa642dd6068>
test/integration/users_signup_test.rb:27:in `block in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:27:in `block in <class:UsersSignupTest>'
You didn't create user in file test/fixtures/users.yml