From 7316f77367b83f45fd01ccf34e27469a0516a227 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 28 Jun 2011 11:06:36 -0400 Subject: [PATCH] use mocha mocking instead of punching ducks --- lib/jasmine/headless/task.rb | 21 +++++++------ spec/lib/jasmine/headless/task_spec.rb | 43 +++++++++++++------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/jasmine/headless/task.rb b/lib/jasmine/headless/task.rb index e5bcceb..7cc9cae 100644 --- a/lib/jasmine/headless/task.rb +++ b/lib/jasmine/headless/task.rb @@ -9,7 +9,7 @@ module Digest def file(file) self end - + def hexdigest 'test' end @@ -37,23 +37,24 @@ module Jasmine desc 'Run Jasmine specs headlessly' task name do Jasmine::Headless::Runner.run( - :colors => colors, - :remove_html_file => !@keep_on_error, + :colors => colors, + :remove_html_file => !@keep_on_error, :jasmine_config => @jasmine_config ) end - create_rails_compliant_task if defined?(Rails) + 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 - end + Rake::Task['assets:precompile'].invoke end + end end end end diff --git a/spec/lib/jasmine/headless/task_spec.rb b/spec/lib/jasmine/headless/task_spec.rb index bf21d14..2fedc62 100644 --- a/spec/lib/jasmine/headless/task_spec.rb +++ b/spec/lib/jasmine/headless/task_spec.rb @@ -1,38 +1,37 @@ 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 +require 'mocha' describe Jasmine::Headless::Task do after do Object.send(:remove_const, :Rails) if defined?(Rails) end - context 'without Rails' do - it 'should not explode when Rails is undefined' do - Jasmine::Headless::Task.new('jasmine:headless') - end - end - - context 'with Rails' do + describe 'define task' do before do - module Rails - def self.version - return "0" - end + Jasmine::Headless::Task.any_instance.stubs(:desc) + Jasmine::Headless::Task.any_instance.stubs(:task) + end + + context 'without Rails' do + it 'should not explode when Rails is undefined' do + Jasmine::Headless::Task.new('jasmine:headless') end end - it 'should be OK if rails is defined' do - Jasmine::Headless::Task.new('jasmine:headless') + context 'with Rails' do + before do + module Rails + def self.version + return "0" + end + end + end + + it 'should be OK if rails is defined' do + Jasmine::Headless::Task.new('jasmine:headless') + end end end end