Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

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

 Exercises

 

1. The codein Listing 5.27 for testing static pages is compact but is still a bit repetitive. RSpec supports a facility called shared examples to eliminate the kind of duplication. By following the example in Listing 5.35, fill in the missing tests for the Help, About, and Contact pages. Note that the let command, introduced briefly in Listing 3.30, creates a local variable with the given value on demand (i.e., when the variable is used), in contrast to an instance variable, which is created upon assignment.

2. You may have noticed that our tests for the layout links test the routing but don’t actually check that the links on the layout go to the right pages. One way to implement thesetests is to use visit and   Click_link insidethe RSpec integration test. Fill in the code in Listing 5.36 to verify that all the layout links are properly defined.

3. Eliminate the need for the full_title test helper in Listing 5.26 by writing tests for the original helper method, as shown in Listing 5.37. (You will have to create both the spec/helpers directory and the application_helper_spec.rb file.) Then include it into the test using the code in Listing 5.38. Verify by running the test suite that the new code is still valid. Note: Listing 5.37 uses regular expressions, which we’ll learn more about in Section 6.2.4. (Thanks to Alex Chaffee for the suggestion and code used in this exercise.)

 

Listing 5.35 Using an RSpec shared example to eliminate test duplication.
spec/requests/static_pages_spec.rb

 

                              

                                     

 
 
 
image
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)