Ruby on rails 验证是否存在电话号码Rspec
我正在尝试使用rspec验证电话号码的预测。我已将电话号码设为一个字符串。我有以下代码 型号Ruby on rails 验证是否存在电话号码Rspec,ruby-on-rails,ruby-on-rails-3,rspec,Ruby On Rails,Ruby On Rails 3,Rspec,我正在尝试使用rspec验证电话号码的预测。我已将电话号码设为一个字符串。我有以下代码 型号 validates_presence_of :name, :address, :telephone, :email validates :email, :presence => true, :format => { :with => email_regex,:message => 'Enter valid email examp
validates_presence_of :name, :address, :telephone, :email
validates :email, :presence => true,
:format => { :with => email_regex,:message => 'Enter valid email example@example.com ' }
end
Factory.define :company do |c|
c.name "Example"
c.address "123 Shark Road, London, England, SW1 9EP"
c.telephone "(874)052-1258"
c.email "example@example.co.uk"
end
describe Company do
before(:each) do
@company = Factory(:company)
@attr = {
:name => "Example",
:address => "123 Shark Road London England SW1 9EP",
:telephone => "(874)052-1258",
:email => "example@example.co.uk"
}
end
it "should create a new instance given valid attributes" do
Company.create!(@attr)
end
it "should commenters name" do
no_comment_name = Company.new(@attr.merge(:name => ""))
no_comment_name.should_not be_valid
end
工厂
validates_presence_of :name, :address, :telephone, :email
validates :email, :presence => true,
:format => { :with => email_regex,:message => 'Enter valid email example@example.com ' }
end
Factory.define :company do |c|
c.name "Example"
c.address "123 Shark Road, London, England, SW1 9EP"
c.telephone "(874)052-1258"
c.email "example@example.co.uk"
end
describe Company do
before(:each) do
@company = Factory(:company)
@attr = {
:name => "Example",
:address => "123 Shark Road London England SW1 9EP",
:telephone => "(874)052-1258",
:email => "example@example.co.uk"
}
end
it "should create a new instance given valid attributes" do
Company.create!(@attr)
end
it "should commenters name" do
no_comment_name = Company.new(@attr.merge(:name => ""))
no_comment_name.should_not be_valid
end
规格
validates_presence_of :name, :address, :telephone, :email
validates :email, :presence => true,
:format => { :with => email_regex,:message => 'Enter valid email example@example.com ' }
end
Factory.define :company do |c|
c.name "Example"
c.address "123 Shark Road, London, England, SW1 9EP"
c.telephone "(874)052-1258"
c.email "example@example.co.uk"
end
describe Company do
before(:each) do
@company = Factory(:company)
@attr = {
:name => "Example",
:address => "123 Shark Road London England SW1 9EP",
:telephone => "(874)052-1258",
:email => "example@example.co.uk"
}
end
it "should create a new instance given valid attributes" do
Company.create!(@attr)
end
it "should commenters name" do
no_comment_name = Company.new(@attr.merge(:name => ""))
no_comment_name.should_not be_valid
end
结束
我得到以下错误:
bundle exec rspec规格/型号/公司规格rb
/home/dj/.rvm/gems/ruby-1.9.2-p290/gems/
rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in'load':
/主页//***/spec/models/com
pany_spec.rb:10:语法错误,意外的tSTRING_BEG,应为
tASSOC(SyntaxError)
:电话“(874)052-1258”,
^
/home//***/spec/models/company\u spec.rb:10:语法错误,
意外的“,”,应为关键字_end
:电话“(874)052-1258”,
^
错误在您的前_中,这里是:电话“(874)052-1258”。您缺少
=>
运算符