Skip to content

Commit b6069e5

Browse files
committed
Test Runner: Modify rspec_matcher to parse more than one regex in expected values
1 parent a97ad1a commit b6069e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

api-spec-testing/rspec_matchers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ def compare_hash(expected_pairs, actual_hash, test)
219219
def compare_string(expected, actual_value, test, response)
220220
# When you must match a regex. For example:
221221
# match: {task: '/.+:\d+/'}
222-
if expected[0] == "/" && expected[-1] == "/"
223-
/#{expected.tr("/", "")}/ =~ actual_value
222+
if expected[0] == '/' && expected[-1] == '/'
223+
parsed = expected
224+
expected.scan(/\$\{([a-z_0-9]+)\}/) do |match|
225+
parsed = parsed.gsub(/\$\{?#{match.first}\}?/, test.cached_values[match.first])
226+
end
227+
/#{parsed.tr("/", "")}/ =~ actual_value
224228
elsif !!(expected.match?(/[0-9]{1}\.[0-9]+E[0-9]+/))
225229
# When the value in the yaml test is a big number, the format is
226230
# different from what Ruby uses, so we transform X.XXXXEXX to X.XXXXXe+XX

0 commit comments

Comments
 (0)