Skip to content

Commit

Permalink
fix: removed double path in body mismatch descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Aug 11, 2020
1 parent d0330b0 commit 7c1bf90
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void provider2Fails() throws IOException {
mockTestProvider2.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" +
"$.name Expected 'larry' (String) but received 'farry' (String)"));
"body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
assertThat(error.getMismatches(), hasSize(1));
Expand Down Expand Up @@ -152,7 +152,7 @@ public void bothprovidersFail() throws IOException {
mockTestProvider2.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" +
"$.name Expected 'larry' (String) but received 'farry' (String)"));
"body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
assertThat(error.getMismatches(), hasSize(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.com.dius.pact.consumer

import au.com.dius.pact.core.matchers.BodyMismatch
import au.com.dius.pact.core.matchers.Mismatch
import au.com.dius.pact.core.model.Request

Expand All @@ -13,7 +14,10 @@ sealed class PactVerificationResult {
data class PartialMismatch(val mismatches: List<Mismatch>) : PactVerificationResult() {
override fun getDescription(): String {
return mismatches.joinToString("\n") {
it.description()
when (it) {
is BodyMismatch -> "${it.type()} - ${it.path}: ${it.description()}"
else -> "${it.type()} - ${it.description()}"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ data class BodyMismatch @JvmOverloads constructor(
val path: String = "/",
val diff: String? = null
) : Mismatch() {
override fun description() = "$path $mismatch"
override fun description() = mismatch
override fun type() = "body"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ class XmlBodyMatcherSpec extends Specification {

then:
result.size() == 3
result*.description() == ['$.animals.dog.1 Unexpected child <dog/>',
'$.animals.cat.1 Unexpected child <cat/>',
'$.animals.cat.2 Unexpected child <cat/>']
result*.description() == ['Unexpected child <dog/>',
'Unexpected child <cat/>',
'Unexpected child <cat/>']
}

def 'type matcher when an element has different types of children'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MessageComparisonSpec extends Specification {
then:
result instanceof Ok
result.value.mismatches.collectEntries { [ it.key, it.value*.description() ] } == [
'$.b': ['$.b Expected \'2\' (String) but received \'3\' (String)']
'$.b': ['Expected \'2\' (String) but received \'3\' (String)']
]
}

Expand All @@ -38,7 +38,7 @@ class MessageComparisonSpec extends Specification {
result instanceof Ok
result.value.mismatches.collectEntries { [ it.key, it.value*.description() ] } == [
'/': [
'/ Expected body \'{"a":1,"b":"2"}\' to match \'{"a":1,"b":"3"}\' using equality but did not match'
'Expected body \'{"a":1,"b":"2"}\' to match \'{"a":1,"b":"3"}\' using equality but did not match'
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ResponseComparisonSpec extends Specification {
expect:
result instanceof Ok
result.value.mismatches.collectEntries { [ it.key, it.value*.description() ] } == [
'$.stuff': ["\$.stuff Expected 'is good' (String) but received 'should make the test fail' (String)"]
'$.stuff': ["Expected 'is good' (String) but received 'should make the test fail' (String)"]
]
result.value.diff[1] == '- "stuff": "is good"'
result.value.diff[2] == '+ "stuff": "should make the test fail"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class JsonReporterSpec extends Specification {
reportJson.execution[0].interactions[0].verification.status == ['expected status of 201 but was 200']
reportJson.execution[0].interactions[0].verification.header == ['HEADER-X': ["Expected a header 'HEADER-X' but was missing"]]
reportJson.execution[0].interactions[0].verification.body.mismatches == [
'$.0': ['$.0 Expected doesNotExist="Test" but was missing'],
'$.1': ['$.1 Expected doesNotExist="Test" but was missing']
'$.0': ['Expected doesNotExist="Test" but was missing'],
'$.1': ['Expected doesNotExist="Test" but was missing']
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class MarkdownReporterSpec extends Specification {
|
|| Path | Failure |
|| ---- | ------- |
||`$.0`|$.0 Expected doesNotExist="Test" but was missing|
||`$.1`|$.1 Expected doesNotExist="Test" but was missing|
||`$.0`|Expected doesNotExist="Test" but was missing|
||`$.1`|Expected doesNotExist="Test" but was missing|
|
|
|Diff:
Expand Down

0 comments on commit 7c1bf90

Please sign in to comment.