簡體   English   中英

語法錯誤“語法錯誤,意外的輸入結束,期望關鍵字結束(SyntaxError)”

[英]Syntax error “syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)”

由於語法錯誤,我無法運行 Rspec user_spec.rb 測試。 可能在 2 個不同的文件中有太多“結束”? 我在某些地方添加和刪除了“結束”,但沒有成功。

語法錯誤“語法錯誤,意外的輸入結束,期望關鍵字結束(SyntaxError)”需要'spec_helper'

用戶規范.rb

describe User do

  before do
    @user = User.new(name: "Example User", email: "user@example.com",
                     password: "foobar", password_confirmation: "foobar")
  end

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password_digest) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }

  it { should be_valid }

    before do
    @user = User.new(name: "Example User", email: "user@example.com")
  end

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password_digest) }

  before do
    @user = User.new(name: "Example User", email: "user@example.com")
  end

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }

  it { should be_valid }

  describe "when name is too long" do
    before { @user.name = "a" * 51 }
    it { should_not be_valid }
  end
end

describe "when email format is invalid" do
    it "should be invalid" do
      addresses = %w[user@foo,com user_at_foo.org example.user@foo.
                     foo@bar_baz.com foo@bar+baz.com]
      addresses.each do |invalid_address|
        @user.email = invalid_address
        expect(@user).not_to be_valid
      end
    end

  describe "when email format is valid" do
    it "should be valid" do
      addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
      addresses.each do |valid_address|
        @user.email = valid_address
        expect(@user).to be_valid
      end
    end


describe "when email address is already taken" do
    before do
      user_with_same_email = @user.dup
      user_with_same_email.save
    end
describe "when password is not present" do
    before do
      @user = User.new(name: "Example User", email: "user@example.com",
                       password: " ", password_confirmation: " ")
    end
    it { should_not be_valid }
  end

  describe "when password doesn't match confirmation" do
    before { @user.password_confirmation = "mismatch" }
    it { should_not be_valid }
  end

user_pages_spec.rb

   require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup" do
    before { visit signup_path }


    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end
end

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end
    end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end
    end

終端輸出

/usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load': /Users/Abraham/code/sample_app/spec/models/user_spec.rb:85: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
    from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

似乎你有一堆describe s 從來沒有end s 關鍵字,從describe "when email format is invalid" do直到describe "when email address is already taken" do

結束那些家伙,你可能就完了 =)

你這里有太多了嗎?

 describe "when name is too long" do
     before { @user.name = "a" * 51 }
     it { should_not be_valid }
 end
 end

只是張貼以防它幫助別人。 對我來說,此錯誤的原因是在使用form_with創建表單后丟失了do 希望可以幫助別人

$ rails server -b $IP -p $PORT - 為我解決了同樣的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM