Multiline strings in Capybara

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.should include text
end

Pair with one of our expert developers to level up your skills with Coaching by thoughtbot. Save time learning best practices and techniques for reducing technical debt in Ember, Ruby, Haskell, and Go in 1-on-1 sessions tailored to your goals.