Capybara: How to test the title of a page?

前端 未结 8 1645
一向
一向 2020-12-08 12:41

In a Rails 3 application using Steak, Capybara and RSpec how do I test the page\'s title?

8条回答
  •  忘掉有多难
    2020-12-08 13:32

    Testing the Title of each page can be done in a much easier way with RSpec.

    require 'spec_helper'
    
    describe PagesController do
      render_views
    
      describe "GET 'home'" do
        before(:each) do
          get 'home'
          @base_title = "Ruby on Rails"
        end
    
        it "should have the correct title " do
          response.should have_selector("title",
                                    :content => @base_title + " | Home")
        end
      end
    end
    

提交回复
热议问题