nelsonic / github-scraper

🕷 🕸 crawl GitHub web pages for insights we can't GET from the API ... 💡
426 stars 96 forks source link

Eliminate unnecessary error test duplication by centralising url checking in a single re-useable method! #47

Closed nelsonic closed 9 years ago

nelsonic commented 9 years ago

At present we have 158 tests:

scraper-code-coverage

every scraper has _two_ tests for validity (at version 2.0):

var test      = require('tape');
var people = require('../lib/people');

test('Scrape undefined profile (error test) ', function(t) {
    people(null, function(err){
        t.ok(err, 400, 'Receive 400 Error when orgname is undefined');
        t.end();
    })
})

test('Scrape random (non-existent) profile (error test) ', function(t){
    var org = '' + Math.floor(Math.random() * 1000000000000000); // a nice long "random" number
    people(org, function(err, data){
        t.ok(err === 404, 'Got 404 Error when username does not exist');
        t.ok(typeof data === 'undefined', '@param profile is undefined (as expected)');
        t.end();
    })
})

This is _bonkers_! (the result of copy-pasting boilerplate code!) and means we have 45 duplicate tests! Which, as it happens codeclimate has identified:

codeclimate-duplications

And told us to focus on:

scraper-code-climate-dupes