运行rspec时出现以下错误:
bundle exec rspec spec/models/user_spec.rb
故障:
1)名字太长的用户 失败/错误:它{should_not be_vaild} NoMethodError: '
中未定义的方法vaild?' for #<User:0x007f8eebf0d6c0> # ./spec/models/user_spec.rb:39:in
阻止(3个级别)完成0.22196秒6个例子,1个失败
失败的例子:
rspec ./spec/models/user_spec.rb:39#名称太长的用户
我的user.rb文件
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ActiveRecord::Base
attr_accessible :name, :email,
validates :name, presence: true, length: { maximum: 50 }
validates :email, presence: true
end
我的user_spec.rb
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
require 'spec_helper'
describe User do
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 not present" do
before { @user.name = " " }
it { should_not be_valid }
end
describe "when email is not present" do
before { @user.email = " " }
it { should_not be_valid }
end
describe "when name is too long" do
before { @user.name = "a" * 51 }
it { should_not be_vaild }
end
end
答案 0 :(得分:3)
我输错了,错误的有效
有效
不是
vaild