Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate presence of telephone number Rspec
    primarykey
    data
    text
    <p>I am trying to validate the prescence of telephone numbers using rspec. I have set the telephone number to a string. I have the following code. </p> <p><strong>Model</strong> </p> <pre><code> validates_presence_of :name, :address, :telephone, :email validates :email, :presence =&gt; true, :format =&gt; { :with =&gt; email_regex,:message =&gt; 'Enter valid email example@example.com ' } end </code></pre> <p><strong>Factory</strong> </p> <pre><code>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 </code></pre> <p><strong>Spec</strong> </p> <pre><code>describe Company do before(:each) do @company = Factory(:company) @attr = { :name =&gt; "Example", :address =&gt; "123 Shark Road London England SW1 9EP", :telephone =&gt; "(874)052-1258", :email =&gt; "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 =&gt; "")) no_comment_name.should_not be_valid end </code></pre> <p>end</p> <p>I am getting the following error: </p> <blockquote> <p>bundle exec rspec spec/models/company_spec.rb /home/dj/.rvm/gems/ruby-1.9.2-p290/gems/ rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load': /home/<strong><em>/</em>***</strong>/spec/models/com pany_spec.rb:10: syntax error, unexpected tSTRING_BEG, expecting tASSOC (SyntaxError) :telephone " (874)052-1258", ^ /home/<strong><em>/</em>***</strong>/spec/models/company_spec.rb:10: syntax error, unexpected ',', expecting keyword_end :telephone " (874)052-1258", ^</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload