test/testing.rb in mongoid-grid_fs-2.4.0 vs test/testing.rb in mongoid-grid_fs-2.5.0
- old
+ new
@@ -1,9 +1,9 @@
-# -*- encoding : utf-8 -*-
+
require 'minitest/autorun'
-testdir = File.expand_path(File.dirname(__FILE__))
+testdir = __dir__
rootdir = File.dirname(testdir)
libdir = File.join(rootdir, 'lib')
STDOUT.sync = true
@@ -14,11 +14,11 @@
class Testing
class Slug < ::String
def self.for(*args)
string = args.flatten.compact.join('-')
words = string.to_s.scan(/\w+/)
- words.map! { |word| word.gsub /[^0-9a-zA-Z_-]/, '' }
+ words.map! { |word| word.gsub(/[^0-9a-zA-Z_-]/, '') }
words.delete_if { |word| word.nil? || word.strip.empty? }
new(words.join('-').downcase)
end
end
@@ -33,11 +33,11 @@
Slug.for(name)
end
end
end
-def Testing(*args, &block)
+def _testing(*args, &block)
Class.new(::Minitest::Test) do
i_suck_and_my_tests_are_order_dependent!
## class methods
#
@@ -60,21 +60,21 @@
end
def slug_for(*args)
string = [context, args].flatten.compact.join('-')
words = string.to_s.scan(/\w+/)
- words.map! { |word| word.gsub /[^0-9a-zA-Z_-]/, '' }
+ words.map! { |word| word.gsub(/[^0-9a-zA-Z_-]/, '') }
words.delete_if { |word| word.nil? || word.strip.empty? }
words.join('-').downcase.sub(/_$/, '')
end
def name
const_get(:Name)
end
def testno
- '%05d' % (@testno ||= 0)
+ format('%05d', (@testno ||= 0))
ensure
@testno += 1
end
def testing(*args, &block)
@@ -109,11 +109,11 @@
## configure the subclass!
#
const_set(:Testno, '0')
slug = slug_for(*args).tr('-', '_')
- name = ['TESTING', '%03d' % const_get(:Testno), slug].delete_if(&:empty?).join('_')
+ name = ['TESTING', format('%03d', const_get(:Testno)), slug].delete_if(&:empty?).join('_')
name = name.upcase!
const_set(:Name, name)
const_set(:Missing, Object.new.freeze)
## instance methods
@@ -123,30 +123,26 @@
def assert(*args, &block)
if (args.size == 1) && args.first.is_a?(Hash)
options = args.first
expected = getopt(:expected, options) { missing }
actual = getopt(:actual, options) { missing }
- if (expected == missing) && (actual == missing)
- actual, expected, *ignored = options.to_a.flatten
- end
+ actual, expected, = options.to_a.flatten if (expected == missing) && (actual == missing)
expected = expected.call if expected.respond_to?(:call)
actual = actual.call if actual.respond_to?(:call)
assert_equal(expected, actual)
end
result = if block
label = "assert(#{args.join(' ')})"
- result = nil
- result = yield
- __assert__(result, label)
- result
+ yield
else
result = args.shift
label = "assert(#{args.join(' ')})"
- __assert__(result, label)
result
- end
+ end
+ __assert__(result, label)
+ result
end
def missing
self.class.const_get(:Missing)
end
@@ -189,10 +185,10 @@
end
end
if $PROGRAM_NAME == __FILE__
- Testing 'Testing' do
+ _testing 'Testing' do
testing('foo') { assert true }
test { assert true }
p instance_methods.grep(/test/)
end