Read more

RSpec: How to check if a string contains terms in a desired order

Emanuel
September 11, 2018Software engineer at makandra GmbH

There seems to be no built-in matcher in RSpec to check if a string contains terms in the desired order. A simple workaround is to use a regular expression that also matches newlines (m-modifier).

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Cons:

  • The readability when terms need to be escaped is bad
  • A failed spec has an error which needs manually action to be understood (Search if terms appear and in which order)

Example:

expect(ActionMailer::Base.last.to_s).to match(/Dear customer.*Account canceled.*You Awesome Company/m)
Posted by Emanuel to makandra dev (2018-09-11 13:24)