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

Add a way to yield different values in sequence #157

Closed
domenic opened this issue Jul 11, 2012 · 4 comments
Closed

Add a way to yield different values in sequence #157

domenic opened this issue Jul 11, 2012 · 4 comments

Comments

@domenic
Copy link
Contributor

domenic commented Jul 11, 2012

stub.yields is super-useful, since it finds the callback for you. But, if you wanted to yield different values in sequence, you're out of luck, and have to go back to manual stub-creation. And then you lose the magic callback-finding :(.

I'm thinking something like this?

var stub = sinon.stub();
stub.yieldsSequence([1], [2], [3]);

function tester(cb) {
    console.log(cb());
}

tester(stub); // => 1
tester(stub); // => 2
tester(stub); // => 3
@cjohansen
Copy link
Contributor

Or maybe

var stub = sinon.stub();
stub.yields(1).thenYields(2),thenYields(3);

Not extremely beautiful... Could you use withArgs for this?

@domenic
Copy link
Contributor Author

domenic commented Jul 11, 2012

Could you use withArgs for this?

Sadly no; I'm trying to simulate failure-failure-success to test some retrying code. There's no distinguishing factors between the calls.

@cjohansen
Copy link
Contributor

I see. I'll need to mull over the best naming for a little while. If you want to implement it I'm happy to merge once we find a good name for it :)

@domenic
Copy link
Contributor Author

domenic commented Jul 11, 2012

Sounds good, I'll probably work on it this weekend :)

cjohansen added a commit that referenced this issue Sep 17, 2012
Add `thenYields` for sequential yielding. Closes #157.
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

No branches or pull requests

2 participants