m26a
m26a

Reputation: 1413

Minitest/Mocha: How to validate the argument with a regex

How can I create an expectation with a regex in the string that the method is receiving? I'm using Mocha and Mintest.

I tried this but it doesn't work:

Logger.expects(:info).with(%r{/hello, world!/}).once

Upvotes: 0

Views: 747

Answers (1)

m26a
m26a

Reputation: 1413

You should use regexp_matches.

Your code should look like this:

Logger.expects(:info).with(regexp_matches(%r{/hello, world!/})).once

This method is documented here: #regexp_matches(regexp) ⇒ RegexpMatches.

Upvotes: 2

Related Questions