Created
April 14, 2012 04:47
-
-
Save dougo-chris/2382173 to your computer and use it in GitHub Desktop.
jasmine & jenkins
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
group :development, :test do | |
gem 'jasmine', '1.2.0.rc2', :git => 'https://github.com/pivotal/jasmine-gem.git', :require => false | |
# gem 'jasmine' | |
gem 'headless', :require => false | |
bundle install | |
bundle exec jasmine init | |
rm lib/tasks/jasmine.rake | |
rm public/javascripts/Player.js | |
rm public/javascripts/Song.js | |
rm spec/javascripts/PlayerSpec.js | |
rm -rf spec/javascripts/helpers | |
# spec/javascripts/support/jasmine_config.rb | |
# when jasmine starts the server out-of-process, it needs this in order to be able to invoke the asset tasks | |
unless Object.const_defined?(:Rake) | |
require 'rake' | |
load File.expand_path('../../../../Rakefile', __FILE__) | |
end | |
module Jasmine | |
class Config | |
include Rake::DSL | |
def js_files(spec_filter = nil) | |
# remove all generated files | |
generated_files_directory = Rails.root.join("tmp/jasmine") | |
rm_rf generated_files_directory, :secure => true | |
precompile_app_assets | |
compile_jasmine_javascripts | |
# this is code from the original jasmine config js_files method - you could also just alias_method_chain it | |
spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter]) | |
src_files.collect {|f| "/" + f } + helpers.collect {|f| File.join(spec_path, f) } + spec_files_to_include.collect {|f| File.join(spec_path, f) } | |
end | |
private | |
# this method compiles all the same javascript files your app will | |
def precompile_app_assets | |
puts "Precompiling assets..." | |
ENV["RAILS_GROUPS"] ||= "assets" | |
ENV["RAILS_ENV"] ||= "test" | |
# make sure the Rails environment is loaded | |
::Rake.application['environment'].invoke | |
# Previously, ::Rails.application.assets.static_root was set to | |
# a temporary compiled dir. In lieu of sprockets' deprecation of | |
# static_root, ::Rails.application.assets.manifest and | |
# ::Rails.application.config.assets.prefix are now set to the compiled | |
# dir. | |
::Rails.application.config.assets.manifest = "tmp/jasmine/assets" | |
::Rails.application.config.assets.prefix = "../tmp/jasmine/assets" | |
# rake won't let you run the same task twice in the same process without | |
# re-enabling it | |
# once the assets have been cleared, recompile them into the spec directory | |
::Rake.application['assets:precompile'].reenable | |
::Rake.application['assets:precompile'].invoke | |
end | |
# this method compiles all of the spec files into js files that jasmine can run | |
def compile_jasmine_javascripts | |
puts "Compiling jasmine coffee scripts into javascript..." | |
root = File.expand_path(Rails.root.join("spec/javascripts"), __FILE__) | |
destination_dir = File.expand_path(Rails.root.join("tmp/jasmine/specs"), __FILE__) | |
# copy json files used as fixtures | |
glob = File.expand_path("**/*.json", root) | |
Dir.glob(glob).each do |srcfile| | |
srcfile = Pathname.new(srcfile) | |
destfile = srcfile.sub(root, destination_dir) | |
FileUtils.mkdir_p(destfile.dirname) | |
File.open(destfile, "w") {|f| f.write(File.new(srcfile))} | |
end | |
glob = File.expand_path("**/*.js.coffee", root) | |
Dir.glob(glob).each do |srcfile| | |
srcfile = Pathname.new(srcfile) | |
destfile = srcfile.sub(root, destination_dir).sub(".coffee", "") | |
FileUtils.mkdir_p(destfile.dirname) | |
File.open(destfile, "w") {|f| f.write(CoffeeScript.compile(File.new(srcfile)))} | |
end | |
end | |
end | |
end | |
... | |
# spec/javascripts/support/jasmine.yml | |
src_files: | |
- spec/javascripts/support/sinon.js | |
- spec/javascripts/support/jasmine-sinon.js | |
- spec/javascripts/support/jasmine-jquery.js | |
- spec/javascripts/fixtures/*.json | |
- tmp/jasmine/assets/application*.js | |
spec_files: | |
- '**/*[sS]pec.js' | |
src_dir: | |
spec_dir: tmp/jasmine | |
# lib/tasks/headless_jasmine.rake | |
namespace :jasmine do | |
namespace :ci do | |
desc "Run Jasmine CI build headlessly" | |
task :headless do | |
Headless.ly do | |
puts "Running Jasmine Headlessly" | |
Rake::Task['jasmine:ci'].invoke | |
end | |
end | |
end | |
end | |
# .gitignore | |
spec/javascripts/generated/* | |
bundle exec rake jasmine:ci | |
bundle exec rake jasmine:ci:headless | |
Chrome | |
------ | |
download driver | |
http://code.google.com/p/chromium/downloads/list | |
namespace :jasmine do | |
namespace :ci do | |
desc "Run Jasmine CI build headlessly" | |
task :headless do | |
require 'jasmine' | |
require 'headless' | |
Headless.ly do | |
puts "Running Jasmine Headlessly" | |
ENV["JASMINE_BROWSER"] = "chrome" | |
Rake::Task['jasmine:ci'].invoke | |
end | |
end | |
end | |
end | |
Origional Setup : USE ABOVE | |
---------------------------- | |
http://pivotallabs.com/users/jdean/blog/articles/1778 | |
# spec/javascripts/support/jasmine_config.rb | |
# when jasmine starts the server out-of-process, it needs this in order to be able to invoke the asset tasks | |
unless Object.const_defined?(:Rake) | |
require 'rake' | |
load File.expand_path('../../../../Rakefile', __FILE__) | |
end | |
module Jasmine | |
class Config | |
include Rake::DSL | |
def js_files(spec_filter = nil) | |
# remove all generated files | |
generated_files_directory = File.expand_path("../../generated", __FILE__) | |
rm_rf generated_files_directory, :secure => true | |
precompile_app_assets | |
compile_jasmine_javascripts | |
# this is code from the original jasmine config js_files method - you could also just alias_method_chain it | |
spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter]) | |
src_files.collect {|f| "/" + f } + helpers.collect {|f| File.join(spec_path, f) } + spec_files_to_include.collect {|f| File.join(spec_path, f) } | |
end | |
private | |
# this method compiles all the same javascript files your app will | |
def precompile_app_assets | |
puts "Precompiling assets..." | |
ENV["RAILS_GROUPS"] ||= "assets" | |
ENV["RAILS_ENV"] ||= "test" | |
# make sure the Rails environment is loaded | |
::Rake.application['environment'].invoke | |
# Previously, ::Rails.application.assets.static_root was set to | |
# a temporary compiled dir. In lieu of sprockets' deprecation of | |
# static_root, ::Rails.application.assets.manifest and | |
# ::Rails.application.config.assets.prefix are now set to the compiled | |
# dir. | |
::Rails.application.config.assets.manifest = "spec/javascripts/generated/assets" | |
::Rails.application.config.assets.prefix = "../spec/javascripts/generated/assets" | |
# rake won't let you run the same task twice in the same process without | |
# re-enabling it | |
# once the assets have been cleared, recompile them into the spec directory | |
::Rake.application['assets:precompile'].reenable | |
::Rake.application['assets:precompile'].invoke | |
end | |
# this method compiles all of the spec files into js files that jasmine can run | |
def compile_jasmine_javascripts | |
puts "Compiling jasmine coffee scripts into javascript..." | |
root = File.expand_path("../../../../spec/javascripts", __FILE__) | |
destination_dir = File.expand_path("../../generated/specs", __FILE__) | |
glob = File.expand_path("**/*.js.coffee", root) | |
Dir.glob(glob).each do |srcfile| | |
srcfile = Pathname.new(srcfile) | |
destfile = srcfile.sub(root, destination_dir).sub(".coffee", "") | |
FileUtils.mkdir_p(destfile.dirname) | |
File.open(destfile, "w") {|f| f.write(CoffeeScript.compile(File.new(srcfile)))} | |
end | |
end | |
end | |
end | |
... | |
# spec/javascripts/support/jasmine.yml | |
src_files: | |
- spec/javascripts/support/sinon.js | |
- spec/javascripts/support/jasmine-sinon.js | |
- spec/javascripts/support/jasmine-jquery.js | |
- spec/javascripts/fixtures/*.json | |
- spec/javascripts/fixtures/*.fixture.js | |
- spec/javascripts/generated/assets/application*.js | |
spec_files: | |
- '**/*[sS]pec.js' | |
src_dir: | |
spec_dir: spec/javascripts | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment