Ruby On Rails Classroom image

Neha  Jaggi / Professional / 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
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


  Students (0)