Created
October 1, 2011 02:23
-
-
Save gnarargs/1255504 to your computer and use it in GitHub Desktop.
Acceptance dsl for js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lab_rat.js | |
var LabRat = { | |
container: '#jasmine-fixtures', | |
setContainer: function(newContainer) { | |
this.container = newContainer; | |
}, | |
fillIn: function(selector, content) { | |
var $input = $(this.container + ' ' + selector); | |
this.ensureElement($input, selector); | |
$input.val(content); | |
}, | |
clickButton: function(label) { | |
var $button = $('input[type=submit][value=' + label + ']', this.container); | |
this.ensureElement($button, label); | |
$button.click(); | |
}, | |
ensureElement: function(elem, matcher) { | |
if (elem.length == 0) { | |
throw new Error(matcher + ' was not found in ' + this.container); | |
} | |
} | |
}; | |
LR = LabRat; | |
// Usage | |
LR.fillIn("#drink_name", "Large Drip"); | |
LR.clickButton("Submit"); | |
...etc | |
// in Jasmine | |
describe("Adding Drinks", function() { | |
beforeEach(function() { | |
CC.Form.init(); | |
}); | |
it("As a user, I want to add a drink and see it displayed", function() { | |
loadFixtures('drink_form.html'); | |
LR.fillIn("#drink_name", "Large Drip"); | |
LR.clickButton("Submit"); | |
expect($("#results")).toHaveText("Large Drip"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment