Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|Last
Lessons:-Validating Presence

 

The initial validation tests then appear as in Listing 6.11.

 

The first new example is just a sanity check, verifying that the @user object is initially valid:

it { should be valid }

 

This is another example of the RSpec boolean convention we saw in Section 6.2.1: Whenever an object responds to a boolean method foo?, there is a corresponding test method called be_foo. In this case, we can test the result of calling

@ user .valid ?

 

with

@ user. should  be  valid  

 

  As before, subject { @user } lets us leave off @user, yielding it { should be valid }

it  { should  be  valid }

 

The second test first sets the user’s name to an invalid (blank) value, and then tests to see that the resulting @user object is invalid:

describe  "when name is not present"  do
         before { @user .name  =  " "  }
         it { should not be valid }
end
 
 
 
image
Pooja   Negi

Skills    Ruby On Rails

Qualifications :- High School - SSN high school, College/University - HNBGU, College/University - SRHU,
Location :-Ranipokhari,Rishikesh,Uttarakhand,India
Description:- Student
Explore
 

  Students (0)