Skip to content

add throwsArg(index) to stubs - #1319

Merged
mantoni merged 4 commits into
sinonjs:masterfrom
seppevs:add_throwsArg_to_stubs
May 20, 2017
Merged

mantoni merged 4 commits into
sinonjs:masterfrom
seppevs:add_throwsArg_to_stubs

Conversation

@seppevs

@seppevs seppevs commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

Fixes issue #1270 by adding a throwsArg(index) method to stubs

I have added unit tests & docs.

This was requested through sinonjs#1270
@coveralls

coveralls commented Mar 8, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.4%) to 93.974% when pulling 32757dc on seppevs:add_throwsArg_to_stubs into e0cfccc on sinonjs:master.

@mroderick

Copy link
Copy Markdown
Member

This PR looks good to me.

However, I cannot figure out why coveralls thinks that this should not be merged.

So, I tried to run the coverage report locally, but it doesn't generate a nice HTML representation. @mantoni do you know the magic incantation to get the mochify-istanbul to play nice and generate an HTML coverage report?

@mantoni

mantoni commented Mar 9, 2017 •

Copy link
Copy Markdown
Member

@mroderick You can run npm run test-coverage to get a text coverage report. If you want HTML, you can add another --reporter html argument and then open coverage/index.html. While it generates the HTML report for me, it fails with a runtime error in the istanbul module. Therefore I'm not sure whether the report is not complete.

@fearphage

fearphage commented Apr 6, 2017 •

Copy link
Copy Markdown
Member

I cannot figure out why coveralls thinks that this should not be merged

Coverage dropped by >= 1%. Coveralls is configured to block the commit when that happens. I'm not 100% sure why that is the case, but I believe it has to do with the way it's tracking coverage. I submitted a PR to attempt to fix this.

@fearphage fearphage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. There are just a few missing tests.

Comment thread lib/sinon/behavior.js
this.exception ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.throwArgAt === "number" ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

Comment thread lib/sinon/stub.js

delete this.returnValue;
delete this.returnArgAt;
delete this.throwArgAt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

@fearphage

Copy link
Copy Markdown
Member

@seppevs Any plans to finish this PR? It looks like a solid addition.

@seppevs

seppevs commented May 19, 2017

Copy link
Copy Markdown
Contributor Author

@fearphage sorry I'm quiet busy. I tried a few weeks ago to add the tests, but I couldn't find where I should add them.

@fearphage

Copy link
Copy Markdown
Member

@seppevs Completely understandable. Would you mind opening/unlocking the PR so others can push to your branch to complete this PR? I'm not sure how to describe it, because I've never done it before. There is (or at least was) a checkbox somewhere in the right column that said something along the lines of "allow other collaborators to push to your PR" or something along those lines. If you check that box, someone else can help you wrap this up. Also thank you very much for your contribution.

@seppevs

seppevs commented May 19, 2017

Copy link
Copy Markdown
Contributor Author

@fearphage "Allow edits from maintainers." is checked. The description when I hover over it:

If checked, users with write access to sinonjs/sinon can add new commits to your add_throwsArg_to_stubs branch. You can always change this setting later.

@coveralls

coveralls commented May 19, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 95.033% when pulling 176dd78 on seppevs:add_throwsArg_to_stubs into e0cfccc on sinonjs:master.

@fearphage

Copy link
Copy Markdown
Member

I'm going to let someone else review and merge. @sinonjs/sinon-core

Comment thread docs/_releases/v1.17.6/stubs.md Outdated

Causes the stub to throw the argument exception at the provided index.

`stub.returnsArg(0);` causes the stub to throw the first argument exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy pasted from returnsArg?

Comment thread lib/sinon/behavior.js
} else if (this.returnThis) {
return context;
} else if (typeof this.throwArgAt === "number") {
throw args[this.throwArgAt];

@mantoni mantoni May 19, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should test whether the function was called with enough arguments to throw the argument at the given index.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. What's the expected behavior if there aren't enough params?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should throw an exception. I know, it sounds ironic in this context, but an exception with a more telling message and not throwing undefined makes sense, I think. We do something similar in yield.

@coveralls

coveralls commented May 19, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.3%) to 95.037% when pulling 0b374b9 on seppevs:add_throwsArg_to_stubs into e0cfccc on sinonjs:master.

@mantoni

mantoni commented May 19, 2017

Copy link
Copy Markdown
Member

For completeness, this feature should also be mirrored in the spy API. Like spy.callArg.

@fearphage

Copy link
Copy Markdown
Member

@mantoni Is that the last bit? I'd prefer to do all the changes at once instead of a few at a time.

@mantoni

mantoni commented May 20, 2017

Copy link
Copy Markdown
Member

Yes, sorry. It came to my mind too late. I didn't do this intentionally. We can also merge this as is and add the spy API separately.

@coveralls

coveralls commented May 20, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.3%) to 95.053% when pulling 58efb00 on seppevs:add_throwsArg_to_stubs into e0cfccc on sinonjs:master.

@fearphage

Copy link
Copy Markdown
Member

@mantoni Back to you.

I filed a related issue when I went to add docs for the spy method -- #1411 Spy methods aren't documented.

@mantoni
mantoni merged commit 4f3a3ac into sinonjs:master May 20, 2017
@mantoni

mantoni commented May 20, 2017

Copy link
Copy Markdown
Member

@fearphage Thank you!

@mroderick mroderick added the semver:minor changes will cause a new minor version label May 21, 2017
@mroderick

Copy link
Copy Markdown
Member

Since this is an expansion of the API, I think we should publish a new MINOR release. What do you think @fearphage @mantoni?

@mantoni

mantoni commented May 21, 2017

Copy link
Copy Markdown
Member

@mroderick Yes, true. Are you doing it?

@fearphage

Copy link
Copy Markdown
Member

I concur. Minor seems fitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:minor changes will cause a new minor version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants