Is the message for the incorrect result ever used?

4 views
Skip to first unread message

Alexey Romanov

unread,
Feb 28, 2011, 5:34:20 AM2/28/11
to specs...@googlegroups.com
As we know, matcher.apply(a) returns (success, okMessage, koMessage).
If success == true, okMessage will be displayed; if success == false,
koMessage will be instead. However, is koMessage ever used if success
== false (and vice versa)? I tried to come up with a situation where
it would make sense to use it, but wasn't able to. Am I missing
something, or could the matchers equally well return (success,
message)? In the second case, something might be done with implicit
conversions...

Yours, Alexey Romanov

etorreborre

unread,
Feb 28, 2011, 6:03:19 AM2/28/11
to specs-users
It is used when you create the negation of a matcher:

def isOdd = isEven.not

E.

Alexey Romanov

unread,
Feb 28, 2011, 6:25:55 AM2/28/11
to specs...@googlegroups.com, etorreborre
Is it really?

`not` is defined to return (!result.success, result.koMessage,
result.okMessage) (where result is the result for the original
matcher). So we use both messages in constructing the _messages_ for
the negated matcher. But again, only one of them will be shown. And it
is the one that corresponds to correct result for the original
matcher.

If matcher.not succeeds (that is, matcher fails), the okMessage
(result.koMessage) is shown, and result.okMessage remains unused. And
if it fails, we show koMessage, which is result.okMessage, and
result.koMessage is unused.

So far as I can see, the same applies to the `and` and `or` methods.

Yours, Alexey Romanov

> --
> You received this message because you are subscribed to the Google Groups "specs-users" group.
> To post to this group, send email to specs...@googlegroups.com.
> To unsubscribe from this group, send email to specs-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/specs-users?hl=en.
>
>

etorreborre

unread,
Feb 28, 2011, 5:35:32 PM2/28/11
to specs-users
> So we use both messages in constructing the _messages_ for the negated matcher.

True, but we need the "ok" message from the first matcher to build the
"ko" message of the second. So if the first result did not contain the
"ok" message we could not have done that.

Or,... I'm really missing something and you need to show me a detailed
example of how to do things better!

And, that being said, in the upcoming specs2, you will be able to
define matchers in many different ways, from functions:

// just the ko message, the ok message is built by adding "not -" in
front of it
val m: Matcher[String] = ((_: String).startsWith("hello"), "doesn't
start with hello")
// the ok and ko message
val m1: Matcher[String] = ((_: String).startsWith("hello"), "starts
with hello", "doesn't start with hello")
// a function for the ko message
val m2: Matcher[String] = ((_: String).startsWith("hello"),
(s:String) => s+ "doesn't start with hello")
// a function for the ok and the ko message
val m3: Matcher[String] = ((_: String).startsWith("hello"),
(s:String) => s+ "starts with hello", (s:String) => s+ "doesn't start
with hello")

Eric.

On Feb 28, 10:25 pm, Alexey Romanov <alexey.v.roma...@gmail.com>
wrote:

Alexey Romanov

unread,
Feb 28, 2011, 5:42:30 PM2/28/11
to specs...@googlegroups.com, etorreborre
On Tue, Mar 1, 2011 at 1:35 AM, etorreborre <etorr...@gmail.com> wrote:
>> So we use both messages in constructing the _messages_ for the negated matcher.
>
> True, but we need the "ok" message from the first matcher to build the
> "ko" message of the second. So if the first result did not contain the
> "ok" message we could not have done that.
>
> Or,... I'm really missing something and you need to show me a detailed
> example of how to do things better!

I'll try to do it sometime this week.

Yours, Alexey Romanov

> And, that being said, in the upcoming specs2, you will be able to
> define matchers in many different ways, from functions:
>
>  // just the ko message, the ok message is built by adding "not -" in
> front of it
>  val m: Matcher[String]  = ((_: String).startsWith("hello"), "doesn't
> start with hello")
>  // the ok and ko message
>  val m1: Matcher[String]  = ((_: String).startsWith("hello"), "starts
> with hello", "doesn't start with hello")
>  // a function for the ko message
>  val m2: Matcher[String] = ((_: String).startsWith("hello"),
> (s:String) => s+ "doesn't start with hello")
>  // a function for the ok and the ko message
>  val m3: Matcher[String] = ((_: String).startsWith("hello"),
> (s:String) => s+ "starts with hello", (s:String) => s+ "doesn't start
> with hello")

Sounds interesting, but I don't think it changes my idea (allowing a
function for the success would, however).

Reply all
Reply to author
Forward
0 new messages