Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
+ Holy crap! 100% doco! rdoc -C ftw
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 6786]
  • Loading branch information
zenspider committed Dec 7, 2011
1 parent b4f5b5d commit 1b84421
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 17 deletions.
5 changes: 5 additions & 0 deletions lib/hoe/minitest.rb
@@ -1,3 +1,8 @@
# :stopdoc:

class Hoe
end

module Hoe::Minitest
def initialize_minitest
gem "minitest"
Expand Down
13 changes: 10 additions & 3 deletions lib/minitest/benchmark.rb
@@ -1,9 +1,7 @@
require 'minitest/unit'
require 'minitest/spec'

class MiniTest::Unit
attr_accessor :runner

class MiniTest::Unit # :nodoc:
def run_benchmarks # :nodoc:
_run_anything :benchmark
end
Expand Down Expand Up @@ -312,6 +310,15 @@ def self.bench name, &block
define_method "bench_#{name.gsub(/\W+/, '_')}", &block
end

##
# Specifies the ranges used for benchmarking for that class.
#
# bench_range do
# bench_exp(2, 16, 2)
# end
#
# See Unit::TestCase.bench_range for more details.

def self.bench_range &block
return super unless block

Expand Down
3 changes: 2 additions & 1 deletion lib/minitest/mock.rb
@@ -1,4 +1,5 @@
class MockExpectationError < StandardError; end
class MockExpectationError < StandardError # :nodoc:
end # omg... worst bug ever. rdoc doesn't allow 1-liners

##
# A simple and clean mock object framework.
Expand Down
31 changes: 25 additions & 6 deletions lib/minitest/pride.rb
Expand Up @@ -4,12 +4,17 @@
# Show your testing pride!

class PrideIO

# Start an escape sequence
ESC = "\e["

# End the escape sequence
NND = "#{ESC}0m"

# The IO we're going to pipe through.
attr_reader :io

def initialize io
def initialize io # :nodoc:
@io = io
# stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
# also reference http://en.wikipedia.org/wiki/ANSI_escape_code
Expand All @@ -19,6 +24,9 @@ def initialize io
# io.sync = true
end

##
# Wrap print to colorize the output.

def print o
case o
when "." then
Expand All @@ -30,7 +38,7 @@ def print o
end
end

def puts(*o)
def puts(*o) # :nodoc:
o.map! { |s|
s.sub(/Finished tests/) {
@index = 0
Expand All @@ -43,22 +51,30 @@ def puts(*o)
super
end

##
# Color a string.

def pride string
string = "*" if string == "."
c = @colors[@index % @size]
@index += 1
"#{ESC}#{c}m#{string}#{NND}"
end

def method_missing msg, *args
def method_missing msg, *args # :nodoc:
io.send(msg, *args)
end
end

class PrideLOL < PrideIO # inspired by lolcat, but massively cleaned up
PI_3 = Math::PI / 3
##
# If you thought the PrideIO was colorful...
#
# (Inspired by lolcat, but with clean math)

class PrideLOL < PrideIO
PI_3 = Math::PI / 3 # :nodoc:

def initialize io
def initialize io # :nodoc:
# walk red, green, and blue around a circle separated by equal thirds.
#
# To visualize, type this into wolfram-alpha:
Expand All @@ -82,6 +98,9 @@ def initialize io
super
end

##
# Make the string even more colorful. Damnit.

def pride string
c = @colors[@index % @size]
@index += 1
Expand Down
14 changes: 13 additions & 1 deletion lib/minitest/spec.rb
Expand Up @@ -197,13 +197,22 @@ def self.it desc = "anonymous", &block
end
end

##
# Essentially, define an accessor for +name+ with +block+.
#
# Why use let instead of def? I honestly don't know.

def self.let name, &block
define_method name do
@_memoized ||= {}
@_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
end
end

##
# Another lazy man's accessor generator. Made even more lazy by
# setting the name for you to +subject+.

def self.subject &block
let :subject, &block
end
Expand Down Expand Up @@ -234,6 +243,9 @@ class << self
# :startdoc:
end

##
# It's where you hide your "assertions".

module MiniTest::Expectations
##
# See MiniTest::Assertions#assert_empty.
Expand Down Expand Up @@ -511,6 +523,6 @@ module MiniTest::Expectations
infect_an_assertion :refute_same, :wont_be_same_as
end

class Object
class Object # :nodoc:
include MiniTest::Expectations
end
35 changes: 29 additions & 6 deletions lib/minitest/unit.rb
Expand Up @@ -55,8 +55,13 @@ def self.filter_backtrace bt # :nodoc:
# printed if the assertion fails.

module Assertions
UNDEFINED = Object.new # :nodoc:

WINDOZE = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
def UNDEFINED.inspect # :nodoc:
"UNDEFINED" # again with the rdoc bugs... :(
end

WINDOZE = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # :nodoc:

##
# Returns the diff command to use in #diff. Tries to intelligently
Expand Down Expand Up @@ -281,9 +286,6 @@ def assert_nil obj, msg = nil
assert obj.nil?, msg
end

UNDEFINED = Object.new
def UNDEFINED.inspect; "UNDEFINED"; end

##
# For testing with binary operators.
#
Expand Down Expand Up @@ -640,7 +642,7 @@ def skip msg = nil, bt = caller
end
end

class Unit
class Unit # :nodoc:
VERSION = "2.8.1" # :nodoc:

attr_accessor :report, :failures, :errors, :skips # :nodoc:
Expand All @@ -650,6 +652,9 @@ class Unit
attr_accessor :verbose # :nodoc:
attr_writer :options # :nodoc:

##
# Lazy accessor for options.

def options
@options ||= {}
end
Expand Down Expand Up @@ -738,6 +743,9 @@ def self.plugins
grep(/^run_/).map { |s| s.to_s }).uniq
end

##
# Return the IO for output.

def output
self.class.output
end
Expand All @@ -750,6 +758,9 @@ def print *a # :nodoc:
output.print(*a)
end

##
# Runner for a given +type+ (eg, test vs bench).

def _run_anything type
suites = TestCase.send "#{type}_suites"
return if suites.empty?
Expand Down Expand Up @@ -787,10 +798,16 @@ def _run_anything type
status
end

##
# Runs all the +suites+ for a given +type+.

def _run_suites suites, type
suites.map { |suite| _run_suite suite, type }
end

##
# Run a single +suite+ for a given +type+.

def _run_suite suite, type
header = "#{type}_suite_header"
puts send(header, suite) if respond_to? header
Expand Down Expand Up @@ -855,7 +872,7 @@ def initialize # :nodoc:
@verbose = false
end

def process_args args = []
def process_args args = [] # :nodoc:
options = {}
orig_args = args.dup

Expand Down Expand Up @@ -1051,11 +1068,17 @@ def self.current # :nodoc:
@@current
end

##
# Return the output IO object

def io
@__io__ = true
MiniTest::Unit.output
end

##
# Have we hooked up the IO yet?

def io?
@__io__
end
Expand Down

0 comments on commit 1b84421

Please sign in to comment.