Permalink
Browse files

add jasmine-headless-webkit for javascript testing

  • Loading branch information...
siuying committed Mar 23, 2012
1 parent 9a66370 commit febb80d2513cc08208c990077a5040f6d16bde8e
View
@@ -1,3 +1,4 @@
+.jhw-cache
.DS_Store
.sass-cache
public/assets/application-*.*
View
@@ -2,12 +2,16 @@ source :rubygems
gem 'therubyracer'
+gem 'jasmine'
gem 'coffee-script'
gem 'uglifier'
gem 'sass'
gem 'sprockets'
+gem 'jasmine-headless-webkit', :git => 'git://github.com/johnbintz/jasmine-headless-webkit.git', :branch => 'master'
+
gem 'guard-rake'
gem 'guard-sprockets2'
+gem 'guard-jasmine-headless-webkit'
gem 'rb-fsevent'
View
@@ -1,34 +1,75 @@
+GIT
+ remote: git://github.com/johnbintz/jasmine-headless-webkit.git
+ revision: 21590a9a194ee80b39fa206706b9b93563b216e1
+ branch: master
+ specs:
+ jasmine-headless-webkit (0.9.0.rc1)
+ coffee-script
+ jasmine-core
+ multi_json
+ rainbow
+ sprockets
+ sprockets-vendor_gems
+
GEM
remote: http://rubygems.org/
specs:
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ diff-lcs (1.1.3)
execjs (1.3.0)
multi_json (~> 1.0)
ffi (1.0.11)
guard (1.0.1)
ffi (>= 0.5.0)
thor (~> 0.14.6)
+ guard-jasmine-headless-webkit (0.3.2)
+ guard (>= 0.4.0)
+ jasmine-headless-webkit (>= 0.7.0)
guard-rake (0.0.5)
guard
rake
guard-sprockets2 (0.0.6)
guard
sprockets (~> 2.0)
hike (1.2.1)
+ jasmine (1.1.2)
+ jasmine-core (>= 1.1.0)
+ rack (>= 1.1)
+ rspec (>= 1.3.1)
+ selenium-webdriver (>= 0.1.3)
+ jasmine-core (1.1.0)
libv8 (3.3.10.4)
multi_json (1.1.0)
rack (1.4.1)
+ rainbow (1.1.3)
rake (0.9.2.2)
rb-fsevent (0.9.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rubyzip (0.9.6.1)
sass (3.1.15)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
sprockets (2.3.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ sprockets-vendor_gems (0.1.1)
therubyracer (0.9.10)
libv8 (~> 3.3.10)
thor (0.14.6)
@@ -42,8 +83,11 @@ PLATFORMS
DEPENDENCIES
coffee-script
+ guard-jasmine-headless-webkit
guard-rake
guard-sprockets2
+ jasmine
+ jasmine-headless-webkit!
rb-fsevent
sass
sprockets
View
@@ -8,4 +8,10 @@ end
guard 'rake', :task => 'copy_assets' do
watch(%r{^public/assets/application-.+$})
+end
+
+guard 'jasmine-headless-webkit' do
+ watch(%r{^spec/(.+)_spec\.(js\.coffee|js|coffee)}) { |m| newest_js_file("spec/#{m[1]}_spec.#{m[2]}") }
+ watch(%r{^lib/(.+)\.(js\.coffee|js)|coffee}) { |m| newest_js_file("spec/lib/#{m[1]}_spec.#{m[2]}") }
+ watch(%r{spec/spec_helper\.(js\.coffee|js|coffee)}) { "spec" }
end
View
@@ -18,3 +18,12 @@ task :copy_assets do
end
end
+
+begin
+ require 'jasmine'
+ load 'jasmine/tasks/jasmine.rake'
+rescue LoadError
+ task :jasmine do
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
+ end
+end
@@ -0,0 +1,9 @@
+beforeEach(function() {
+ this.addMatchers({
+ toBePlaying: function(expectedSong) {
+ var player = this.actual;
+ return player.currentlyPlayingSong === expectedSong &&
+ player.isPlaying;
+ }
+ });
+});
@@ -0,0 +1,74 @@
+# src_files
+#
+# Return an array of filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# src_files:
+# - lib/source1.js
+# - lib/source2.js
+# - dist/**/*.js
+#
+src_files:
+ - public/assets/application.js
+
+# stylesheets
+#
+# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# stylesheets:
+# - css/style.css
+# - stylesheets/*.css
+#
+stylesheets:
+ - public/assets/application.css
+
+# helpers
+#
+# Return an array of filepaths relative to spec_dir to include before jasmine specs.
+# Default: ["helpers/**/*.js"]
+#
+# EXAMPLE:
+#
+# helpers:
+# - helpers/**/*.js
+#
+helpers:
+
+# spec_files
+#
+# Return an array of filepaths relative to spec_dir to include.
+# Default: ["**/*[sS]pec.js"]
+#
+# EXAMPLE:
+#
+# spec_files:
+# - **/*[sS]pec.js
+#
+spec_files:
+
+# src_dir
+#
+# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
+# Default: project root
+#
+# EXAMPLE:
+#
+# src_dir: public
+#
+src_dir:
+
+# spec_dir
+#
+# Spec directory path. Your spec_files must be returned relative to this path.
+# Default: spec/javascripts
+#
+# EXAMPLE:
+#
+# spec_dir: spec/javascripts
+#
+spec_dir:
@@ -0,0 +1,23 @@
+module Jasmine
+ class Config
+
+ # Add your overrides or custom config code here
+
+ end
+end
+
+
+# Note - this is necessary for rspec2, which has removed the backtrace
+module Jasmine
+ class SpecBuilder
+ def declare_spec(parent, spec)
+ me = self
+ example_name = spec["name"]
+ @spec_ids << spec["id"]
+ backtrace = @example_locations[parent.description + " " + example_name]
+ parent.it example_name, {} do
+ me.report_spec(spec["id"])
+ end
+ end
+ end
+end
@@ -0,0 +1,32 @@
+$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
+
+require 'rubygems'
+require 'jasmine'
+jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
+require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
+if Jasmine::Dependencies.rspec2?
+ require 'rspec'
+else
+ require 'spec'
+end
+
+jasmine_config = Jasmine::Config.new
+spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
+
+should_stop = false
+
+if Jasmine::Dependencies.rspec2?
+ RSpec.configuration.after(:suite) do
+ spec_builder.stop if should_stop
+ end
+else
+ Spec::Runner.configure do |config|
+ config.after(:suite) do
+ spec_builder.stop if should_stop
+ end
+ end
+end
+
+spec_builder.start
+should_stop = true
+spec_builder.declare_suites

0 comments on commit febb80d

Please sign in to comment.