mardi 3 novembre 2015

Struggling to understand this syntax error - Rails Tutorial Chapter 8

I am a complete newbie when it comes to Ruby on Rails and I can't figure out what is causing this syntax error in my code!

For reference, I'm following the Rails Tutorial by Michael Hartl and am currently on chapter 8 "8.15 A Flash Test".

After creating and filling in the integration test for the flash error, I receive this error when I run rake test:

ERROR["test_should_get_new", SessionsControllerTest, 2015-11-01 06:24:20 +0000]
test_should_get_new#SessionsControllerTest (1446359060.17s)
SyntaxError:         SyntaxError: /Users/user/charity_app/app/controllers/sessions_controller.rb:15: syntax error, unexpected end-of-input, expecting keyword_end


ERROR["test_login_with_invalid_information", UsersLoginTest, 2015-11-01 06:24:20 +0000]
test_login_with_invalid_information#UsersLoginTest (1446359060.67s)
SyntaxError:         SyntaxError: /Users/user/charity_app/app/controllers/sessions_controller.rb:15: syntax error, unexpected end-of-input, expecting keyword_end
        test/integration/users_login_test.rb:6:in `block in <class:UsersLoginTest>'
    test/integration/users_login_test.rb:6:in `block in <class:UsersLoginTest>'

Here's my test files, routes file and my sessions controller file:

routes file:

Rails.application.routes.draw do
root                'static_pages#home'
get    'help'    => 'static_pages#help'
get    'about'   => 'static_pages#about'
get    'contact' => 'static_pages#contact'
get    'signup'  => 'users#new'
get    'login'   => 'sessions#new'
post   'login'   => 'sessions#create'
delete 'logout'  => 'sessions#destroy'
resources :users
end

Sessions Controller file:

class SessionsController < ApplicationController
def new
end

def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
    # log user in
else 
    # show error message
end

def destroy
end
end

users_login_test file:

require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

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
end

and my sessions_controller_test file:

require 'test_helper'

class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end

end

test helper file:

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
# order.
fixtures :all


# Add more helper methods to be used by all tests here...
end

Please help. I can't understand why this syntax error is occurring.

Aucun commentaire:

Enregistrer un commentaire