Skip to content

Instantly share code, notes, and snippets.

@smsohan
Last active December 28, 2015 08:19
Show Gist options
  • Save smsohan/7470950 to your computer and use it in GitHub Desktop.
Save smsohan/7470950 to your computer and use it in GitHub Desktop.
Rails/Js/AssetPipeline/Testing
<# All $ ready moves to erb pages %>
<%= content_for :scripts %>
$(function(){
new LoginForm({form: $('#the-form')})
});
<% end %>
#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: ->
#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