I am pretty newbie in Ruby and we are using Capybara + Rspec + Poltergeist as the driver.

What I want to do is to expect some text on the webpage I am testing, so I have this simple code:

expect(page).to have_content(text)

But sometimes it fails because "text" can be found in capital letters or lowercase or uppercase ... So, how can I expect the text in a insensitive case matcher? Or, can I use some function to maybe "downcase" all?


1 Answer 1


have_content actually takes a regexp as parameter. You can use the i flag to make the search case insensitive

expect(page).to have_content(/my case insensitive search/i)
  • Just to be sure... I cannot do something like: page_downcased = page.downcase text_downcased = text.downcase expect(page_downcased).to have_content(text_downcased) Or some other method to lowercase/uppercase both compared texts ?
    – LaiaPR
    Jan 27, 2016 at 11:34
  • You can do page.body.downcase, but I find using regex to be more elegant. Jan 27, 2016 at 11:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.