Skip to content

Commit b74b97f

Browse files
committed
Update uses_mocha in ActionMailer and ActiveResource
1 parent 8c2e839 commit b74b97f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

actionmailer/test/abstract_unit.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ def self.start(*args)
3030
end
3131
end
3232

33-
# Wrap tests that use Mocha and skip if unavailable.
34-
def uses_mocha(test_name)
35-
gem 'mocha', ">=0.9.0"
33+
def uses_gem(gem_name, test_name, version = '> 0')
34+
require 'rubygems'
35+
gem gem_name.to_s, version
36+
require gem_name.to_s
3637
yield
37-
rescue Gem::LoadError
38-
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
38+
rescue LoadError
39+
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
40+
end
41+
42+
# Wrap tests that use Mocha and skip if unavailable.
43+
unless defined? uses_mocha
44+
def uses_mocha(test_name, &block)
45+
uses_gem('mocha', test_name, '>= 0.5.5', &block)
46+
end
3947
end
4048

4149
def set_delivery_method(delivery_method)

activeresource/test/abstract_unit.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99

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

12+
def uses_gem(gem_name, test_name, version = '> 0')
13+
require 'rubygems'
14+
gem gem_name.to_s, version
15+
require gem_name.to_s
16+
yield
17+
rescue LoadError
18+
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
19+
end
20+
1221
# Wrap tests that use Mocha and skip if unavailable.
13-
def uses_mocha(test_name)
14-
unless Object.const_defined?(:Mocha)
15-
require 'mocha'
16-
require 'stubba'
22+
unless defined? uses_mocha
23+
def uses_mocha(test_name, &block)
24+
uses_gem('mocha', test_name, '>= 0.5.5', &block)
1725
end
18-
yield
19-
rescue LoadError => load_error
20-
raise unless load_error.message =~ /mocha/i
21-
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
22-
end
26+
end

0 commit comments

Comments
 (0)