Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2 | 3 | 4|Last
Lessons:-Pretty RSpec

Pretty RSpec


We noted in Section 5.3.1 that the tests for the static pages are getting a little verbose and repetitive (Listing 5.20). In this section we’ll make use of the latest features of RSpec to make our tests more compact and elegant. Let’s take a look at a couple of the examples to see how they can be improved:


describe   "Home page"   do
      it       "should  have  the  h1  'Sample App'"    do
        visit root path
        page. should  have  selector  (  'h1' ,  text:  'Sample App ')




One thing we notice is that all three examples include a visit to the root path. We can eliminate this duplication with a before block:




This uses the line

before   { visit  root  path  }


to visit the root path before each example. (The before method can also be invoked with before(:each), which is a synonym.)

                Another source of duplication appears in each example; we have both


it   "should have the h1 'Sample App'"   do
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

  Students (0)