Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 验证是否存在电话号码Rspec_Ruby On Rails_Ruby On Rails 3_Rspec - Fatal编程技术网

Ruby on rails 验证是否存在电话号码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

我正在尝试使用rspec验证电话号码的预测。我已将电话号码设为一个字符串。我有以下代码

型号

  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”。您缺少
=>
运算符