Skip to content

Commit

Permalink
Update uses_mocha in ActionMailer and ActiveResource
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jul 19, 2008
1 parent 8c2e839 commit b74b97f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
18 changes: 13 additions & 5 deletions actionmailer/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ def self.start(*args)
end
end

# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
gem 'mocha', ">=0.9.0"
def uses_gem(gem_name, test_name, version = '> 0')
require 'rubygems'
gem gem_name.to_s, version
require gem_name.to_s
yield
rescue Gem::LoadError
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
rescue LoadError
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
end

# Wrap tests that use Mocha and skip if unavailable.
unless defined? uses_mocha
def uses_mocha(test_name, &block)
uses_gem('mocha', test_name, '>= 0.5.5', &block)
end
end

def set_delivery_method(delivery_method)
Expand Down
22 changes: 13 additions & 9 deletions activeresource/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")

def uses_gem(gem_name, test_name, version = '> 0')
require 'rubygems'
gem gem_name.to_s, version
require gem_name.to_s
yield
rescue LoadError
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
end

# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
unless Object.const_defined?(:Mocha)
require 'mocha'
require 'stubba'
unless defined? uses_mocha
def uses_mocha(test_name, &block)
uses_gem('mocha', test_name, '>= 0.5.5', &block)
end
yield
rescue LoadError => load_error
raise unless load_error.message =~ /mocha/i
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
end
end

0 comments on commit b74b97f

Please sign in to comment.