Skip to content

Commit 8e9312e

Browse files
authored
Merge pull request #178 from philschatz/fix-array-tests
fix tests that validate an Array is returned
2 parents 3ba95a4 + ba4195c commit 8e9312e

7 files changed

Lines changed: 40 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
},
3030
"dependencies": {
31-
"fetch-vcr": "^0.5.1",
31+
"fetch-vcr": "^1.1.0",
3232
"lodash": "^4.16.4",
3333
"node-fetch": "^1.6.3"
3434
},

test/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const fetchVCR = require('fetch-vcr')
33
fetchVCR.configure({
44
fixturePath: '../node_modules/octokat-fixtures/_fixtures',
5-
// headerBlacklist: ['authorization', 'user-agent']
5+
headerBlacklist: ['authorization', 'user-agent']
66
})
77

88
require('./all')

test/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
require('fetch-vcr').configure({
33
fixturePath: './node_modules/octokat-fixtures/_fixtures',
4-
// headerBlacklist: ['authorization', 'user-agent']
4+
headerBlacklist: ['authorization', 'user-agent']
55
})
66

77
require('./all')

test/ruby-specs/commit-comments.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ describe('Commit Comments', function () {
5151

5252
it('deletes a commit comment', () => {
5353
return this.commit_comment.remove()
54-
.then(result => {
55-
expect(result).to.equal(true)
56-
})
5754
})
5855
})
5956
})

test/ruby-specs/contents.spec.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,33 @@ describe('Contents', function () {
4242

4343
context('With a file', function () {
4444
beforeEach(function (done) {
45-
let removeFile = function (content) {
45+
let removeFile = function (octoPartial, content) {
4646
let config = {
4747
sha: content.sha,
4848
message: 'Removing as prep for testing'
4949
}
50-
return client.repos(test_repo).contents('test_create.txt').remove(config).then(() => done())
50+
return octoPartial.remove(config)
5151
}
5252

5353
// If the file exists, remove it. Otherwise, done.
54-
client.repos(test_repo).contents('test_create.txt').fetch()
54+
function removeFirst(content1) {
55+
function removeSecond () {
56+
const octoPartial2 = client.repos(test_repo).contents('test_delete.txt')
57+
octoPartial2.fetch()
58+
/* eslint handle-callback-err: "off" */
59+
.then(content => {
60+
removeFile(octoPartial2, content)
61+
.then(x => done())
62+
}, err => done())
63+
}
64+
removeFile(octoPartial, content1)
65+
.then(removeSecond, removeSecond)
66+
}
67+
let octoPartial = client.repos(test_repo).contents('test_create.txt')
68+
octoPartial.fetch()
5569
/* eslint handle-callback-err: "off" */
56-
.then(removeFile, err => done())
70+
.then(removeFirst, removeFirst)
71+
5772

5873
// In Mocha 3, if the returned value is a promise then it will complain that
5974
// we have specified a done() callback _and_ returned a promise.
@@ -113,10 +128,10 @@ describe('Contents', function () {
113128
return repo.fetch().then(({defaultBranch}) => {
114129
return repo.branches(defaultBranch).fetch().then(({commit}) => {
115130
let config = {
116-
message: 'I am commit-ing',
131+
message: 'I am commit-ing for removal',
117132
content: btoa('Here be the content\n')
118133
}
119-
return repo.contents('test_create.txt').add(config)
134+
return repo.contents('test_delete.txt').add(config)
120135
.then(null, function (err) { console.log(err); throw new Error(err) })
121136
.then(response => {
122137
expect(response.commit.sha).to.match(/[a-z0-9]{40}/)
@@ -126,7 +141,7 @@ describe('Contents', function () {
126141
sha: response.content.sha,
127142
message: 'I am rm-ing'
128143
}
129-
return client.repos(test_repo).contents('test_create.txt').remove(config)
144+
return client.repos(test_repo).contents('test_delete.txt').remove(config)
130145
.then(function (response) {
131146
expect(response.url).is.a('string')
132147
})

test/ruby-specs/gists.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Gists', function () {
99
describe('Authenticated Gists', function () {
1010
before(function () {
1111
let newGist = {
12-
description: 'A gist from Octokit',
12+
description: 'A gist from Octokat',
1313
public: true,
1414
files: {
1515
'zen.text': {

test/simple.spec.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ describe(`${GH} = new Octokat({token: ...})`, function () {
9898
let {finalArgs, context} = constructMethod()
9999
// If the last arg was something like 'fetch' then
100100
if (isFuncArgs) {
101-
context().then(cb)
101+
return context().then(cb)
102102
} else {
103-
context(...finalArgs).then(cb)
103+
return context(...finalArgs).then(cb)
104104
}
105105
})
106106

107107
it(`${obj}${code} (callback ver)`, function () {
108108
let {finalArgs, context} = constructMethod()
109-
context(...finalArgs, function (err, val) {
109+
return context(...finalArgs, function (err, val) {
110110
if (err) { return assert.fail(err) }
111111
cb(val)
112112
})
@@ -116,7 +116,13 @@ describe(`${GH} = new Octokat({token: ...})`, function () {
116116
let itIsOk = (obj, ...args) => itIs(obj, '', args, val => expect(val).to.be.ok)
117117

118118
let itIsArray = (obj, ...args) =>
119-
itIs(obj, ' yields Array', args, val => expect(val).to.be.an.array)
119+
itIs(obj, ' yields Array', args, (val) => {
120+
expect(val).to.be.an.array
121+
if (!val || (!Array.isArray(val) && !Array.isArray(val.items))) {
122+
console.log('woops not an array!', val);
123+
throw new Error('woops, not an array!')
124+
}
125+
})
120126

121127
let itIsFalse = (obj, ...args) =>
122128
itIs(obj, ' yields False', args, val => expect(val).to.be.false)
@@ -173,6 +179,7 @@ describe(`${GH} = new Octokat({token: ...})`, function () {
173179
itIsOk(GH, 'feeds.fetch')
174180
})
175181

182+
itIsArray(GH, 'user.publicEmails.fetch')
176183
itIsArray(GH, 'users.fetch')
177184
itIsArray(GH, 'gists.public.fetch')
178185
// itIsArray(GH, 'global.events')
@@ -280,13 +287,13 @@ describe(`${GH} = new Octokat({token: ...})`, function () {
280287
itIsOk(REPO, 'readme.read')
281288
itIsArray(REPO, 'hooks.fetch')
282289
itIsArray(REPO, 'assignees.fetch')
283-
itIsArray(REPO, 'languages.fetch')
290+
itIsOk(REPO, 'languages.fetch')
284291
itIsArray(REPO, 'teams.fetch')
285292
itIsArray(REPO, 'tags.fetch')
286293
itIsArray(REPO, 'branches.fetch')
287294
itIsArray(REPO, 'contributors.fetch')
288295
itIsArray(REPO, 'subscribers.fetch')
289-
itIsArray(REPO, 'subscription.fetch')
296+
itIsOk(REPO, 'subscription.fetch')
290297
itIsArray(REPO, 'comments.fetch')
291298
itIsArray(REPO, 'downloads.fetch')
292299
itIsArray(REPO, 'milestones.fetch')
@@ -421,7 +428,7 @@ describe(`${GH} = new Octokat({token: ...})`, function () {
421428
describe(`${ORG} = ${GH}.orgs(ORG_NAME)`, function () {
422429
before(() => { STATE[ORG] = STATE[GH].orgs(ORG_NAME) })
423430

424-
itIsArray(ORG, 'fetch')
431+
itIsOk(ORG, 'fetch')
425432
itIsArray(ORG, 'members.fetch')
426433
itIsArray(ORG, 'repos.fetch')
427434
return itIsArray(ORG, 'issues.fetch')

0 commit comments

Comments
 (0)