I'm writing a Scala test with some ScalaTest matchers.
When my test fails, intellij says something like
{"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","position":27},{"id":"20","position":341},{"id":"19","position":33}]} was not equal to {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","timestamp":"2015-01-28T11:55:44.494Z","content":"Episode","position":27},{"id":"20","timestamp":"2015-01-19T11:55:44.494Z","content":"Program","position":341},{"id":"19","timestamp":"2015-01-17T11:55:44.494Z","content":"Episode","position":33}]}
org.scalatest.exceptions.TestFailedException: {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","position":27},{"id":"20","position":341},{"id":"19","position":33}]} was not equal to {"count":3,"pagination":{"offset":0,"limit":100},"content":{"uri":"http://locahost.com/catalogue/content?order=Query&id=18,20,19"},"list":[{"id":"18","timestamp":"2015-01-28T11:55:44.494Z","content":"Episode","position":27},{"id":"20","timestamp":"2015-01-19T11:55:44.494Z","content":"Program","position":341},{"id":"19","timestamp":"2015-01-17T11:55:44.494Z","content":"Episode","position":33}]}
at org.scalatest.MatchersHelper$.newTestFailedException(MatchersHelper.scala:160)
at org.scalatest.Matchers$ShouldMethodHelper$.shouldMatcher(Matchers.scala:6231)
at org.scalatest.Matchers$AnyShouldWrapper.should(Matchers.scala:6265)
...
However, intellij does not give me the handy see difference in the text feature.
I thought it might be because I'm comparing 2 objects
val responseBody = responseAs[JsValue]
responseBody should be(viewingByAccountIdResponseJson)
but changing it to
assert(responseBody.toString() === viewingByAccountIdResponseJson.toString())
Does not allow me to do a text comparison either.
Is there any way to configure intellij to do this?
(I'm currently using a FlatSpec with Matchers)
Note: This is related to this question Formatting output so that Intellij Idea shows diffs for two texts
However, even using the syntax recommended that intellij might pick up, it does not work.
I see this is not possible at the moment and as of the current moment in time, is a feature request:
https://youtrack.jetbrains.com/issue/SCL-4867
As intellij feature request mentioned by Bruce celebrates it's 7th birthday, some of us have lost their hope (still don't forget to +1 it). Here's an ugly script which allows you to mitigate the issue a bit. Just copy This was not equal to That
line and feed it to the stdin of this script:
| scalatest-diff
cat > ~/bin/scalatest-diff
#!/usr/bin/perl
my $in = join("", <STDIN>);
if( $in =~ m/[^:]+\: (.+?) was not equal to (.+)/so ) {
my $this = $1;
my $that = $2;
$this =~ s/,/,\n/g;
$that =~ s/,/,\n/g;
open(thisFile, ">", "/tmp/this");
open(thatFile, ">", "/tmp/that");
print thisFile $this; close thisFile;
print thatFile $that; close thatFile;
exec("vimdiff /tmp/this /tmp/that");
}
<Ctrl-D>
chmod a+x ~/bin/scalatest-diff
P.S. feel free to change vimdiff to your favorite differ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With