【问题标题】:syntax error ruby rspec testing [closed]语法错误ruby rspec测试[关闭]
【发布时间】:2017-09-03 01:58:14
【问题描述】:

您好,我在 rspec 文件中找不到语法错误。我已经翻了几十次了,就是找不到。我可以用一双额外的眼睛来帮助我解决这个问题。这是我的规范文件:

require 'rails_helper'

RSpec.describe User, type: :model do
  let(:user) { User.create!(name: "Bloccit User", email: "user@bloccit.com", 
  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("user@bloccit.com").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: 
     "user@bloccit.com")
    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:"user@bloccit.com")}
   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)>'

如果有人能帮我指出这一点,我将不胜感激。这让我很生气。谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby rspec rspec-rails ruby-on-rails-5.1


    【解决方案1】:

    错误是告诉你语法错误在你的用户模型文件的第26行。

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

    它不在规范文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多