-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow receive with multiple methods #368
Comments
What about this: allow(obj).to receive_messages(first: 1, last: 2) Then it's very explicit that it is the multi-case. |
Yes, I like that. Could the wording be more fluid for either single- or multi-use, perhaps:
Then it looks like a shorthand for |
I think I prefer allow(obj).to receive_messages(first: 1, last: 2) over allow(obj).to receive_and_return(first: 1) the wording seems nicer. |
I think I like |
👍 for |
Yes, I'm on board with |
As I stated in #389 I believe we should keep the original matcher
Isn't it possible? |
It's possible, but receive_messages seems more explicit and readable to me. Why do you prefer complicating receive by overloading it? |
I can see the appeal too: one less method to remember in the DSL, is it worth having a different name for 1 vs. many stubs? Which of the following should be
|
It's just longer and another method to remember, like @avit said. |
If someone tries to use it as:
Just raise an exception and say that this usage is not supported yet until we discuss how to better chain it in such usage cases. |
I'm ok with having the extra DSL method if it removes the overloading and reduces the internal complexity, especially if it removes the chaining conundrum. |
Just to be clear, I don't really mind if it will be called |
There will only be patch releases, no more minors, before version |
@rosenfeld So my issue with the overloading of expect(obj).to receive(:first) # Parity
expect(obj).to receive(first: 1) # Not overly expressive, but understandable
expect(obj).to receive(:first, :last) # Is this ordered? How do I chain `.with`?
expect(obj).to receive(first: 1, last: 2) # Same concern as above By having a close parity between the two uses, it makes it easier to remember when you can and should use each as the API is the same. With that being said, I do not think that |
Yes, that makes sense, @cupakromer. I agree with everything you said. I'd just prefer a shorter name then receive_message if possible, but that's not a big deal. Also, if we're going to keep the long name, maybe change it to something else with more meaning since receive and receive_message mean the same to me... What about something like this?
|
For the example above we could introduce For expectations something like this might work:
For ordered and chaining I don't think it worths adding a shortcut DSL... Can you think of any examples where it would be useful? |
RSpec is actively moving away from
I'm hesitant to see dbl = double( 'Book', title: 'Testing with RSpec', price: 0.99 ) Due to that, I see this discussion related more to partial mocking on non- Note there is current planning to make a
Again, just looking at the code, I'm not sure what this is supposed to be expressing. Is it an ordered expectation? Or are you just mashing two expectations into one test? Though based on your comment I can infer the latter. Reading through tests, I would prefer the current, more explicit, options to defining ordered / complex message expectations. Just my 2¢ take it with a grain of salt. |
IMO, only the first should be Currently |
That's fine to me, @myronmarston. Go ahead. |
Fixed by #399. |
Previously it was possible to quickly stub methods thus:
Now these "should" be done as separate declarations with messier syntax:
Is there a way around this? Would it be feasible to have at least:
or something like:
The text was updated successfully, but these errors were encountered: