Awesomeness Calc Spec

by longmatthewh

HTML

<script src="http://searls.github.io/jasmine-all/jasmine-all-min.js"></script>

JavaScript

function AwesomenessCalc(data) {
    this.firstName = data.firstName;
    this.ownsGuitar = data.ownsGuitar;
    this.isDeveloper = data.isDeveloper;
    this.favoriteBrowser = data.favoriteBrowser;

    this.getScore = function() {
    	var score = 0;
    	score += calcItemScore(this.firstName, ['matt'], 50);
        //you can comment out this line, and the spec will still pass
    	score += calcItemScore(this.favoriteBrowser, ['ie', 'internet explorer'], -60);
        //you can firefox from the array below, and the spec will still pass
    	score += calcItemScore(this.favoriteBrowser, ['firefox', 'chrome'], 30);
    	score += (this.isDeveloper) ? 10 : 0;
    	score += (this.ownsGuitar) ? 10 : 0;
        return score;
    };
    
    function calcItemScore(dataItem, matches, score) {
    	if (dataItem && isMatch(dataItem, matches)) {
    		return score;
    	}
    	return 0;
    }
    
    function isMatch(dataItem, matches) {
    	var isMatch = false;
    	var lowerCaseDataItem = dataItem.toLowerCase();
    	$.each(matches, function(index, value) {
    		if (lowerCaseDataItem.indexOf(value) > -1) {
    			isMatch = true;
    		}
    	});
    	return isMatch;
    }
}

describe('awesomness', function() {
	var calc;
	
	it('if first name starts with matt the awesomeness score gets 50 pts', function() {
		calc = new AwesomenessCalc({firstName:'mAtt'});
		expect(calc.getScore()).toBe(50);
	});
	
	it('if favorite browser is chrome score gets 30 pts', function() {
		calc = new AwesomenessCalc({favoriteBrowser:'cHrome'});
		expect(calc.getScore()).toBe(30);
	});
	
	it('if developer score gets 10 pts', function() {
		calc = new AwesomenessCalc({isDeveloper:true});
		expect(calc.getScore()).toBe(10);		
	});
	
	it('if owns guitar ', function() {
		calc = new AwesomenessCalc({ownsGuitar:true});
		expect(calc.getScore()).toBe(10);		
	});
	
	it('if developer matt owns guitar and loves chrome score is 100 pts', function() {
		calc = new AwesomenessCalc({firstName:'Matt',...