Overriding "should"

18 views
Skip to first unread message

Ittai Zeidman

unread,
May 8, 2015, 2:04:39 AM5/8/15
to specs2...@googlegroups.com
Hi,
I sometimes have the urge to use a different keyword than "should" in my mutable specifications.
For example when I want to document things I don't support I would love to have something like
"MyClass" doesNotSupport ... and of course have that print as "does not support" in the reports.
Is there an easy mechanism to do that?

etorreborre

unread,
May 8, 2015, 2:12:40 AM5/8/15
to specs2...@googlegroups.com, itt...@wix.com
The intended way to do that is to write whatever you want and use the `>>` operator:

class MySpec extends mutable.Specification {
  "MyClass does not support" >> {
     "this" >> { badStuff }
     "and *especially* that" >> { evenWorseStuff }
  }  
}

You could also have a look at how should is implemented and add your own implicit conversions but the purpose of `>>` is precisely to let you be free with your text and not slave to the should/in paradigm.

Eric.

Ittai Zeidman

unread,
May 8, 2015, 2:18:08 AM5/8/15
to specs2...@googlegroups.com, itt...@wix.com
Very nice, thanks!

Ittai Zeidman

unread,
May 12, 2016, 1:25:56 AM5/12/16
to specs2-users, itt...@wix.com
Hi Eric,
I came back to this issue and wanted to replace "should" with "of" for a specific case.
I went to look at how it's implemented and it's a "private [specs2]" scope.
WDYT about making it public? 
Other options are to copy all that code or to move my one liner to specs2 package. WDYT?

Thanks!

etorreborre

unread,
May 14, 2016, 3:36:14 AM5/14/16
to specs2-users, itt...@wix.com
I think I prefer the second option. I have tried to put private[specs2] in some parts where I thought things might not be stable in terms of API.
So you know that this part could have to be rewritten in a future upgrade.

Eric.

Ittai Zeidman

unread,
May 14, 2016, 2:39:58 PM5/14/16
to etorreborre, specs2-users
I ended up by putting my one liner in the specs2 package.
I think it's a reasonable mix between duplicating as little code as possible and being aware of the brittleness of the API.
Thanks!
--

Ittai Zeidman

Cell: 054-6735021

40 Hanamal street, Tel Aviv, Israel



Reply all
Reply to author
Forward
0 new messages