3

I'm using Poltergeist / Capybara for my tests:

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, {
      timeout: 60,
      phantomjs_options: ['--load-images=no'],
      case_insensitive: true # <-- doesn't work
    })
  end
end

but I noticed that I have to rewrite a lot of tests, as Poltergeists driver seems to be case-sensitive. Is there anything I can pass to change this?

supersize
  • 13,764
  • 18
  • 74
  • 133

3 Answers3

3

As @eugen mentions all searches in capybara are case sensitive by default. The problem you mention of having to rewrite tests usually occurs when moving from a driver that does/does-not support css text-transform to one that does-not/does - so the text being matched is or is not having the css text-transform (uppercase/lowercase/capitalize/...) applied. If you want to be able to swap back and forth between drivers and really need case insensitivity you can pass regexes to the different matchers

expect(page).to have_text(/case insensitive text/i)
expect(page).to have_selector(:css, '#div1', text: /case insensitive text/i)
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Okay that makes sense. My driver before was case insensitive. However, I would like to use `expect(page).to have_content` instead of `have_text`. Is this working fine with your answer? – supersize Dec 15 '15 at 23:06
  • Indeed! Thanks for your help! – supersize Dec 15 '15 at 23:11
1

You could use a regex when comparing strings

expect(page.body).to match(%r{#{string}}i)

source: Case insensitive Rspec match

Community
  • 1
  • 1
Laurens
  • 2,420
  • 22
  • 39
1

All searches in capybara are case sensitive, there is no global option to change that. If you need to do case insensitive matching, you'll have to do it on a search by search basis.

eugen
  • 8,916
  • 11
  • 57
  • 65