Created
September 29, 2011 06:46
-
-
Save padi/1250125 to your computer and use it in GitHub Desktop.
shared examples stored under spec/javascripts/.
This file contains hidden or 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
I tried the basic idea from thoughtbot as much as possible (it uses Underscore.js, but I think I don't need it yet) | |
So do I need to be able to pass all the needed variables (like body) from the jquery.validate.remote_spec to window.sharedExamples? |
This file contains hidden or 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
describe("jQuery validate remote option", function() { | |
var body, form; | |
beforeEach(function() { | |
body = $('body'); | |
spyOnEvent(body, 'signup:timeout'); | |
spyOnEvent(body, 'signup:connecting'); | |
spyOnEvent(body, 'signup:timeoutRecovery'); | |
loadFixtures('sign-up-form.fixture.html'); | |
form = $('#jasmine-fixtures form'); | |
form.tdSignUpForm({ debug: true }); | |
}); | |
describe("when there is no response on focus out", function() { | |
beforeEach(function() { | |
form.find('input#user_email').val('[email protected]'); | |
form.find('input#user_email').focusout(); | |
mostRecentAjaxRequest().response({}); //disconnected, so there is no response. We'll simulate it like this for now | |
form.find('input#user_email').val('[email protected]'); | |
}); | |
it("should not show check icon", function() { | |
expect(form).not.toContain('input#user_email + .icon.valid'); | |
}); | |
it("should not show error icon", function() { | |
expect(form).not.toContain('input#user_email + .icon.error'); | |
}); | |
it("should trigger signup:timeout event", function() { | |
expect('signup:timeout').toHaveBeenTriggeredOn(body); | |
}); | |
describe("on focus out", function() { | |
beforeEach(function() { | |
form.find('input#user_email').focusout(); | |
mostRecentAjaxRequest().response({ status: 200 }); | |
}); | |
itShouldBehaveLike("remote revalidation"); | |
}); | |
describe("on submit", function() { | |
beforeEach(function() { | |
form.submit(); | |
mostRecentAjaxRequest().response({ status: 200 }); | |
}); | |
itShouldBehaveLike("remote revalidation"); | |
}); | |
}); | |
}); |
This file contains hidden or 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
describe("jQuery validate remote option", function() { | |
var body, form, CONTEXT; | |
beforeEach(function() { | |
CONTEXT = { | |
body: $('body') | |
}; | |
spyOnEvent(body, 'signup:timeout'); | |
spyOnEvent(body, 'signup:connecting'); | |
spyOnEvent(body, 'signup:timeoutRecovery'); | |
loadFixtures('sign-up-form.fixture.html'); | |
form = $('#jasmine-fixtures form'); | |
form.tdSignUpForm({ debug: true }); | |
}); | |
describe("when there is no response on focus out", function() { | |
beforeEach(function() { | |
form.find('input#user_email').val('[email protected]'); | |
form.find('input#user_email').focusout(); | |
mostRecentAjaxRequest().response({}); //disconnected, so there is no response. We'll simulate it like this for now | |
form.find('input#user_email').val('[email protected]'); | |
}); | |
it("should not show check icon", function() { | |
expect(form).not.toContain('input#user_email + .icon.valid'); | |
}); | |
it("should not show error icon", function() { | |
expect(form).not.toContain('input#user_email + .icon.error'); | |
}); | |
it("should trigger signup:timeout event", function() { | |
expect('signup:timeout').toHaveBeenTriggeredOn(body); | |
}); | |
describe("on focus out", function() { | |
beforeEach(function() { | |
form.find('input#user_email').focusout(); | |
mostRecentAjaxRequest().response({ status: 200 }); | |
}); | |
itShouldBehaveLike("remote revalidation", CONTEXT); | |
}); | |
describe("on submit", function() { | |
beforeEach(function() { | |
form.submit(); | |
mostRecentAjaxRequest().response({ status: 200 }); | |
}); | |
itShouldBehaveLike("remote revalidation", CONTEXT); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment