From 4e5ba7945ca165a3ef1da8eb2d974dc506a20609 Mon Sep 17 00:00:00 2001 From: Zachary Spencer Date: Tue, 28 Jun 2011 16:25:32 +0800 Subject: [PATCH 1/3] Made it so the rake task doesn't explode if you're too cool to use Rails --- lib/jasmine/headless/task.rb | 17 ++++++++++------- spec/lib/jasmine/headless/task_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 spec/lib/jasmine/headless/task_spec.rb diff --git a/lib/jasmine/headless/task.rb b/lib/jasmine/headless/task.rb index 05ae7cc..e5bcceb 100644 --- a/lib/jasmine/headless/task.rb +++ b/lib/jasmine/headless/task.rb @@ -42,15 +42,18 @@ module Jasmine :jasmine_config => @jasmine_config ) end + create_rails_compliant_task if defined?(Rails) + end + private + def create_rails_compliant_task + if Rails.version >= "3.1.0" + desc 'Force generate static assets without an MD5 hash, all assets end with -test.' + task 'assets:precompile:for_testing' => :environment do + Rails.application.assets.digest_class = Digest::JasmineTest - if Rails.version >= "3.1.0" - desc 'Force generate static assets without an MD5 hash, all assets end with -test.' - task 'assets:precompile:for_testing' => :environment do - Rails.application.assets.digest_class = Digest::JasmineTest - - Rake::Task['assets:precompile'].invoke + Rake::Task['assets:precompile'].invoke + end end - end end end end diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb new file mode 100644 index 0000000..69847fe --- /dev/null +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' +require 'fakefs/spec_helpers' +require 'jasmine/headless/task' + +module Jasmine + module Headless + class Task + def desc(block) + end + def task(block) + end + end + end +end +describe Jasmine::Headless::Task do + it 'should not explode when Rails is undefined' do + Jasmine::Headless::Task.new('jasmine:headless') do |t| + end + end +end From ccaab1c8f3891d04e1e68479e4d3f273ce2525d3 Mon Sep 17 00:00:00 2001 From: Zachary Spencer Date: Tue, 28 Jun 2011 16:25:32 +0800 Subject: [PATCH 2/3] Made it so the rake task doesn't explode if you're too cool to use Rails --- lib/jasmine/headless/task.rb | 17 ++++++++++------- spec/lib/jasmine/headless/task_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 spec/lib/jasmine/headless/task_spec.rb diff --git a/lib/jasmine/headless/task.rb b/lib/jasmine/headless/task.rb index 05ae7cc..e5bcceb 100644 --- a/lib/jasmine/headless/task.rb +++ b/lib/jasmine/headless/task.rb @@ -42,15 +42,18 @@ module Jasmine :jasmine_config => @jasmine_config ) end + create_rails_compliant_task if defined?(Rails) + end + private + def create_rails_compliant_task + if Rails.version >= "3.1.0" + desc 'Force generate static assets without an MD5 hash, all assets end with -test.' + task 'assets:precompile:for_testing' => :environment do + Rails.application.assets.digest_class = Digest::JasmineTest - if Rails.version >= "3.1.0" - desc 'Force generate static assets without an MD5 hash, all assets end with -test.' - task 'assets:precompile:for_testing' => :environment do - Rails.application.assets.digest_class = Digest::JasmineTest - - Rake::Task['assets:precompile'].invoke + Rake::Task['assets:precompile'].invoke + end end - end end end end diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb new file mode 100644 index 0000000..69847fe --- /dev/null +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' +require 'fakefs/spec_helpers' +require 'jasmine/headless/task' + +module Jasmine + module Headless + class Task + def desc(block) + end + def task(block) + end + end + end +end +describe Jasmine::Headless::Task do + it 'should not explode when Rails is undefined' do + Jasmine::Headless::Task.new('jasmine:headless') do |t| + end + end +end From 3b214f913f842ac89513214a4fbd363402e1dc9d Mon Sep 17 00:00:00 2001 From: Zachary Spencer Date: Tue, 28 Jun 2011 16:49:31 +0800 Subject: [PATCH 3/3] made the tests a bit more robust, but they may now be more DANGEROUS! --- spec/lib/jasmine/headless/task_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb index 69847fe..e31a8dd 100644 --- a/spec/lib/jasmine/headless/task_spec.rb +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -14,6 +14,16 @@ module Jasmine end describe Jasmine::Headless::Task do it 'should not explode when Rails is undefined' do + Object.send(:remove_const, :Rails) if defined?(Rails) + Jasmine::Headless::Task.new('jasmine:headless') do |t| + end + end + it 'should be OK if rails is defined' do + module Rails + def self.version + return "0" + end + end Jasmine::Headless::Task.new('jasmine:headless') do |t| end end