use mocha mocking instead of punching ducks

This commit is contained in:
John Bintz 2011-06-28 11:06:36 -04:00
parent 343fd6f84b
commit 7316f77367
2 changed files with 32 additions and 32 deletions

View File

@ -9,7 +9,7 @@ module Digest
def file(file) def file(file)
self self
end end
def hexdigest def hexdigest
'test' 'test'
end end
@ -37,23 +37,24 @@ module Jasmine
desc 'Run Jasmine specs headlessly' desc 'Run Jasmine specs headlessly'
task name do task name do
Jasmine::Headless::Runner.run( Jasmine::Headless::Runner.run(
:colors => colors, :colors => colors,
:remove_html_file => !@keep_on_error, :remove_html_file => !@keep_on_error,
:jasmine_config => @jasmine_config :jasmine_config => @jasmine_config
) )
end end
create_rails_compliant_task if defined?(Rails) create_rails_compliant_task if defined?(Rails)
end end
private private
def create_rails_compliant_task def create_rails_compliant_task
if Rails.version >= "3.1.0" if Rails.version >= "3.1.0"
desc 'Force generate static assets without an MD5 hash, all assets end with -test.<ext>' desc 'Force generate static assets without an MD5 hash, all assets end with -test.<ext>'
task 'assets:precompile:for_testing' => :environment do task 'assets:precompile:for_testing' => :environment do
Rails.application.assets.digest_class = Digest::JasmineTest Rails.application.assets.digest_class = Digest::JasmineTest
Rake::Task['assets:precompile'].invoke Rake::Task['assets:precompile'].invoke
end
end end
end
end end
end end
end end

View File

@ -1,38 +1,37 @@
require 'spec_helper' require 'spec_helper'
require 'fakefs/spec_helpers' require 'fakefs/spec_helpers'
require 'jasmine/headless/task' require 'jasmine/headless/task'
require 'mocha'
module Jasmine
module Headless
class Task
def desc(block); end
def task(block); end
end
end
end
describe Jasmine::Headless::Task do describe Jasmine::Headless::Task do
after do after do
Object.send(:remove_const, :Rails) if defined?(Rails) Object.send(:remove_const, :Rails) if defined?(Rails)
end end
context 'without Rails' do describe 'define task' do
it 'should not explode when Rails is undefined' do
Jasmine::Headless::Task.new('jasmine:headless')
end
end
context 'with Rails' do
before do before do
module Rails Jasmine::Headless::Task.any_instance.stubs(:desc)
def self.version Jasmine::Headless::Task.any_instance.stubs(:task)
return "0" end
end
context 'without Rails' do
it 'should not explode when Rails is undefined' do
Jasmine::Headless::Task.new('jasmine:headless')
end end
end end
it 'should be OK if rails is defined' do context 'with Rails' do
Jasmine::Headless::Task.new('jasmine:headless') 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 end
end end