Last active
December 28, 2015 08:19
-
-
Save smsohan/7470950 to your computer and use it in GitHub Desktop.
Rails/Js/AssetPipeline/Testing
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
<# All $ ready moves to erb pages %> | |
<%= content_for :scripts %> | |
$(function(){ | |
new LoginForm({form: $('#the-form')}) | |
}); | |
<% end %> |
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
#Classes take bare minimum and extract from there | |
class LoginForm | |
constructor: (options)=> | |
@form = options.form | |
@submitButton = @form.find("#submit-button") | |
@submitButton.on 'click', => @handleSubmit() | |
handleSubmit: -> |
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
#specs override the instance variables as needed | |
describe 'LoginForm', -> | |
loginForm = null | |
form = null | |
beforeEach -> | |
form = $('<form/>') | |
loginForm = new LoginForm(form) | |
describe 'handleSubmit', -> | |
it 'handles the submit' -> | |
#send a stubbed button | |
submitButton = $('<button>') | |
loginForm.submitButton = submitButton | |
loginForm.handleSubmit() | |
expectSomeThingHere() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment