huh 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79ff651fa273d7c1e691c9eae2c90a1b5574ede7acbff20aed6f4d8a51dd3aa9
4
+ data.tar.gz: d60c2024380bec661dc5176fdb080d4bb926fee4a1127f8504b3bc3e2150919e
5
+ SHA512:
6
+ metadata.gz: 7ca5f3eb10c28e4eb7d8980aca2d4344d7795673409c4f87ca3aed767e7ac66e0ee492fc238b1a50ac784ac76add1c1286d8ca855f081fd84795d9b044d395f4
7
+ data.tar.gz: 8a4318da9cdbd72cb56432b8cc587b522832fd51c5084534450ef4179322e0ee7b6da988879099e8f757f868d87a58dfecbcd891925f673b942f030b3a4bc2cf
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 Justin Baker
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 Justin Baker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,88 +1,92 @@
1
- Intro
2
- =========
3
-
4
- A tiny(<40 lines) library for unit testing
5
-
6
- Install
7
- =========
8
-
9
- sudo gem install huh
10
-
11
- or from source
12
-
13
- git clone git://github.com/justinbaker/huh.git
14
- cd huh
15
- rake
16
- gem install huh-1.0.8.gem
17
-
18
- Usage
19
- =========
20
-
21
- class PostTest < Huh
22
-
23
- test "should_not_save" do
24
- @post = Post.new
25
- assert !@post.save
26
- end
27
-
28
- finish!
29
-
30
- end
31
-
32
- Don't forget the finish!; it prints out number of tests, assertions, failures, as well as percentage of passing tests.
33
-
34
- Running tests from `irb` or `rails console`
35
- =============================================
36
-
37
- Just require huh, and call Huh#run with all test files as an argument.
38
-
39
- require "huh"
40
- Huh.run(Dir.glob("examples/*.rb"))
41
-
42
- Assertions
43
- ============
44
-
45
- The current list of assertions available:
46
-
47
- - assert(a): expects a to be true
48
- - assert_equal(a, b): expects a == b
49
- - assert_not_equal(a, b): expects a != b
50
- - assert_same(a, b): expects a.equal?(b)
51
- - assert_not_same(a, b): expects !a.equal?(b)
52
- - assert_nil(a): expects a == nil
53
- - assert_not_nil(a): expects a != nil
54
- - assert_instance_of(t, o): expects o.instance_of?(t)
55
- - assert_kind_of(t, o): expects o.kind_of?(t)
56
- - assert_match(p,s): expects p.match(s)
57
- - assert_no_match(p,s): expects !p.match(s)
58
- - assert_respond_to(m,o): expects o.respond_to?(m)
59
- - assert_raises(block): expects block.call to raise an error
60
- - assert_block(block): expects block.call to return true
61
- - assert_send(array): expects array[0].send(array[1], array[REST OF ARRAY])
62
- - assert_in_delta(e,a,d): expects e-a to be less than or equal to d
63
- - assert_nothing_thrown(block): expects block to throw nothing
64
- - assert_nothing_raised(block): expects block to raise nothing
65
- - flunk: fails always
66
-
67
- License
68
- ===========
69
- Copyright (c) 2010 Justin baker
70
-
71
- Permission is hereby granted, free of charge, to any person obtaining
72
- a copy of this software and associated documentation files (the
73
- "Software"), to deal in the Software without restriction, including
74
- without limitation the rights to use, copy, modify, merge, publish,
75
- distribute, sublicense, and/or sell copies of the Software, and to
76
- permit persons to whom the Software is furnished to do so, subject to
77
- the following conditions:
78
-
79
- The above copyright notice and this permission notice shall be
80
- included in all copies or substantial portions of the Software.
81
-
82
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
83
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
85
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
86
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
87
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
88
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # HUH
2
+
3
+ (Don't use this. I don't maintain it.)
4
+
5
+ Originally written in 2010 as an exercise in how small a test framework can be.
6
+
7
+ A tiny(<40 lines) library for unit testing
8
+
9
+ Install
10
+ =========
11
+
12
+ gem install huh
13
+
14
+ or from source
15
+
16
+ git clone https://github.com/slayyyyer/huh.git
17
+ cd huh
18
+ rake
19
+ gem install huh-2.0.0.gem
20
+
21
+ Usage
22
+ =========
23
+
24
+ class PostTest < Huh
25
+
26
+ test "should_not_save" do
27
+ @post = Post.new
28
+ assert !@post.save
29
+ end
30
+
31
+ finish!
32
+
33
+ end
34
+
35
+ Don't forget the finish!; it prints out number of tests, assertions, failures, as well as percentage of passing tests.
36
+
37
+ Running tests from `irb` or `rails console`
38
+ =============================================
39
+
40
+ Just require huh, and call Huh#run with all test files as an argument.
41
+
42
+ require "huh"
43
+ Huh.run(Dir.glob("examples/*.rb"))
44
+
45
+ Assertions
46
+ ============
47
+
48
+ The current list of assertions available:
49
+
50
+ - `assert(a)`: expects a to be true
51
+ - `assert_equal(a, b)`: expects a == b
52
+ - `assert_not_equal(a, b)`: expects a != b
53
+ - `assert_same(a, b)`: expects a.equal?(b)
54
+ - `assert_not_same(a, b)`: expects !a.equal?(b)
55
+ - `assert_nil(a)`: expects a == nil
56
+ - `assert_not_nil(a)`: expects a != nil
57
+ - `assert_instance_of(t, o)`: expects o.instance_of?(t)
58
+ - `assert_kind_of(t, o)`: expects o.kind_of?(t)
59
+ - `assert_match(p,s)`: expects p.match(s)
60
+ - `assert_no_match(p,s)`: expects !p.match(s)
61
+ - `assert_respond_to(m,o)`: expects o.respond_to?(m)
62
+ - `assert_raises(block)`: expects block.call to raise an error
63
+ - `assert_block(block)`: expects block.call to return true
64
+ - `assert_operator(a, b, o)`: expects a.send(o, b)
65
+ - `assert_send(array)`: expects array[0].send(array[1], array[REST OF ARRAY])
66
+ - `assert_in_delta(e,a,d)`: expects (e-a).abs to be less than or equal to d
67
+ - `assert_nothing_thrown(block)`: expects block to throw nothing
68
+ - `assert_nothing_raised(block)`: expects block to raise nothing
69
+ - `flunk`: fails always
70
+
71
+ License
72
+ ===========
73
+ Copyright (c) 2015 Justin baker
74
+
75
+ Permission is hereby granted, free of charge, to any person obtaining
76
+ a copy of this software and associated documentation files (the
77
+ "Software"), to deal in the Software without restriction, including
78
+ without limitation the rights to use, copy, modify, merge, publish,
79
+ distribute, sublicense, and/or sell copies of the Software, and to
80
+ permit persons to whom the Software is furnished to do so, subject to
81
+ the following conditions:
82
+
83
+ The above copyright notice and this permission notice shall be
84
+ included in all copies or substantial portions of the Software.
85
+
86
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
88
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
89
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
90
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
91
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
92
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,83 +1,83 @@
1
- require File.dirname(__FILE__) + "/../lib/huh"
2
-
3
- class Test < Huh
4
-
5
- test "the truth" do
6
- assert true
7
- end
8
-
9
- test "the power of equality" do
10
- assert_equal "me", "me"
11
- end
12
-
13
- test "the power of inequality" do
14
- assert_not_equal "me", "you"
15
- end
16
-
17
- test "nil yo" do
18
- assert_nil nil
19
- end
20
-
21
- test "not nil yo" do
22
- assert_not_nil true
23
- end
24
-
25
- test "everything is a class" do
26
- assert_instance_of Fixnum, 1
27
- end
28
-
29
- test "everything is a class" do
30
- assert_kind_of Fixnum, 1
31
- end
32
-
33
- test "love match" do
34
- assert_match /love/, "love"
35
- end
36
-
37
- test "no_love_match" do
38
- assert_no_match /love/, "loner"
39
- end
40
-
41
- test "respond_to?" do
42
- assert_respond_to :gsub, "hello"
43
- end
44
-
45
- test "should get pissed" do
46
- assert_raises do
47
- raise "WHAT THE FUCK"
48
- end
49
- end
50
-
51
- test "should be true" do
52
- assert_block do
53
- true
54
- end
55
- end
56
-
57
- test "should send it" do
58
- assert_send [[1,2], :include?, 1]
59
- end
60
-
61
- test "delta!!!!" do
62
- assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
63
- end
64
-
65
- test "shouldn't have no problems throwing" do
66
- assert_nothing_thrown do
67
- "I'm a good kid :)"
68
- end
69
- end
70
-
71
- test "shouldn't have no problems raising" do
72
- assert_nothing_raised do
73
- "I'm a good kid :)"
74
- end
75
- end
76
-
77
- test "should fail!!!!" do
78
- flunk
79
- end
80
-
81
- finish!
82
-
83
- end
1
+ require_relative "../lib/huh"
2
+
3
+ class Test < Huh
4
+
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+
9
+ test "the power of equality" do
10
+ assert_equal "me", "me"
11
+ end
12
+
13
+ test "the power of inequality" do
14
+ assert_not_equal "me", "you"
15
+ end
16
+
17
+ test "nil yo" do
18
+ assert_nil nil
19
+ end
20
+
21
+ test "not nil yo" do
22
+ assert_not_nil true
23
+ end
24
+
25
+ test "everything is a class" do
26
+ assert_instance_of Integer, 1
27
+ end
28
+
29
+ test "everything is a class" do
30
+ assert_kind_of Integer, 1
31
+ end
32
+
33
+ test "love match" do
34
+ assert_match /love/, "love"
35
+ end
36
+
37
+ test "no_love_match" do
38
+ assert_no_match /love/, "loner"
39
+ end
40
+
41
+ test "respond_to?" do
42
+ assert_respond_to :gsub, "hello"
43
+ end
44
+
45
+ test "should get pissed" do
46
+ assert_raises do
47
+ raise "WHAT THE FUCK"
48
+ end
49
+ end
50
+
51
+ test "should be true" do
52
+ assert_block do
53
+ true
54
+ end
55
+ end
56
+
57
+ test "should send it" do
58
+ assert_send [[1,2], :include?, 1]
59
+ end
60
+
61
+ test "delta!!!!" do
62
+ assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
63
+ end
64
+
65
+ test "shouldn't have no problems throwing" do
66
+ assert_nothing_thrown do
67
+ "I'm a good kid :)"
68
+ end
69
+ end
70
+
71
+ test "shouldn't have no problems raising" do
72
+ assert_nothing_raised do
73
+ "I'm a good kid :)"
74
+ end
75
+ end
76
+
77
+ test "should fail!!!!" do
78
+ flunk
79
+ end
80
+
81
+ finish!
82
+
83
+ end
data/examples/basic.rb CHANGED
@@ -1,11 +1,11 @@
1
- require File.dirname(__FILE__) + "/../lib/huh"
2
-
3
- class Test < Huh
4
-
5
- test "the truth" do
6
- assert true
7
- end
8
-
9
- finish!
10
-
11
- end
1
+ require_relative "../lib/huh"
2
+
3
+ class Test < Huh
4
+
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+
9
+ finish!
10
+
11
+ end
data/lib/huh/task.rb CHANGED
@@ -1,9 +1,18 @@
1
- class Huh
2
- class Task
3
- def initialize(name = :test, files = [])
4
- task name do
5
- Huh.run(files)
6
- end
7
- end
8
- end
9
- end
1
+ # Huh is a small unit testing library
2
+ # It supports many assertions commonly used, and has no external dependencies.
3
+ #
4
+ # Author:: Justin Baker (mailto:bakermoto@gmail.com)
5
+ # Copyright:: Copyright (c) 2010 Justin Baker
6
+ # License:: MIT license
7
+
8
+ # This class creates a task in a Rakefile to run tests from rake
9
+ #
10
+ class Huh
11
+ class Task
12
+ def initialize(name = :test, files = [])
13
+ Rake::Task.define_task(name) do
14
+ Huh.run(files)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/huh.rb CHANGED
@@ -1,38 +1,37 @@
1
- class Huh
2
- V = "1.0.8" unless defined?(V)
3
- class Failure < StandardError; end
4
- def self.test(name, &block)
5
- @t = oz(@t) + 1
6
- print begin; yield; "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n"; rescue Failure => e; "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n" ;end
7
- end
8
- def self.setup(&block); @setup = block; end
9
- def self.teardown(&block); @teardown = block; end
10
- def self.assert(truth)
11
- @setup.call if @setup
12
- !!truth ? (@a = oz(@a) + 1) : (@f = oz(@f) + 1; raise Failure)
13
- @teardown.call if @teardown
14
- end
15
- def self.oz(v); v or 0; end
16
- def self.flunk; assert(false); end
17
- def self.assert_equal(e,a); assert(e == a); end
18
- def self.assert_not_equal(e,a); assert(e != a); end
19
- def self.assert_same(e,a); assert(e.equal?(a)); end
20
- def self.assert_not_same(e,a); assert(!e.equal?(a)); end
21
- def self.assert_nil(a); assert(a.nil?); end
22
- def self.assert_not_nil(a); assert(!a.nil?); end
23
- def self.assert_instance_of(k,o); assert(o.instance_of?(k)); end
24
- def self.assert_kind_of(k,o); assert(o.kind_of?(k)); end
25
- def self.assert_match(p,s); assert(p.match(s)); end
26
- def self.assert_no_match(p,s); assert(!p.match(s)); end
27
- def self.assert_respond_to(m,o); assert(o.respond_to?(m)); end
28
- def self.assert_raises(&block); assert(begin; yield; rescue; true; end); end
29
- def self.assert_block(&block); assert(begin;yield; rescue; false; end); end
30
- def self.assert_operator(a,b,o);assert(a.send(o, b)); end
31
- def self.assert_send(a); assert(a[0].send(a[1], *a[2..-1])); end
32
- def self.assert_in_delta(e,a,d); assert((e.to_f - a.to_f).abs <= d.to_f); end
33
- def self.assert_nothing_thrown(&block); assert(begin; yield; true; rescue; false;end); end
34
- def self.assert_nothing_raised(&block); assert(begin; yield;true; rescue; false;end) end
35
- def self.finish!;puts "\n#{oz(@t)} tests, #{oz(@a)} assertions, #{oz(@f)} failures. #{(((oz(@t)-oz(@f)).to_f/@t.to_f)*100).to_i}% passing tests"; end
36
- def self.run(f);f.each{|t|puts "\nrunning tests from #{t}\n"; require t}; end
37
- end
38
-
1
+ class Huh
2
+ V = "2.0.0" unless defined?(V)
3
+ class Failure < StandardError; end
4
+ def self.test(name, &block)
5
+ @t = oz(@t) + 1
6
+ print begin; yield; "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n"; rescue Failure => e; "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n" ;end
7
+ end
8
+ def self.setup(&block); @setup = block; end
9
+ def self.teardown(&block); @teardown = block; end
10
+ def self.assert(truth)
11
+ @setup.call if @setup
12
+ !!truth ? (@a = oz(@a) + 1) : (@f = oz(@f) + 1; raise Failure)
13
+ @teardown.call if @teardown
14
+ end
15
+ def self.oz(v); v or 0; end
16
+ def self.flunk; assert(false); end
17
+ def self.assert_equal(e,a); assert(e == a); end
18
+ def self.assert_not_equal(e,a); assert(e != a); end
19
+ def self.assert_same(e,a); assert(e.equal?(a)); end
20
+ def self.assert_not_same(e,a); assert(!e.equal?(a)); end
21
+ def self.assert_nil(a); assert(a.nil?); end
22
+ def self.assert_not_nil(a); assert(!a.nil?); end
23
+ def self.assert_instance_of(k,o); assert(o.instance_of?(k)); end
24
+ def self.assert_kind_of(k,o); assert(o.kind_of?(k)); end
25
+ def self.assert_match(p,s); assert(p.match(s)); end
26
+ def self.assert_no_match(p,s); assert(!p.match(s)); end
27
+ def self.assert_respond_to(m,o); assert(o.respond_to?(m)); end
28
+ def self.assert_raises(&block); assert(begin; yield; rescue; true; end); end
29
+ def self.assert_block(&block); assert(begin;yield; rescue; false; end); end
30
+ def self.assert_operator(a,b,o);assert(a.send(o, b)); end
31
+ def self.assert_send(a); assert(a[0].send(a[1], *a[2..-1])); end
32
+ def self.assert_in_delta(e,a,d); assert((e.to_f - a.to_f).abs <= d.to_f); end
33
+ def self.assert_nothing_thrown(&block); assert(begin; yield; true; rescue; false;end); end
34
+ def self.assert_nothing_raised(&block); assert(begin; yield;true; rescue; false;end) end
35
+ def self.finish!;puts "\n#{oz(@t)} tests, #{oz(@a)} assertions, #{oz(@f)} failures. #{(((oz(@t)-oz(@f)).to_f/@t.to_f)*100).to_i}% passing tests"; end
36
+ def self.run(f);f.each{|t|puts "\nrunning tests from #{t}\n"; require File.expand_path(t)}; end
37
+ end
data/lib/huh_expanded.rb CHANGED
@@ -1,236 +1,236 @@
1
- # Huh is a small unit testing library
2
- # It supports many assertions commonly used, and has no external dependencies.
3
- #
4
- # Author:: Justin Baker (mailto:bakermoto@gmail.com)
5
- # Copyright:: Copyright (c) 2010 Justin Baker
6
- # License:: MIT license
7
-
8
- # This class creates a new test case. Your test classes should inherit from this class.
9
- #
10
- # Example
11
- # class MyTest < Huh
12
- # test "the truth" do
13
- # assert true
14
- # end
15
- # end
16
- #
17
- # You can do almost anything you do with Test::Unit included in the standard library, or MiniTest.
18
- # For all of the assertions, see README.md or examples/all_assertions for usage.
19
- #
20
- #
21
- class Huh
22
-
23
- VERSION = "1.0.8" unless defined?(VERSION) #:nodoc:
24
-
25
- # The error thrown from a failing test
26
- #
27
- class Failure < StandardError; end
28
-
29
- # The method used for creating a new test
30
- #
31
- # Example
32
- # class PostTest < Huh
33
- # test "create_new_post_and_save" do
34
- # assert Post.new.save
35
- # end
36
- # end
37
- #
38
- def self.test(name, &block)
39
- @tests = oz(@tests) + 1
40
- begin
41
- yield
42
- rescue Failure => e
43
- print "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n"
44
- else
45
- print "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n"
46
- end
47
- end
48
-
49
- # runs a block before every test
50
- #
51
- # Example
52
- # class PostTest < Huh
53
- # setup do
54
- # @post = Post.new
55
- # end
56
- # test "create_new_post_and_save" do
57
- # assert @post.save
58
- # end
59
- # end
60
- #
61
- def self.setup(&block)
62
- @setup = block
63
- end
64
-
65
- # runs a block after every test
66
- #
67
- # Example
68
- # class PostTest < Huh
69
- # teardown do
70
- # @post = nil
71
- # end
72
- # test "create_new_post_and_save" do
73
- # @post = Post.new
74
- # assert @post.save
75
- # end
76
- # end
77
- #
78
- def self.teardown(&block)
79
- @teardown = block
80
- end
81
-
82
- # validates that a condition is true
83
- #
84
- # Example
85
- # class PostTest < Huh
86
- # test "create_new_post_and_save" do
87
- # @post = Post.new
88
- # assert @post.save
89
- # end
90
- # end
91
- #
92
- def self.assert(truth)
93
- @setup.call if @setup
94
- !!truth ? (@assertions = oz(@assertions) + 1) : (@failures = oz(@failures) + 1; raise Failure)
95
- @teardown.call if @teardown
96
- end
97
-
98
- # return value if it isn't zero
99
- #
100
- def self.oz(value)
101
- value or 0
102
- end
103
-
104
- # assertion that ALWAYS fails
105
- #
106
- def self.flunk
107
- assert false
108
- end
109
-
110
- # validate that actual == expected
111
- #
112
- def self.assert_equal(expected, actual)
113
- assert expected == actual
114
- end
115
-
116
- # validate that actual != expected
117
- #
118
- def self.assert_not_equal(expected, actual)
119
- assert expected != actual
120
- end
121
-
122
- # validate that expected.equal?(actual)
123
- #
124
- def self.assert_same(expected, actual)
125
- assert expected.equal?(actual)
126
- end
127
-
128
- # validate that !expected.equal?(actual)
129
- #
130
- def self.assert_not_same(expected, actual)
131
- assert !expected.equal?(actual)
132
- end
133
-
134
- # validate that value.nil?
135
- #
136
- def self.assert_nil(value)
137
- assert value.nil?
138
- end
139
-
140
- # validate that !value.nil?
141
- #
142
- def self.assert_not_nil(value)
143
- assert !value.nil?
144
- end
145
-
146
- # validate that object.instance_of?(type)
147
- #
148
- def self.assert_instance_of(type, object)
149
- assert object.instance_of?(type)
150
- end
151
-
152
- # validate that object.kind_of?(type)
153
- #
154
- def self.assert_kind_of(kind, object)
155
- assert object.kind_of?(kind)
156
- end
157
-
158
- # validate that pattern.match(string)
159
- #
160
- def self.assert_match(pattern, string)
161
- assert pattern.match(string)
162
- end
163
-
164
- # validate that !pattern.match(string)
165
- #
166
- def self.assert_no_match(pattern, string)
167
- assert !pattern.match(string)
168
- end
169
-
170
- # validate that object.respond_to?(meth)
171
- #
172
- def self.assert_respond_to(meth, object)
173
- assert object.respond_to?(meth)
174
- end
175
-
176
- # validate that the block raises an error
177
- #
178
- def self.assert_raises(&block)
179
- assert(begin; yield; rescue; true; end)
180
- end
181
-
182
- # validate that the block returns true
183
- #
184
- def self.assert_block(&block)
185
- assert(begin;yield; rescue; false; end)
186
- end
187
-
188
- # validate that the block returns true when operator is called on it with value
189
- #
190
- def self.assert_operator(object, value,operator)
191
- assert object.send(operator, value)
192
- end
193
-
194
- # validate that send_array[0] returns true when send_array[1] is called on it with the rest of send_array as args
195
- #
196
- def self.assert_send(send_array)
197
- assert send_array[0].send(send_array[1], *send_array[2..-1])
198
- end
199
-
200
- # validate that actual is less than delta away from expected
201
- #
202
- def self.assert_in_delta(expected, actual, delta)
203
- assert (expected.to_f - actual.to_f).abs <= delta.to_f
204
- end
205
-
206
- # validate that nothing is thrown by the block
207
- #
208
- def self.assert_nothing_thrown(&block)
209
- assert(begin; yield; true; rescue; false;end)
210
- end
211
-
212
- # validate that no errors are raised by the block
213
- #
214
- def self.assert_nothing_raised(&block)
215
- assert(begin; yield;true; rescue; false;end)
216
- end
217
-
218
- # print out statistics of test
219
- #
220
- def self.finish!
221
- percentage = ((( oz(@tests) - oz(@failures) ).to_f / @tests.to_f) * 100 ).to_i
222
- print "\n#{oz(@tests)} tests, #{oz(@assertions)} assertions, #{oz(@failures)} failures."
223
- print "#{percentage}% passing tests}\n"
224
- end
225
-
226
- # use in irb/rails console to run tests
227
- #
228
- def self.run(files)
229
- puts "\nrunning tests from #{t}\n"
230
- files.each do |file|
231
- require file
232
- end
233
- end
234
-
235
- end
236
-
1
+ # Huh is a small unit testing library
2
+ # It supports many assertions commonly used, and has no external dependencies.
3
+ #
4
+ # Author:: Justin Baker (mailto:bakermoto@gmail.com)
5
+ # Copyright:: Copyright (c) 2010 Justin Baker
6
+ # License:: MIT license
7
+
8
+ # This class creates a new test case. Your test classes should inherit from this class.
9
+ #
10
+ # Example
11
+ # class MyTest < Huh
12
+ # test "the truth" do
13
+ # assert true
14
+ # end
15
+ # end
16
+ #
17
+ # You can do almost anything you do with Test::Unit included in the standard library, or MiniTest.
18
+ # For all of the assertions, see README.md or examples/all_assertions for usage.
19
+ #
20
+ #
21
+ class Huh
22
+
23
+ VERSION = "2.0.0" unless defined?(VERSION) #:nodoc:
24
+
25
+ # The error thrown from a failing test
26
+ #
27
+ class Failure < StandardError; end
28
+
29
+ # The method used for creating a new test
30
+ #
31
+ # Example
32
+ # class PostTest < Huh
33
+ # test "create_new_post_and_save" do
34
+ # assert Post.new.save
35
+ # end
36
+ # end
37
+ #
38
+ def self.test(name, &block)
39
+ @tests = oz(@tests) + 1
40
+ begin
41
+ yield
42
+ rescue Failure => e
43
+ print "Testing #{name} [\033[1;49;31mFAILED\033[0m]\n"
44
+ else
45
+ print "Testing #{name} [\033[1;49;32mPASSED\033[0m]\n"
46
+ end
47
+ end
48
+
49
+ # runs a block before every test
50
+ #
51
+ # Example
52
+ # class PostTest < Huh
53
+ # setup do
54
+ # @post = Post.new
55
+ # end
56
+ # test "create_new_post_and_save" do
57
+ # assert @post.save
58
+ # end
59
+ # end
60
+ #
61
+ def self.setup(&block)
62
+ @setup = block
63
+ end
64
+
65
+ # runs a block after every test
66
+ #
67
+ # Example
68
+ # class PostTest < Huh
69
+ # teardown do
70
+ # @post = nil
71
+ # end
72
+ # test "create_new_post_and_save" do
73
+ # @post = Post.new
74
+ # assert @post.save
75
+ # end
76
+ # end
77
+ #
78
+ def self.teardown(&block)
79
+ @teardown = block
80
+ end
81
+
82
+ # validates that a condition is true
83
+ #
84
+ # Example
85
+ # class PostTest < Huh
86
+ # test "create_new_post_and_save" do
87
+ # @post = Post.new
88
+ # assert @post.save
89
+ # end
90
+ # end
91
+ #
92
+ def self.assert(truth)
93
+ @setup.call if @setup
94
+ !!truth ? (@assertions = oz(@assertions) + 1) : (@failures = oz(@failures) + 1; raise Failure)
95
+ @teardown.call if @teardown
96
+ end
97
+
98
+ # return value if it isn't zero
99
+ #
100
+ def self.oz(value)
101
+ value or 0
102
+ end
103
+
104
+ # assertion that ALWAYS fails
105
+ #
106
+ def self.flunk
107
+ assert false
108
+ end
109
+
110
+ # validate that actual == expected
111
+ #
112
+ def self.assert_equal(expected, actual)
113
+ assert expected == actual
114
+ end
115
+
116
+ # validate that actual != expected
117
+ #
118
+ def self.assert_not_equal(expected, actual)
119
+ assert expected != actual
120
+ end
121
+
122
+ # validate that expected.equal?(actual)
123
+ #
124
+ def self.assert_same(expected, actual)
125
+ assert expected.equal?(actual)
126
+ end
127
+
128
+ # validate that !expected.equal?(actual)
129
+ #
130
+ def self.assert_not_same(expected, actual)
131
+ assert !expected.equal?(actual)
132
+ end
133
+
134
+ # validate that value.nil?
135
+ #
136
+ def self.assert_nil(value)
137
+ assert value.nil?
138
+ end
139
+
140
+ # validate that !value.nil?
141
+ #
142
+ def self.assert_not_nil(value)
143
+ assert !value.nil?
144
+ end
145
+
146
+ # validate that object.instance_of?(type)
147
+ #
148
+ def self.assert_instance_of(type, object)
149
+ assert object.instance_of?(type)
150
+ end
151
+
152
+ # validate that object.kind_of?(type)
153
+ #
154
+ def self.assert_kind_of(kind, object)
155
+ assert object.kind_of?(kind)
156
+ end
157
+
158
+ # validate that pattern.match(string)
159
+ #
160
+ def self.assert_match(pattern, string)
161
+ assert pattern.match(string)
162
+ end
163
+
164
+ # validate that !pattern.match(string)
165
+ #
166
+ def self.assert_no_match(pattern, string)
167
+ assert !pattern.match(string)
168
+ end
169
+
170
+ # validate that object.respond_to?(meth)
171
+ #
172
+ def self.assert_respond_to(meth, object)
173
+ assert object.respond_to?(meth)
174
+ end
175
+
176
+ # validate that the block raises an error
177
+ #
178
+ def self.assert_raises(&block)
179
+ assert(begin; yield; rescue; true; end)
180
+ end
181
+
182
+ # validate that the block returns true
183
+ #
184
+ def self.assert_block(&block)
185
+ assert(begin;yield; rescue; false; end)
186
+ end
187
+
188
+ # validate that the block returns true when operator is called on it with value
189
+ #
190
+ def self.assert_operator(object, value,operator)
191
+ assert object.send(operator, value)
192
+ end
193
+
194
+ # validate that send_array[0] returns true when send_array[1] is called on it with the rest of send_array as args
195
+ #
196
+ def self.assert_send(send_array)
197
+ assert send_array[0].send(send_array[1], *send_array[2..-1])
198
+ end
199
+
200
+ # validate that actual is less than delta away from expected
201
+ #
202
+ def self.assert_in_delta(expected, actual, delta)
203
+ assert (expected.to_f - actual.to_f).abs <= delta.to_f
204
+ end
205
+
206
+ # validate that nothing is thrown by the block
207
+ #
208
+ def self.assert_nothing_thrown(&block)
209
+ assert(begin; yield; true; rescue; false;end)
210
+ end
211
+
212
+ # validate that no errors are raised by the block
213
+ #
214
+ def self.assert_nothing_raised(&block)
215
+ assert(begin; yield;true; rescue; false;end)
216
+ end
217
+
218
+ # print out statistics of test
219
+ #
220
+ def self.finish!
221
+ percentage = ((( oz(@tests) - oz(@failures) ).to_f / @tests.to_f) * 100 ).to_i
222
+ print "\n#{oz(@tests)} tests, #{oz(@assertions)} assertions, #{oz(@failures)} failures."
223
+ print "#{percentage}% passing tests}\n"
224
+ end
225
+
226
+ # use in irb/rails console to run tests
227
+ #
228
+ def self.run(files)
229
+ puts "\nrunning tests from #{t}\n"
230
+ files.each do |file|
231
+ require file
232
+ end
233
+ end
234
+
235
+ end
236
+
metadata CHANGED
@@ -1,76 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: huh
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 8
10
- version: 1.0.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Justin Baker
14
- autorequire:
15
8
  bindir: bin
16
9
  cert_chain: []
17
-
18
- date: 2011-03-08 00:00:00 -05:00
19
- default_executable:
10
+ date: 1980-01-02 00:00:00.000000000 Z
20
11
  dependencies: []
21
-
22
12
  description: A tiny(<40 lines) library for unit testing
23
- email:
13
+ email:
24
14
  - bakermoto@gmail.com
25
15
  executables: []
26
-
27
16
  extensions: []
28
-
29
17
  extra_rdoc_files: []
30
-
31
- files:
32
- - lib/huh_expanded.rb
33
- - lib/huh/task.rb
34
- - lib/huh.rb
35
- - examples/basic.rb
36
- - examples/all_assertions.rb
18
+ files:
37
19
  - LICENSE
38
20
  - README.md
39
- has_rdoc: true
40
- homepage: http://github.com/justinbaker/huh
21
+ - examples/all_assertions.rb
22
+ - examples/basic.rb
23
+ - lib/huh.rb
24
+ - lib/huh/task.rb
25
+ - lib/huh_expanded.rb
26
+ homepage: https://github.com/slayyyyer/huh
41
27
  licenses: []
42
-
43
- post_install_message:
28
+ metadata: {}
44
29
  rdoc_options: []
45
-
46
- require_paths:
30
+ require_paths:
47
31
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
51
34
  - - ">="
52
- - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
- version: "0"
57
- required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
60
39
  - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 23
63
- segments:
64
- - 1
65
- - 3
66
- - 6
40
+ - !ruby/object:Gem::Version
67
41
  version: 1.3.6
68
42
  requirements: []
69
-
70
- rubyforge_project: huh
71
- rubygems_version: 1.6.0
72
- signing_key:
73
- specification_version: 3
43
+ rubygems_version: 4.0.20
44
+ specification_version: 4
74
45
  summary: 40 line ruby unit testing library
75
46
  test_files: []
76
-