-1
當談到Ruby on Rails時,我是一個完整的新手,我無法弄清楚在我的代碼中導致這種語法錯誤的原因!努力理解這種語法錯誤 - Rails教程第8章
作爲參考,我正在關注Michael Hartl的Rails教程,我目前正在編寫第8章「8.15 Flash測試」。
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>'
這裏是我的測試文件,路線文件和我的會話控制器文件:
中創建和集成測試的閃存錯誤填充後,我當我運行rake測試收到此錯誤
routes文件:
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
會話控制器文件:
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文件:
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
和我sessions_controller_test文件:
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
測試幫助文件:
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
請幫助。我不明白爲什麼這個語法錯誤正在發生。
如果您正確縮進您的代碼,您不會遇到發現此錯誤的問題。在會話控制器中'create'方法的末尾缺少'end'。 –
它在我的文件上正確縮進,我只是不確定如何縮進這裏。非常感謝! – feezy26