2017-09-03 101 views
0

嗨,我的生活我無法找到我的rspec文件中的語法錯誤。我經歷了幾十次,卻找不到它。我可以用一組額外的眼睛來幫助我。繼承人我的規格文件:語法錯誤ruby rspec測試

require 'rails_helper' 

RSpec.describe User, type: :model do 
    let(:user) { User.create!(name: "Bloccit User", email: "[email protected]", 
    password: "password") } 

    #name tests 
    it { is_expected.to validate_presence_of(:name) } 
    it { is_expected.to validate_length_of(:name).is_at_least(1) } 

    #email tests 
    it { is_expected.to validate_presence_of(:email) } 
    it { is_expected.to validate_uniqueness_of(:email) } 
    it { is_expected.to validate_length_of(:email).is_at_least(3) } 
    it { is_expected.to allow_value("[email protected]").for(:email) } 

    #password tests 
    it { is_expected.to validate_presence_of(:password) } 
    it { is_expected.to have_secure_password } 
    it { is_expected.to validate_length_of(:password).is_at_least(6)} 

    describe "attributes" do 
    it "should have a name and an email address" do 
    expect(user).to have_attributes(name: "Bloccit User", email: 
    "[email protected]") 
    end 

    it "should capitalize the user name" do 
    user.name = 'bloc user' 
    user.save 
    expect(user.name).to eq "Bloc User" 
    end 
    end 

    describe "invalid user" do 
    let(:user_with_invalid_name) {User.new(name: "", 
    email:"[email protected]")} 
    let(:user_with_invalid_email) {User.new(name: "Bloccit User", email:"")} 

    it "should have an invalid user due to blank name" do 
    expect(user_with_invalid_name).to_not be_valid 
    end 

    it "should be an invalid user due to blank email" do 
    expect(user_with_invalid_email).to_not be_valid 
    end 

    end 
end 

我每次運行代碼時都會收到以下錯誤消息。

SyntaxError: 
/mnt/c/Users/bjm84/Bloccit/app/models/user.rb:26: syntax error, unexpected 
end-of-input, expecting keyword_end 
# ./spec/models/user_spec.rb:3:in `<top (required)>' 

如果有人能幫我指出這一點,我將不勝感激。這讓我非常興奮。謝謝。

回答

1

錯誤告訴你語法錯誤在你的用戶模型文件的第26行。

/mnt/c/Users/bjm84/Bloccit/app/models/user.rb:26 

它不在spec文件中。