我有一段代碼,我試圖運行rspec。Rails 4 - 語法錯誤,意外tidENTIFIER,預計輸入結束
require 'spec_helper'
describe "User" do
before { @user = User.new(name: "Example User", email: "[email protected]", password: "foobar", password_confirmation: "foobar") }
subject { @user }
it { should respond_to(:name)}
end
我收到以下錯誤
c:\Sites\sample_app>rspec spec/models/user_spec.rb
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec
/core/configuration.rb:819:in `load': c:/Sites/sample_app/spec/models/user_spec.
rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input (SyntaxError)
before { @user...er'
現在我重新輸入一個新的文件,測試和運行,並沒有錯誤。我想有一些編碼問題,或者我沒有了解到我沒有得到的東西。有沒有人能夠解釋這個問題?
錯誤來自第1行,您要求spec_helper,那麼您可以共享spec_helper代碼嗎? –
是的,因爲錯誤說「user_spec.rb:1」...我寫錯了這個問題嗎?奇怪它已經有-1。只是尋找一些幫助:/ –
請重新閱讀來自@SachinSingh的評論:-)你被要求發佈你的'spec_helper.rb'文件,因爲這可能是問題的源頭(沒有雙關語意)。 –