My spec wants to test if a certain substring occurs withing any entry of an array of strings.
p @banner.errors.messages[:base] #=> ["Specify a leader text or an image, not both"]
All my spec really wants to know, is whether or not the “not both” string occurs in any of the array-items in there.
@banner.errors.messages[:base].should include(/not both/)
fails, because "not both" is not included in ["Specify a leader text or an image, not both"]
Note: When I test against the literal string (should include(“Specify…both”), things work. But that seems dirty to me. Such user-faced texts are not critical for the test to pass; and such texts will change: every time the error message is changed, I will need to update my tests.
Maybe like this?
But note that there is a edge case where the match might be over two or more lines, e.g. a line ending with “not ” and the next line is ” both”.