Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive Rspec match

I'm writing a Capybara test and using Rspec for the assertions. My test is failing because there is a CSS style being applied that is causing the text to be in all caps. How can I rewrite this so that it is a case insensitive assertion?

"ALL CAPS".should include('All Caps')
like image 935
Andrew Avatar asked Jul 03 '12 17:07

Andrew


4 Answers

Here's improving on phoet's solution:

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

Unfortunately the syntax highlighting here isn't doing it much justice (it looks perfectly fine in Sublime Text)

like image 91
prusswan Avatar answered Oct 22 '22 01:10

prusswan


I only run into this issue when:

  • Using poltergeist driver. (I don't know if this also happens with other drivers)

  • Inspecting page, not page.body for expectations: expect(page).to ...

So, If I do expect(page.body).to ... it just works and solved the issue.

like image 45
Robin Avatar answered Oct 22 '22 00:10

Robin


how about using a regex to do this?

"ALL CAPS".should match(/#{Regexp.escape('All Caps')}/i)
like image 6
phoet Avatar answered Oct 22 '22 01:10

phoet


How about downcasing both ends of the assertion?

"ALL CAPS".downcase.should include('All Caps'.downcase)
like image 6
bruno077 Avatar answered Oct 22 '22 01:10

bruno077