Capybara: How to test the title of a page?

前端 未结 8 1641
一向
一向 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:15

    I added this to my spec helper:

    class Capybara::Session
      def must_have_title(title="")
        find('title').native.text.must_have_content(title)
      end
    end
    

    Then I can just use:

    it 'should have the right title' do
      page.must_have_title('Expected Title')
    end
    

提交回复
热议问题