In a Rails 3 application using Steak, Capybara and RSpec how do I test the page's title?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Rspec controller error expecting <“index”> but
In order to test for the title of a page with Rspec and Capybara 2.1 you could use
expect(page).to have_title 'Title text'
another option is
expect(page).to have_css 'title', text: 'Title text', visible: false
Since Capybara 2.1 the default is
Capybara.ignore_hidden_elements = true
, and because the title element is invisible you need the optionvisible: false
for the search to include non visible page elements.it { should have_selector "title", text: full_title("Your title here") }
This works under Rails 3.1.10, Capybara 2.0.2 and Rspec 2.12, and allows matching partial contents:
Testing the Title of each page can be done in a much easier way with RSpec.
I added this to my spec helper:
Then I can just use:
You should be able to search for the
title
element to make sure it contains the text you want: