语法错误 ruby rspec 测试
syntax error ruby rspec testing
你好,我在我的 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)>'
如果有人能帮我查明这一点,我将不胜感激。这让我非常恼火。谢谢
错误告诉您语法错误在您的 用户模型文件.
的第 26 行
/mnt/c/Users/bjm84/Bloccit/app/models/user.rb:26
它不在规范文件中。
你好,我在我的 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)>'
如果有人能帮我查明这一点,我将不胜感激。这让我非常恼火。谢谢
错误告诉您语法错误在您的 用户模型文件.
的第 26 行/mnt/c/Users/bjm84/Bloccit/app/models/user.rb:26
它不在规范文件中。