Skip to content

Commit

Permalink
Ensures that regex is asserted also for RegexProperty not only Pattern
Browse files Browse the repository at this point in the history
fixes gh-1200
  • Loading branch information
marcingrzejszczak committed Nov 8, 2019
1 parent 7326dec commit 22d7be7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Expand Up @@ -244,6 +244,14 @@ class Common {
assert value ==~ pattern
}

void assertThatSidesMatch(RegexProperty pattern, String value) {
assert value ==~ pattern.pattern
}

void assertThatSidesMatch(String value, RegexProperty pattern) {
assert value ==~ pattern.pattern
}

void assertThatSidesMatch(MatchingStrategy firstSide, MatchingStrategy secondSide) {
if (firstSide.type == MatchingStrategy.Type.ABSENT && secondSide.type != MatchingStrategy.Type.ABSENT) {
throwAbsentError()
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.springframework.cloud.contract.spec.internal

import spock.lang.Issue
import spock.lang.Specification

import org.springframework.cloud.contract.spec.Contract
Expand Down Expand Up @@ -422,4 +423,23 @@ then:
expect:
contract != null
}

@Issue("1200")
def 'should fail when regex do not match the concrete value'() {
when:
Contract.make {
request {
method 'GET'
url '/any'
}
response {
status OK()
body([
time: $(p(regex(iso8601WithOffset())),c( "thisIsNotADate"))
])
}
}
then:
thrown(AssertionError)
}
}

0 comments on commit 22d7be7

Please sign in to comment.