huh 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/examples/all_assertions.rb +4 -0
- data/lib/huh.rb +13 -13
- data/lib/huh_expanded.rb +109 -0
- metadata +5 -4
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Intro
|
2
2
|
=========
|
3
3
|
|
4
|
-
A tiny(<
|
4
|
+
A tiny(<40 lines) library for unit testing
|
5
5
|
|
6
6
|
Install
|
7
7
|
=========
|
@@ -13,7 +13,7 @@ or from source
|
|
13
13
|
git clone git://github.com/justinbaker/huh.git
|
14
14
|
cd huh
|
15
15
|
rake
|
16
|
-
gem install huh-1.0.
|
16
|
+
gem install huh-1.0.6.gem
|
17
17
|
|
18
18
|
Usage
|
19
19
|
=========
|
data/examples/all_assertions.rb
CHANGED
data/lib/huh.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Huh
|
2
|
-
V = "1.0.
|
2
|
+
V = "1.0.6"
|
3
3
|
class Failure < StandardError; end
|
4
4
|
def self.test(name, &block)
|
5
5
|
@t = oz(@t) + 1
|
@@ -14,22 +14,22 @@ class Huh
|
|
14
14
|
def self.assert(truth)
|
15
15
|
!!truth ? (@a = oz(@a) + 1) : (@f = oz(@f) + 1; raise Failure)
|
16
16
|
end
|
17
|
-
def self.oz(v); v or 0; end
|
18
|
-
def self.flunk; assert(false); end
|
19
|
-
def self.assert_equal(e,a); assert(e == a); end
|
17
|
+
def self.oz(v); v or 0; end
|
18
|
+
def self.flunk; assert(false); end
|
19
|
+
def self.assert_equal(e,a); assert(e == a); end
|
20
20
|
def self.assert_not_equal(e,a); assert(e != a); end
|
21
|
-
def self.assert_same(e,a); assert(e.equal?(a)); end
|
21
|
+
def self.assert_same(e,a); assert(e.equal?(a)); end
|
22
22
|
def self.assert_not_same(e,a); assert(!e.equal?(a)); end
|
23
|
-
def self.assert_nil(a); assert(a.nil?); end
|
24
|
-
def self.assert_not_nil(a); assert(!a.nil?); end
|
25
|
-
def self.assert_instance_of(k,o); assert(o.instance_of?(k)); end
|
26
|
-
def self.assert_kind_of(k,o); assert(o.kind_of?(k)); end
|
27
|
-
def self.assert_match(p,s); assert(p.match(s)); end
|
28
|
-
def self.assert_no_match(p,s); assert(!p.match(s)); end
|
29
|
-
def self.assert_respond_to(m,o); assert(o.respond_to?(m)); end
|
23
|
+
def self.assert_nil(a); assert(a.nil?); end
|
24
|
+
def self.assert_not_nil(a); assert(!a.nil?); end
|
25
|
+
def self.assert_instance_of(k,o); assert(o.instance_of?(k)); end
|
26
|
+
def self.assert_kind_of(k,o); assert(o.kind_of?(k)); end
|
27
|
+
def self.assert_match(p,s); assert(p.match(s)); end
|
28
|
+
def self.assert_no_match(p,s); assert(!p.match(s)); end
|
29
|
+
def self.assert_respond_to(m,o); assert(o.respond_to?(m)); end
|
30
30
|
def self.assert_raises(&block); assert(begin; yield; rescue; true; end); end
|
31
31
|
def self.assert_block(&block); assert(begin;yield; rescue; false; end); end
|
32
|
-
def self.assert_operator(a,b,o);assert(a.send(
|
32
|
+
def self.assert_operator(a,b,o);assert(a.send(o, b)); end
|
33
33
|
def self.assert_send(a); assert(a[0].send(a[1], *a[2..-1])); end
|
34
34
|
def self.assert_in_delta(e,a,d); assert((e.to_f - a.to_f).abs <= d.to_f); end
|
35
35
|
def self.assert_nothing_thrown(&block); assert(begin; yield; true; rescue; false;end); end
|
data/lib/huh_expanded.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
class Huh
|
2
|
+
|
3
|
+
VERSION = "1.0.5"
|
4
|
+
|
5
|
+
class Failure < StandardError; end
|
6
|
+
|
7
|
+
def self.test(name, &block)
|
8
|
+
@tests = oz(@tests) + 1
|
9
|
+
begin
|
10
|
+
yield
|
11
|
+
rescue Failure => e
|
12
|
+
print "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n"
|
13
|
+
else
|
14
|
+
print "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.assert(truth)
|
19
|
+
!!truth ? (@assertions = oz(@assertions) + 1) : (@failures = oz(@failures) + 1; raise Failure)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.oz(value)
|
23
|
+
value or 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.flunk
|
27
|
+
assert false
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.assert_equal(expected, actual)
|
31
|
+
assert expected == actual
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.assert_not_equal(expected, actual)
|
35
|
+
assert expected != actual
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.assert_same(expected, actual)
|
39
|
+
assert expected.equal?(actual)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.assert_not_same(expected, actual)
|
43
|
+
assert !expected.equal?(actual)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.assert_nil(value)
|
47
|
+
assert value.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.assert_not_nil(value)
|
51
|
+
assert !value.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.assert_instance_of(type, object)
|
55
|
+
assert object.instance_of?(type)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.assert_kind_of(kind, object)
|
59
|
+
assert object.kind_of?(kind)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.assert_match(pattern, string)
|
63
|
+
assert pattern.match(string)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.assert_no_match(pattern, string)
|
67
|
+
assert !pattern.match(string)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.assert_respond_to(meth, object)
|
71
|
+
assert object.respond_to?(meth)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.assert_raises(&block)
|
75
|
+
assert(begin; yield; rescue; true; end)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.assert_block(&block)
|
79
|
+
assert(begin;yield; rescue; false; end)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.assert_operator(a,b,operator)
|
83
|
+
assert a.send(operator, b)
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.assert_send(a)
|
87
|
+
assert(a[0].send(a[1], *a[2..-1]))
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.assert_in_delta(e,a,d)
|
91
|
+
assert((e.to_f - a.to_f).abs <= d.to_f)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.assert_nothing_thrown(&block)
|
95
|
+
assert(begin; yield; true; rescue; false;end)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.assert_nothing_raised(&block)
|
99
|
+
assert(begin; yield;true; rescue; false;end)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.finish!
|
103
|
+
percentage = (((oz(@tests)-oz(@failures)).to_f/@tests.to_f)*100).to_i
|
104
|
+
print "\n#{oz(@tests)} tests, #{oz(@assertions)} assertions, #{oz(@failures)} failures."
|
105
|
+
print "#{percentage}% passing tests}\n"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Baker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-24 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,6 +29,7 @@ extensions: []
|
|
29
29
|
extra_rdoc_files: []
|
30
30
|
|
31
31
|
files:
|
32
|
+
- lib/huh_expanded.rb
|
32
33
|
- lib/huh.rb
|
33
34
|
- examples/all_assertions.rb
|
34
35
|
- examples/flunk.rb
|