Skip to content
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

Stub and yield passed block #495

Closed
andyw8 opened this issue Oct 28, 2020 · 7 comments
Closed

Stub and yield passed block #495

andyw8 opened this issue Oct 28, 2020 · 7 comments

Comments

@andyw8
Copy link
Contributor

andyw8 commented Oct 28, 2020

I was looking for way to stub a method and simply yield the block.

After trying some awkward approaches, I discovered this works with simply stubs(:foo).yields, but this form without arguments doesn't seem be documented:

https://www.rubydoc.info/github/floehopper/mocha/Mocha%2FExpectation:yields

If this is a valid use then I can submit a PR to update the docs.

@floehopper
Copy link
Member

@andyw8 The *parameters in the Mocha::Expectation#yields(*parameters) ⇒ Expectation signature in the docs means that you can list zero, one, or more parameters. However, perhaps people aren't familiar enough with this notation. I'd be happy to include another example in the docs which has no parameters being yielded to the block if you think that would make things clearer.

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 1, 2020

Yeah, I understand that *parameters can mean zero, but it felt a little like 'undocumented behaviour'. I've opened #496 to address.

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 1, 2020

@nitishr
Copy link
Contributor

nitishr commented Nov 10, 2020

@andyw8 The *parameters in the Mocha::Expectation#yields(*parameters) ⇒ Expectation signature in the docs means that you can list zero, one, or more parameters. However, perhaps people aren't familiar enough with this notation. I'd be happy to include another example in the docs which has no parameters being yielded to the block if you think that would make things clearer.

There already is such an example:

# @example Yield when expected method is invoked.
. Perhaps it's not clear enough because of mixing yields and returns, and not being explicit about 'no/without parameters'.

@floehopper
Copy link
Member

Perhaps it's not clear enough because of mixing yields and returns, and not being explicit about 'no/without parameters'.

Thanks, @nitishr. Yes, that was my assumption too. I'm always keen to improve the documentation and so if separating the examples makes things clearer then I'm in favour of it. In fact in this case, it might be clearer not to call Expectation#returns in any of the examples for Expectation#yields. What do you think?

floehopper pushed a commit that referenced this issue Nov 27, 2020
With a particular focus on clarifying the behaviour of
Expectation#yields with no arguments.

Closes #495.
@nitishr
Copy link
Contributor

nitishr commented Nov 27, 2020

Yeah, I think focusing on just the yields without mixing with returns would be clearer. I'm happy to update the example(s) if you'd like.

@floehopper
Copy link
Member

Yeah, I think focusing on just the yields without mixing with returns would be clearer. I'm happy to update the example(s) if you'd like.

Thanks. I've already merged something along those lines in d590812.

floehopper pushed a commit that referenced this issue Dec 23, 2020
With a particular focus on clarifying the behaviour of
Expectation#yields with no arguments.

Closes #495.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants