0

I use Capybara 2.0.2 and Rspec 2.10.0 to test page title:

  page.should have_selector('title', :text => 'Page title') 

But it's doesn't work. Can anyone help me?

Leo Lukin
  • 1,201
  • 1
  • 11
  • 24
  • 1
    For anyone using Capybara 2.1.0+ you can use `expect(page).to have_title "my_title"` as described here: http://stackoverflow.com/a/14139814/805003 – manafire Dec 02 '13 at 01:10

2 Answers2

1

I had the same issue and ended up writing my own matcher to make it work.
See StackOverflow Q&A RSpec & Capybara 2.0 tripping up my have_selector tests for details and interesting discussion around the matter.

Community
  • 1
  • 1
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
0

Not sure which version of gems you are using but I ran into a similar instance where using :text failed but when I used :content it passed the test.

Try replacing

 page.should have_selector('title', :text => 'Page title') 

with

page.should have_selector("title", :content => "Page title")
Learner
  • 4,596
  • 1
  • 20
  • 23
  • You shouldnt use :content as this key has been removed in later versions of Capybara. see this link for the reasons https://github.com/jnicklas/capybara/pull/602 – Dono Jan 24 '14 at 13:15