These are chat archives for etorreborre/specs2

30th
May 2018
Alexander Samsig
@Asamsig
May 30 2018 06:45
What is the best way to use answers, if I want to access one of the parameters when doing my stubbing? Currently it is a real pain having to cast the parameter to an Array[Any], and then access the parameter I want, and casting that again.
Alexander Samsig
@Asamsig
May 30 2018 06:58
It looks like to me, that if answers offered an alternative with a signature like answers(function: InvocationOnMock => T)you would be able to call .getArguments() on that to access the array of parameters. Even more so you could just create an alternative offering answers(function: Array[Any] => T).
Eric Torreborre
@etorreborre
May 30 2018 07:32
Right, a fix is coming up stay tuned
Igal Tabachnik
@hmemcpy
May 30 2018 07:39
Hi Eric, I was wondering if there was any way to suppress throwing exceptions from getDescription, if there's a problem building the descripitions
for example, when there's some exception thrown from some val on a spec class
Eric Torreborre
@etorreborre
May 30 2018 07:40
Exceptions = bad. More seriously yes we could always try/catch + report them
Igal Tabachnik
@hmemcpy
May 30 2018 07:40
I end up catching the UserException that specs2 produces
But I'm integrating with bazel, and they use the Descriptions to apply filtering
and it blows up during applying filtering, because it can't build the description tree...
So I'm not quite sure how to solve it :) If I return an empty description, it will fail with "unable to match filter", which is not the error I really want
Eric Torreborre
@etorreborre
May 30 2018 07:41
so in that case you would still like to see a description tree where some nodes are DescriptionException: “boom”?
Igal Tabachnik
@hmemcpy
May 30 2018 07:42
Hmm maybe.
In my case, I did an even eviler thing, i.e.
ggrrr class Foo extends Specification { val boom: String = { throw new Exception("Boom") }
there's nothing to be done here, specs2 behaves exactly as it should
throws a user exception, saying it cannot initialize "Foo"
(exceptions are evil :)
Eric Torreborre
@etorreborre
May 30 2018 07:44
Is it possible to at least use lazy vals?
Igal Tabachnik
@hmemcpy
May 30 2018 07:47
oh yeah, with lazy val this doesn't blow up!
makes sense
I don't really have an idea here, I'm sure you need to evaluate everything to build descriptions from fragments
and fragments may throw
Anyway, I'm handling this in bazel/rules_scala for now, propagating the exception so it gets printed in the resulting xml
Eric Torreborre
@etorreborre
May 30 2018 07:49
Well Fragment = Description + Execution. In that case (a throwing val) I think that specs2 does not even have the time to create a fragment
Igal Tabachnik
@hmemcpy
May 30 2018 07:50
Oh well, I need to examine our own usecases and possibly suggest people stop using class-level vals to initialize stuff that may throw
let's enjoy DelayedInit while we still can :)
Eric Torreborre
@etorreborre
May 30 2018 07:51
yes naked vals doing initialization are clearly dangerous
Igal Tabachnik
@hmemcpy
May 30 2018 07:53
Anyway, thanks! I'm not sure you're following, but specs2 support in Bazel/IntelliJ is getting much better
Eric Torreborre
@etorreborre
May 30 2018 07:57
No I haven’t been following that because we are not Bazel users (very much multi-repo here) but what is there to know about the better IntelliJ support? I haven’t been updating my IntelliJ Scala plugin for a while (doing a fair chunk of Haskell these days)
Ha, standup time TTYL
Igal Tabachnik
@hmemcpy
May 30 2018 08:02
Enjoy your standup!
Well, the bazel integration is its own service, it doesn't use any existing scala-plugin code
So I implemented many of the run capabilities myself, and contributed them upstream to the bazel plugin (which is developed by Google)
And in bazel itself there's support for running external test frameworks, so we implemented a layer that talks to specs2. Essentially, bazel executes the specs junit runner
It works well now :)
And I hear you, we are gradually migrating to a monorepo, but it's a very lengthy process...
Eric Torreborre
@etorreborre
May 30 2018 08:33
I am still on the fence with monorepos. They can add a productivity + consistency boost but the downsides seems to me that you need more tooling efforts and more care to avoid creating a big ball of mud in between projects
Alexander Samsig
@Asamsig
May 30 2018 09:25

@etorreborre

Right, a fix is coming up stay tuned

Was this aimed at my inquiry? If so what timeline are we looking at? :D

Eric Torreborre
@etorreborre
May 30 2018 09:28
Yes. 4.2.1-ca75f1d09-20180530093100 should be available soon for you to try out but publishing to sonatype takes forever today
If you don’t want to wait you can publishLocal from master
Eric Torreborre
@etorreborre
May 30 2018 10:02
Ok @Asamsig 4.2.1-ca75f1d09-20180530093100 is ready
Alexander Samsig
@Asamsig
May 30 2018 10:38
Cool! Thanks :+1:
Alexander Samsig
@Asamsig
May 30 2018 12:00

Hey again, after upgrading to the newest version, some of my tests are failing in a very weird manner. I have a method that I've mocked like so:

tokenHasher.hash(anyString, any[Option[String]])(any[ExecutionContext]) returns Future.successful(
      "superhashedtoken"
    )

The method is defined like this:

def hash(plainValue: String, extractSaltFrom: Option[String] = None)(implicit executionContext: ExecutionContext): Future[String]
If I in my code then leave out the second parameter, and let it default to None, through the default parameter, then the mock fails and returns null, if I on the other hand explicitly give None, the mock works as intended
Alexander Samsig
@Asamsig
May 30 2018 12:06
Okay, I seem to have found a why. Using any[Option[String]] fails, using anyObject[Option[String]] or any[Option[String]]() it works. What is the purpose of the new any overload? It didn't exist in the version I was running earlier.
Eric Torreborre
@etorreborre
May 30 2018 14:38
I don’t remember but probably this mirrors the difference between Any and AnyRef