When checking for a multiline string in
Capybara, you need to use page.text
because page.source does not preserve new lines - so "a\nb" would come out
as "a b" in page.source. Here’s a sample Cucumber step definition:
Then/^I should see:$/do|text|page.text.shouldincludetextend
About thoughtbot
We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.
Upgrade your codebase with a Code Audit
Learn how we can help you understand the current state of your code quality, speed up delivery times, improve developer happiness, and level up your user experience