Skip to content

Commit

Permalink
fix: correct equality error message to match compatibility-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jul 26, 2023
1 parent 95a19e0 commit 8a22a66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rust/pact_ffi/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn post_to_mock_server_with_mismatches() {
pactffi_cleanup_mock_server(port);

assert_eq!(
"[{\"method\":\"POST\",\"mismatches\":[{\"actual\":\"\\\"no-very-bar\\\"\",\"expected\":\"\\\"bar\\\"\",\"mismatch\":\"Expected 'no-very-bar' (String) be equal to 'bar' (String)\",\"path\":\"$.foo\",\"type\":\"BodyMismatch\"}],\"path\":\"/path\",\"type\":\"request-mismatch\"}]",
"[{\"method\":\"POST\",\"mismatches\":[{\"actual\":\"\\\"no-very-bar\\\"\",\"expected\":\"\\\"bar\\\"\",\"mismatch\":\"Expected 'no-very-bar' (String) to be equal to 'bar' (String)\",\"path\":\"$.foo\",\"type\":\"BodyMismatch\"}],\"path\":\"/path\",\"type\":\"request-mismatch\"}]",
mismatches
);
}
Expand Down
22 changes: 11 additions & 11 deletions rust/pact_matching/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Matches<&Value> for Value {
if self == actual {
Ok(())
} else {
Err(anyhow!("Expected {} ({}) be equal to {} ({})",
Err(anyhow!("Expected {} ({}) to be equal to {} ({})",
value_of(actual), type_of(actual), value_of(self), type_of(self)))
}
},
Expand Down Expand Up @@ -641,7 +641,7 @@ mod tests {
expect!(result).to(be_ok());

let result = match_json(&val1.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 'other value' (String) be equal to 'string value' (String)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 'other value' (String) to be equal to 'string value' (String)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch {
path: "$".to_string(),
expected: val1.body.value(),
Expand All @@ -658,7 +658,7 @@ mod tests {
expect!(result).to(be_ok());

let result = match_json(&val1.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 200 (Integer) be equal to 100 (Integer)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 200 (Integer) to be equal to 100 (Integer)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch {
path: "$".to_string(),
expected: val1.body.value(),
Expand All @@ -675,7 +675,7 @@ mod tests {
expect!(result).to(be_ok());

let result = match_json(&val1.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 100.02 (Decimal) be equal to 100.01 (Decimal)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 100.02 (Decimal) to be equal to 100.01 (Decimal)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch {
path: "$".to_string(),
expected: val1.body.value(),
Expand All @@ -692,7 +692,7 @@ mod tests {
expect!(result).to(be_ok());

let result = match_json(&val1.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected false (Boolean) be equal to true (Boolean)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected false (Boolean) to be equal to true (Boolean)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch {
path: "$".to_string(),
expected: val1.body.value(),
Expand All @@ -709,7 +709,7 @@ mod tests {
expect!(result).to(be_ok());

let result = match_json(&val1.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 33 (Integer) be equal to null (Null)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 33 (Integer) to be equal to null (Null)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch {
path: "$".to_string(),
expected: val1.clone().body.value(),
Expand Down Expand Up @@ -739,7 +739,7 @@ mod tests {
expect!(result).to(be_err());

let result = match_json(&val2.clone(), &val3.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result)).to(be_equal_to("Expected 44 (Integer) be equal to 22 (Integer)".to_string()));
expect!(mismatch_message(&result)).to(be_equal_to("Expected 44 (Integer) to be equal to 22 (Integer)".to_string()));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch { path: "$[1]".to_string(),
expected: Some("22".into()), actual: Some("44".into()), mismatch: "".to_string() } ]));

Expand All @@ -756,7 +756,7 @@ mod tests {
expect!(&mismatch).to(be_equal_to(&Mismatch::BodyMismatch { path: "$[1]".to_string(),
expected: Some("22".into()),
actual: Some("44".into()), mismatch: "".to_string()}));
expect!(mismatch.description()).to(be_equal_to("$[1] -> Expected 44 (Integer) be equal to 22 (Integer)".to_string()));
expect!(mismatch.description()).to(be_equal_to("$[1] -> Expected 44 (Integer) to be equal to 22 (Integer)".to_string()));
let mismatch = mismatches[1].clone();
expect!(&mismatch).to(be_equal_to(&Mismatch::BodyMismatch { path: "$".to_string(),
expected: Some("[11,22,33]".into()),
Expand Down Expand Up @@ -794,7 +794,7 @@ mod tests {
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected an empty Map but received {\"a\":1,\"b\":2}"));

let result = match_json(&val2.clone(), &val3.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 3 (Integer) be equal to 2 (Integer)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 3 (Integer) to be equal to 2 (Integer)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch { path: "$.b".to_string(),
expected: Some("2".into()), actual: Some("3".into()), mismatch: "".to_string() } ]));

Expand All @@ -809,7 +809,7 @@ mod tests {
} ]));

let result = match_json(&val3.clone(), &val4.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 2 (Integer) be equal to 3 (Integer)"));
expect!(mismatch_message(&result).as_str()).to(be_equal_to("Expected 2 (Integer) to be equal to 3 (Integer)"));
expect!(result).to(be_err().value(vec![ Mismatch::BodyMismatch { path: "$.b".to_string(),
expected: Some("3".into()),
actual: Some("2".into()), mismatch: "".to_string() } ]));
Expand All @@ -826,7 +826,7 @@ mod tests {
expect!(&mismatch).to(be_equal_to(&Mismatch::BodyMismatch { path: "$.b".to_string(),
expected: Some("3".into()),
actual: Some("2".into()), mismatch: "".to_string()}));
expect!(mismatch.description()).to(be_equal_to("$.b -> Expected 2 (Integer) be equal to 3 (Integer)".to_string()));
expect!(mismatch.description()).to(be_equal_to("$.b -> Expected 2 (Integer) to be equal to 3 (Integer)".to_string()));

let result = match_json(&val4.clone(), &val2.clone(), &CoreMatchingContext::with_config(DiffConfig::AllowUnexpectedKeys));
let mismatches = result.unwrap_err();
Expand Down

0 comments on commit 8a22a66

Please sign in to comment.