Why can't Spock Mocks/Stubs be declared in different statements?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Why can't Spock Mocks/Stubs be declared in different statements?

Rick Jensen
The question has come up a number of times in my group, and I never have been able to give a great answer beyond "because that's the way it is". So, what is the reason / rationale for the requirement that Mock interactions and Stub responses for a particular method signature be declared at the same time?

In particular, I'm looking for reasons like "The Mocks / Stubs work in a particular way in order to provide some particular capability, and because of that, we have to declare things at the same time".

Thanks,
Rick

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why can't Spock Mocks/Stubs be declared in different statements?

Przemysław Wojnowski
Hi. Could you provide an example?

2015-05-07 21:41 GMT+02:00 Rick Jensen <[hidden email]>:
The question has come up a number of times in my group, and I never have been able to give a great answer beyond "because that's the way it is". So, what is the reason / rationale for the requirement that Mock interactions and Stub responses for a particular method signature be declared at the same time?

In particular, I'm looking for reasons like "The Mocks / Stubs work in a particular way in order to provide some particular capability, and because of that, we have to declare things at the same time".

Thanks,
Rick

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why can't Spock Mocks/Stubs be declared in different statements?

Leonard Brünings
In reply to this post by Rick Jensen
Hi,

what do you mean by different statements, do you mean given/when/then or outside of a specification?

Please look also at https://spockframework.github.io/spock/docs/1.0/interaction_based_testing.html

Cheers
Leonard

On Thursday, May 7, 2015 at 9:41:31 PM UTC+2, Rick Jensen wrote:
The question has come up a number of times in my group, and I never have been able to give a great answer beyond "because that's the way it is". So, what is the reason / rationale for the requirement that Mock interactions and Stub responses for a particular method signature be declared at the same time?

In particular, I'm looking for reasons like "The Mocks / Stubs work in a particular way in order to provide some particular capability, and because of that, we have to declare things at the same time".

Thanks,
Rick

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why can't Spock Mocks/Stubs be declared in different statements?

Kostis Kapelonis
I think he means the part "In particular, the following Mockito-style
splitting of stubbing and mocking into two separate statements will
not work:"
mentioned in Spock docs at
http://spockframework.github.io/spock/docs/1.0/interaction_based_testing.html

On Fri, May 8, 2015 at 10:19 PM, Leonard Brünings
<[hidden email]> wrote:

> Hi,
>
> what do you mean by different statements, do you mean given/when/then or
> outside of a specification?
>
> Please look also at
> https://spockframework.github.io/spock/docs/1.0/interaction_based_testing.html
>
> Cheers
> Leonard
>
>
> On Thursday, May 7, 2015 at 9:41:31 PM UTC+2, Rick Jensen wrote:
>>
>> The question has come up a number of times in my group, and I never have
>> been able to give a great answer beyond "because that's the way it is". So,
>> what is the reason / rationale for the requirement that Mock interactions
>> and Stub responses for a particular method signature be declared at the same
>> time?
>>
>> In particular, I'm looking for reasons like "The Mocks / Stubs work in a
>> particular way in order to provide some particular capability, and because
>> of that, we have to declare things at the same time".
>>
>> Thanks,
>> Rick
>
> --
> You received this message because you are subscribed to the Google Groups
> "Spock Framework - User" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/spockframework.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why can't Spock Mocks/Stubs be declared in different statements?

Peter Niederwieser
Administrator
In reply to this post by Rick Jensen
Mocking frameworks match invocations against expectations. An expectation (called interaction in Spock) defines both invocation constraints (also called matchers) and return values, and the first matching expectation wins. This is the model used by all mocking frameworks I know, except for Mockito. Under this model, if constraints and return values are mistakenly split up into separate expectations, an invocation will match at most one of them (since matching stops after the first match), which will not result in the desired behavior. The best that can be possibly done about such incorrect usages is to detect them and inform the user.

On 07 May 2015, at 21:41, Rick Jensen <[hidden email]> wrote:

The question has come up a number of times in my group, and I never have been able to give a great answer beyond "because that's the way it is". So, what is the reason / rationale for the requirement that Mock interactions and Stub responses for a particular method signature be declared at the same time?

In particular, I'm looking for reasons like "The Mocks / Stubs work in a particular way in order to provide some particular capability, and because of that, we have to declare things at the same time".

Thanks,
Rick

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Why can't Spock Mocks/Stubs be declared in different statements?

Peter Niederwieser
Administrator
Mockito introduced a different model with different trade-offs. Spock implements some of the advantages of Mockito’s model on the DSL level (interactions can be specified after the fact in a `then` block) while retaining the non-Mockito model and its advantages. However, it still requires the same interaction to specify both constraints and return values for an invocation. For some reason, this is a common source of confusion - perhaps because Mockito is so prevalent these days.

On 22 May 2015, at 00:22, Peter Niederwieser <[hidden email]> wrote:

Mocking frameworks match invocations against expectations. An expectation (called interaction in Spock) defines both invocation constraints (also called matchers) and return values, and the first matching expectation wins. This is the model used by all mocking frameworks I know, except for Mockito. Under this model, if constraints and return values are mistakenly split up into separate expectations, an invocation will match at most one of them (since matching stops after the first match), which will not result in the desired behavior. The best that can be possibly done about such incorrect usages is to detect them and inform the user.

On 07 May 2015, at 21:41, Rick Jensen <[hidden email]> wrote:

The question has come up a number of times in my group, and I never have been able to give a great answer beyond "because that's the way it is". So, what is the reason / rationale for the requirement that Mock interactions and Stub responses for a particular method signature be declared at the same time?

In particular, I'm looking for reasons like "The Mocks / Stubs work in a particular way in order to provide some particular capability, and because of that, we have to declare things at the same time".

Thanks,
Rick

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

signature.asc (859 bytes) Download Attachment