Skip to content

Instantly share code, notes, and snippets.

@richsoni
Last active December 21, 2015 07:19
Show Gist options
  • Save richsoni/6270587 to your computer and use it in GitHub Desktop.
Save richsoni/6270587 to your computer and use it in GitHub Desktop.
Setup for testing Backbone in a rails app
#should only need to be done once
gem 'jasmine'
gem 'guard-jasmine'
gem "jasminerice", :git => 'https://github.com/bradphelan/jasminerice.git'
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#change your port to the port of your application, mine is 5555
################################################################################
guard :jasmine, :server => :webrick, :server_mount => '/jasmine', :port => 5555 do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{spec/javascripts/fixtures/.+$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end
#install node if not already installed
> brew install npm
#Install jshint as a global command
> npm -g install jshint
# This pulls in all your specs from the javascripts directory into Jasmine:
# spec/javascripts/*_spec.js.coffee
# spec/javascripts/*_spec.js
# spec/javascripts/*_spec.js.erb
#
#=require jquery
#=require ../../app/assets/javascripts/application
#=require_tree ./
SESSION =
brokerage_id: 61
current_version: null
office_id: 6
pos: ""
user_id: 1659
user_name: "Buster Bluth"
#should emulate the directory structure of the app itself
~/workspace/pos.rb/spec-------------------------------------------------------------------------------------------------rich@nimrod2 1.9.2p180 master 6cc570fx
❯ ls -R javascripts/
backbone fixtures spec.css spec.js.coffee
javascripts//backbone:
core_spec.js.coffee models
javascripts//backbone/models:
base
javascripts//backbone/models/base:
base_model_spec.js.coffee
javascripts//fixtures:
' example_fixture.html.haml full_client.js.coffee
> cd ~/workspace/pos.rb
> bundle
> cd .git/hooks
> rm -rf scripts
> rm *
> cd ~/workspace/pos.rb
> overcommit .
> cd .git/hooks
> chmod 777 *
> cd ~/workspace/pos.rb
> echo "//test5" >> app/assets/javascripts/lib/helpers/date_range_picker.js; git commit app/assets/javascripts/lib/helpers/date_range_picker.js -m 'test'
#if you see something like this then it works
Running pre_commit checks
Checking author_name........................OK
Checking js_console_log.....................OK
Checking js_syntax..........................FAILED
app/assets/javascripts/lib/helpers/date_range_picker.js: line 44, col 22, 'customConfig' is already defined.
1 error
Checking whitespace.........................OK
!!! One or more pre_commit checks failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment