Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add jasmine-headless-webkit for javascript testing

  • Loading branch information...
commit febb80d2513cc08208c990077a5040f6d16bde8e 1 parent 9a66370
Francis Chong authored March 23, 2012
1  .gitignore
... ...
@@ -1,3 +1,4 @@
  1
+.jhw-cache
1 2
 .DS_Store
2 3
 .sass-cache
3 4
 public/assets/application-*.*
4  Gemfile
@@ -2,12 +2,16 @@ source :rubygems
2 2
 
3 3
 gem 'therubyracer'
4 4
 
  5
+gem 'jasmine'
5 6
 gem 'coffee-script'
6 7
 gem 'uglifier'
7 8
 gem 'sass'
8 9
 gem 'sprockets'
9 10
 
  11
+gem 'jasmine-headless-webkit', :git => 'git://github.com/johnbintz/jasmine-headless-webkit.git', :branch => 'master'
  12
+
10 13
 gem 'guard-rake'
11 14
 gem 'guard-sprockets2'
  15
+gem 'guard-jasmine-headless-webkit'
12 16
 
13 17
 gem 'rb-fsevent'
44  Gemfile.lock
... ...
@@ -1,16 +1,35 @@
  1
+GIT
  2
+  remote: git://github.com/johnbintz/jasmine-headless-webkit.git
  3
+  revision: 21590a9a194ee80b39fa206706b9b93563b216e1
  4
+  branch: master
  5
+  specs:
  6
+    jasmine-headless-webkit (0.9.0.rc1)
  7
+      coffee-script
  8
+      jasmine-core
  9
+      multi_json
  10
+      rainbow
  11
+      sprockets
  12
+      sprockets-vendor_gems
  13
+
1 14
 GEM
2 15
   remote: http://rubygems.org/
3 16
   specs:
  17
+    childprocess (0.3.1)
  18
+      ffi (~> 1.0.6)
4 19
     coffee-script (2.2.0)
5 20
       coffee-script-source
6 21
       execjs
7 22
     coffee-script-source (1.2.0)
  23
+    diff-lcs (1.1.3)
8 24
     execjs (1.3.0)
9 25
       multi_json (~> 1.0)
10 26
     ffi (1.0.11)
11 27
     guard (1.0.1)
12 28
       ffi (>= 0.5.0)
13 29
       thor (~> 0.14.6)
  30
+    guard-jasmine-headless-webkit (0.3.2)
  31
+      guard (>= 0.4.0)
  32
+      jasmine-headless-webkit (>= 0.7.0)
14 33
     guard-rake (0.0.5)
15 34
       guard
16 35
       rake
@@ -18,17 +37,39 @@ GEM
18 37
       guard
19 38
       sprockets (~> 2.0)
20 39
     hike (1.2.1)
  40
+    jasmine (1.1.2)
  41
+      jasmine-core (>= 1.1.0)
  42
+      rack (>= 1.1)
  43
+      rspec (>= 1.3.1)
  44
+      selenium-webdriver (>= 0.1.3)
  45
+    jasmine-core (1.1.0)
21 46
     libv8 (3.3.10.4)
22 47
     multi_json (1.1.0)
23 48
     rack (1.4.1)
  49
+    rainbow (1.1.3)
24 50
     rake (0.9.2.2)
25 51
     rb-fsevent (0.9.0)
  52
+    rspec (2.8.0)
  53
+      rspec-core (~> 2.8.0)
  54
+      rspec-expectations (~> 2.8.0)
  55
+      rspec-mocks (~> 2.8.0)
  56
+    rspec-core (2.8.0)
  57
+    rspec-expectations (2.8.0)
  58
+      diff-lcs (~> 1.1.2)
  59
+    rspec-mocks (2.8.0)
  60
+    rubyzip (0.9.6.1)
26 61
     sass (3.1.15)
  62
+    selenium-webdriver (2.20.0)
  63
+      childprocess (>= 0.2.5)
  64
+      ffi (~> 1.0)
  65
+      multi_json (~> 1.0)
  66
+      rubyzip
27 67
     sprockets (2.3.1)
28 68
       hike (~> 1.2)
29 69
       multi_json (~> 1.0)
30 70
       rack (~> 1.0)
31 71
       tilt (~> 1.1, != 1.3.0)
  72
+    sprockets-vendor_gems (0.1.1)
32 73
     therubyracer (0.9.10)
33 74
       libv8 (~> 3.3.10)
34 75
     thor (0.14.6)
@@ -42,8 +83,11 @@ PLATFORMS
42 83
 
43 84
 DEPENDENCIES
44 85
   coffee-script
  86
+  guard-jasmine-headless-webkit
45 87
   guard-rake
46 88
   guard-sprockets2
  89
+  jasmine
  90
+  jasmine-headless-webkit!
47 91
   rb-fsevent
48 92
   sass
49 93
   sprockets
6  Guardfile
@@ -8,4 +8,10 @@ end
8 8
 
9 9
 guard 'rake', :task => 'copy_assets' do
10 10
   watch(%r{^public/assets/application-.+$})
  11
+end
  12
+
  13
+guard 'jasmine-headless-webkit' do
  14
+  watch(%r{^spec/(.+)_spec\.(js\.coffee|js|coffee)})  { |m| newest_js_file("spec/#{m[1]}_spec.#{m[2]}") }
  15
+  watch(%r{^lib/(.+)\.(js\.coffee|js)|coffee})        { |m| newest_js_file("spec/lib/#{m[1]}_spec.#{m[2]}") }
  16
+  watch(%r{spec/spec_helper\.(js\.coffee|js|coffee)}) { "spec" }
11 17
 end
9  Rakefile
@@ -18,3 +18,12 @@ task :copy_assets do
18 18
   end
19 19
 end
20 20
 
  21
+
  22
+begin
  23
+  require 'jasmine'
  24
+  load 'jasmine/tasks/jasmine.rake'
  25
+rescue LoadError
  26
+  task :jasmine do
  27
+    abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
  28
+  end
  29
+end
9  spec/javascripts/helpers/SpecHelper.js
... ...
@@ -0,0 +1,9 @@
  1
+beforeEach(function() {
  2
+  this.addMatchers({
  3
+    toBePlaying: function(expectedSong) {
  4
+      var player = this.actual;
  5
+      return player.currentlyPlayingSong === expectedSong && 
  6
+             player.isPlaying;
  7
+    }
  8
+  });
  9
+});
74  spec/javascripts/support/jasmine.yml
... ...
@@ -0,0 +1,74 @@
  1
+# src_files
  2
+#
  3
+# Return an array of filepaths relative to src_dir to include before jasmine specs.
  4
+# Default: []
  5
+#
  6
+# EXAMPLE:
  7
+#
  8
+# src_files:
  9
+#   - lib/source1.js
  10
+#   - lib/source2.js
  11
+#   - dist/**/*.js
  12
+#
  13
+src_files:
  14
+    - public/assets/application.js
  15
+
  16
+# stylesheets
  17
+#
  18
+# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
  19
+# Default: []
  20
+#
  21
+# EXAMPLE:
  22
+#
  23
+# stylesheets:
  24
+#   - css/style.css
  25
+#   - stylesheets/*.css
  26
+#
  27
+stylesheets:
  28
+  - public/assets/application.css
  29
+
  30
+# helpers
  31
+#
  32
+# Return an array of filepaths relative to spec_dir to include before jasmine specs.
  33
+# Default: ["helpers/**/*.js"]
  34
+#
  35
+# EXAMPLE:
  36
+#
  37
+# helpers:
  38
+#   - helpers/**/*.js
  39
+#
  40
+helpers:
  41
+
  42
+# spec_files
  43
+#
  44
+#  Return an array of filepaths relative to spec_dir to include.
  45
+# Default: ["**/*[sS]pec.js"]
  46
+#
  47
+# EXAMPLE:
  48
+#
  49
+# spec_files:
  50
+#   - **/*[sS]pec.js
  51
+#
  52
+spec_files:
  53
+
  54
+# src_dir
  55
+#
  56
+# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
  57
+# Default: project root
  58
+#
  59
+# EXAMPLE:
  60
+#
  61
+# src_dir: public
  62
+#
  63
+src_dir:
  64
+
  65
+# spec_dir
  66
+#
  67
+# Spec directory path. Your spec_files must be returned relative to this path.
  68
+# Default: spec/javascripts
  69
+#
  70
+# EXAMPLE:
  71
+#
  72
+# spec_dir: spec/javascripts
  73
+#
  74
+spec_dir:
23  spec/javascripts/support/jasmine_config.rb
... ...
@@ -0,0 +1,23 @@
  1
+module Jasmine
  2
+  class Config
  3
+
  4
+    # Add your overrides or custom config code here
  5
+
  6
+  end
  7
+end
  8
+
  9
+
  10
+# Note - this is necessary for rspec2, which has removed the backtrace
  11
+module Jasmine
  12
+  class SpecBuilder
  13
+    def declare_spec(parent, spec)
  14
+      me = self
  15
+      example_name = spec["name"]
  16
+      @spec_ids << spec["id"]
  17
+      backtrace = @example_locations[parent.description + " " + example_name]
  18
+      parent.it example_name, {} do
  19
+        me.report_spec(spec["id"])
  20
+      end
  21
+    end
  22
+  end
  23
+end
32  spec/javascripts/support/jasmine_runner.rb
... ...
@@ -0,0 +1,32 @@
  1
+$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
  2
+
  3
+require 'rubygems'
  4
+require 'jasmine'
  5
+jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
  6
+require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
  7
+if Jasmine::Dependencies.rspec2?
  8
+  require 'rspec'
  9
+else
  10
+  require 'spec'
  11
+end
  12
+
  13
+jasmine_config = Jasmine::Config.new
  14
+spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
  15
+
  16
+should_stop = false
  17
+
  18
+if Jasmine::Dependencies.rspec2?
  19
+  RSpec.configuration.after(:suite) do
  20
+    spec_builder.stop if should_stop
  21
+  end
  22
+else
  23
+  Spec::Runner.configure do |config|
  24
+    config.after(:suite) do
  25
+      spec_builder.stop if should_stop
  26
+    end
  27
+  end
  28
+end
  29
+
  30
+spec_builder.start
  31
+should_stop = true
  32
+spec_builder.declare_suites

0 notes on commit febb80d

Please sign in to comment.
Something went wrong with that request. Please try again.