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 throwsArg(index) to stubs #1319

Merged
merged 4 commits into from May 20, 2017
Merged

Conversation

seppevs
Copy link
Contributor

@seppevs seppevs commented Mar 8, 2017

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

I have added unit tests & docs.

This was requested through sinonjs#1270
@coveralls
Copy link

coveralls commented Mar 8, 2017

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
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
Copy link
Member

mantoni commented Mar 9, 2017

@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
Copy link
Member

fearphage commented Apr 6, 2017

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.

Copy link
Member

@fearphage fearphage left a comment

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.

@@ -113,6 +113,7 @@ var proto = {
this.exception ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.throwArgAt === "number" ||
Copy link
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.

@@ -92,6 +92,7 @@ var proto = {

delete this.returnValue;
delete this.returnArgAt;
delete this.throwArgAt;
Copy link
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
Member

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

@seppevs
Copy link
Contributor Author

seppevs commented May 19, 2017

@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
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
Copy link
Contributor Author

seppevs commented May 19, 2017

@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
Copy link

coveralls commented May 19, 2017

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
Member

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


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
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?

@@ -126,6 +127,8 @@ var proto = {
return args[this.returnArgAt];
} else if (this.returnThis) {
return context;
} else if (typeof this.throwArgAt === "number") {
throw args[this.throwArgAt];
Copy link
Member

@mantoni mantoni May 19, 2017

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
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
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
Copy link

coveralls commented May 19, 2017

Coverage Status

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

@mantoni
Copy link
Member

mantoni commented May 19, 2017

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

@fearphage
Copy link
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
Copy link
Member

mantoni commented May 20, 2017

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
Copy link

coveralls commented May 20, 2017

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
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
Copy link
Member

mantoni commented May 20, 2017

@fearphage Thank you!

@mroderick mroderick added the semver:minor changes will cause a new minor version label May 21, 2017
@mroderick
Copy link
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
Copy link
Member

mantoni commented May 21, 2017

@mroderick Yes, true. Are you doing it?

@fearphage
Copy link
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.

None yet

5 participants