Skip to content

Commit abef077

Browse files
author
ryan
committed
Added miniunit 1.3.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 7c083f8 commit abef077

File tree

8 files changed

+730
-0
lines changed

8 files changed

+730
-0
lines changed

lib/mini/mock.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
############################################################
2+
# This file is imported from a different project.
3+
# DO NOT make modifications in this repo.
4+
# File a patch instead and assign it to Ryan Davis
5+
############################################################
6+
7+
class MockExpectationError < StandardError; end
8+
9+
require 'mini/test'
10+
11+
class Mini::Mock
12+
def initialize
13+
@expected_calls = {}
14+
@actual_calls = Hash.new {|h,k| h[k] = [] }
15+
end
16+
17+
def expect(name, retval, args=[])
18+
n, r, a = name, retval, args # for the closure below
19+
@expected_calls[name] = { :retval => retval, :args => args }
20+
self.class.__send__(:define_method, name) { |*a|
21+
raise ArgumentError unless @expected_calls[n][:args].size == a.size
22+
@actual_calls[n] << { :retval => r, :args => a }
23+
retval
24+
}
25+
self
26+
end
27+
28+
def verify
29+
@expected_calls.each_key do |name|
30+
expected = @expected_calls[name]
31+
msg = "expected #{name}, #{expected.inspect}"
32+
raise MockExpectationError, msg unless
33+
@actual_calls.has_key? name and @actual_calls[name].include?(expected)
34+
end
35+
true
36+
end
37+
end

lib/mini/spec.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
############################################################
2+
# This file is imported from a different project.
3+
# DO NOT make modifications in this repo.
4+
# File a patch instead and assign it to Ryan Davis
5+
############################################################
6+
7+
#!/usr/bin/ruby -w
8+
9+
require 'mini/test'
10+
11+
class Module
12+
def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
13+
Mini::Assertions.public_instance_methods(false).each do |meth|
14+
meth = meth.to_s
15+
16+
new_name = case meth
17+
when /^assert/ then
18+
meth.sub(/^assert/, pos_prefix.to_s)
19+
when /^refute/ then
20+
meth.sub(/^refute/, neg_prefix.to_s)
21+
end
22+
next unless new_name
23+
next if new_name =~ skip_re
24+
25+
regexp, replacement = map.find { |re, _| new_name =~ re }
26+
new_name.sub! regexp, replacement if replacement
27+
28+
# warn "%-22p -> %p %p" % [meth, new_name, regexp]
29+
self.class_eval <<-EOM
30+
def #{new_name} *args, &block
31+
return Mini::Spec.current.#{meth}(*args, &self) if Proc === self
32+
return Mini::Spec.current.#{meth}(args.first, self) if args.size == 1
33+
return Mini::Spec.current.#{meth}(self, *args)
34+
end
35+
EOM
36+
end
37+
end
38+
end
39+
40+
Object.infect_with_assertions(:must, :wont,
41+
/^(must|wont)$|wont_(throw)|
42+
must_(block|not?_|nothing|raise$)/x,
43+
/(must_throw)s/ => '\1',
44+
/(?!not)_same/ => '_be_same_as',
45+
/_in_/ => '_be_within_',
46+
/_operator/ => '_be',
47+
/_includes/ => '_include',
48+
/(must|wont)_(.*_of|nil|empty)/ => '\1_be_\2',
49+
/must_raises/ => 'must_raise')
50+
51+
class Object
52+
alias :must_be_close_to :must_be_within_delta
53+
alias :wont_be_close_to :wont_be_within_delta
54+
end
55+
56+
module Kernel
57+
def describe desc, &block
58+
cls = Class.new(Mini::Spec)
59+
Object.const_set desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
60+
61+
cls.class_eval(&block)
62+
end
63+
end
64+
65+
class Mini::Spec < Mini::Test::TestCase
66+
def self.current
67+
@@current_spec
68+
end
69+
70+
def initialize name
71+
super
72+
@@current_spec = self
73+
end
74+
75+
def self.before(type = :each, &block)
76+
raise "unsupported before type: #{type}" unless type == :each
77+
define_method :setup, &block
78+
end
79+
80+
def self.after(type = :each, &block)
81+
raise "unsupported after type: #{type}" unless type == :each
82+
define_method :teardown, &block
83+
end
84+
85+
def self.it desc, &block
86+
define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block
87+
end
88+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy