Case insensitive Rspec match

后端 未结 6 687
温柔的废话
温柔的废话 2021-02-12 10:00

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 ca

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-12 10:27

    Also, if you are using Capybara, you can use the have_content matcher which is case insensitive:

    ALL CAPS

    find('h1').should have_content('All Caps')

    Update: I guess I was partly wrong. Consider this:

    Title Case

    puts find('h1').text # TITLE CASE < notice all caps puts find('h1').has_content?('Title Case') # true puts find('h1').has_content?('TITLE CASE') # false puts find('h1').has_content?('title case') # false

    It's strange to me that the text returned is in all caps (how it's styled after CSS), but the matcher is actually testing against the text in the unstyled HTML. I spent a while digging through the source code and I still can't figure out why this works.

提交回复
热议问题