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

Fix failing reset() on sandbox with unused fake server #1428

Merged
merged 2 commits into from May 26, 2017

Conversation

fatso83
Copy link
Contributor

@fatso83 fatso83 commented May 26, 2017

Purpose (TL;DR) - mandatory

sandbox.reset() fails when the sandbox has been configured to use a fake server and the server has not been utilized. This is the standard config for sinon-test and was revealed to crash in sinonjs/sinon-test#57

Background (Problem in detail) - optional

    var sandbox = sinonSandbox.create({useFakeServer: true});
    sandbox.reset();

will crash immediately today due to the fields not being initalized.

Solution - optional

Initializes the fields at creation time.

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. git reset --hard HEAD~1 && npm test #pre-fix the tests fail
  4. git merge && npm test #after fix the tests pass

@coveralls
Copy link

coveralls commented May 26, 2017

Coverage Status

Coverage increased (+0.04%) to 94.935% when pulling 874b9c1 on fatso83:failing-sandbox-reset into fe049aa on sinonjs:master.

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.

I think the tests need a little love. I'm not sure what exactly though.

@@ -56,6 +56,18 @@ describe("sinonSandbox", function () {
assert.same(sandbox.assert, sinonAssert);
});

it("can be reset without failing when pre-configured to use a fake server", function () {
var sandbox = sinonSandbox.create({useFakeServer: true});
sandbox.reset();
Copy link
Member

Choose a reason for hiding this comment

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

There are no assertions in either test. How did this fail before your changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, good catch. I'll add some kind of refutation along with throws (don't remember the exact api).

failing test

 1) sinonSandbox can be reset without failing when configured to use a fake server:
     TypeError: Cannot set property 'length' of undefined
      at Object.resetBehavior (lib/sinon/util/fake_server.js:279:51)
      at Object.reset (lib/sinon/util/fake_server.js:274:14)
      at lib/sinon/collection.js:26:21
      at Array.forEach (native)
      at each (lib/sinon/collection.js:25:19)
      at Object.reset (lib/sinon/collection.js:41:9)
      at Context.<anonymous> (test/sandbox-test.js:68:17)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, pushed a fix. Output before fix:


  1306 passing (846ms)
  4 pending
  2 failing

  1) sinonSandbox can be reset without failing when pre-configured to use a fake server:
     AssertionError: [refute.exception] Expected not to throw but threw TypeError (Cannot set property 'length' of undefined)
      at referee.fail (node_modules/referee/lib/referee.js:193:25)
      at Object.fail (node_modules/referee/lib/referee.js:90:21)
      at assertion (node_modules/referee/lib/referee.js:98:21)
      at Function.referee.(anonymous function).(anonymous function) [as exception] (node_modules/referee/lib/referee.js:118:23)
      at Context.<anonymous> (test/sandbox-test.js:61:16)

  2) sinonSandbox can be reset without failing when configured to use a fake server:
     AssertionError: [refute.exception] Expected not to throw but threw TypeError (Cannot set property 'length' of undefined)
      at referee.fail (node_modules/referee/lib/referee.js:193:25)
      at Object.fail (node_modules/referee/lib/referee.js:90:21)
      at assertion (node_modules/referee/lib/referee.js:98:21)
      at Function.referee.(anonymous function).(anonymous function) [as exception] (node_modules/referee/lib/referee.js:118:23)
      at Context.<anonymous> (test/sandbox-test.js:69:16)


@coveralls
Copy link

coveralls commented May 26, 2017

Coverage Status

Coverage increased (+0.04%) to 94.935% when pulling 0bf0a79 on fatso83:failing-sandbox-reset into fe049aa on sinonjs:master.

@fatso83 fatso83 merged commit c81d76b into sinonjs:master May 26, 2017
@fatso83 fatso83 deleted the failing-sandbox-reset branch May 26, 2017 12:58
@mroderick mroderick added the semver:patch changes will cause a new patch version label May 26, 2017
@mroderick
Copy link
Member

This has become part of sinon@2.3.2, which is on npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:patch changes will cause a new patch version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants