Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6|Last
Lessons:- Test-driven Development

The code in Listing 3.9 is pure Ruby, but even if you’ve studied Ruby before it probably won’t look very familiar. This is because RSpec uses the general malleability of Ruby to define a domain-specific language (DSL) built just for testing. The important point is that you do not need to understand RSpec’s syntax to be able to use RSpec. It may seem like magic at first, but RSpec and Capybara are designed to read more or less like English, and if you follow the examples from the generate script and the other examples in this tutorial, you’ll pick it up fairly quickly    

Listing 3.9 contains a describe block with one example, i.e., a block starting with it "..." do:

describe  "Home page"  do
   it "should have the content 'Sample App'" do
     visit  '/static pages/home'
      page.should have content ( 'Sample App' )
  end
end

 

The first line indicates that we are describing the Home page. This is just a string, and it can be anything you want; RSpec doesn’t care, but you and other human readers probably do. Then the spec says that when you visit the Home page at /static_pages/home, the content should contain the words ‘‘Sample App.’’ As with the first line, what goes inside the quote marks is irrelevant to RSpec and is intended to be descriptive to human readers. Then the line 

visit  '/static pages/home'

 uses the Capybara function visit to simulate visiting the URI /static_pages/home in a browser, while the line

page.should have content ( 'Sample App' )

uses the page variable (also provided by Capybara) to test that the resulting page has the right content 

   To run the test, we have several options, including some convenient but rather advanced tools discussed in Section 3.6. For now, we’ll use the rspec command at the command line (executed with bundle exec to ensure that RSpec runs in the environment specified by our Gemfile):9

$ bundle exec rspec spec/requests/static pages spec.rb

 This yields a failing test. The appearance of the result depends on your system; on my system, the red failing test appears as in Figure 3.6.10 (The screenshot, which predates,

 

 
 
 
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)