huh 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -12
- data/examples/basic.rb +11 -0
- data/examples/flunk.rb +11 -0
- data/examples/post_test.rb +32 -0
- data/lib/huh.rb +3 -8
- metadata +7 -4
data/README.md
CHANGED
@@ -6,26 +6,30 @@ A tiny(<30 lines) library for unit testing
|
|
6
6
|
Install
|
7
7
|
=========
|
8
8
|
|
9
|
-
|
9
|
+
sudo gem install huh
|
10
10
|
|
11
11
|
or from source
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
git clone git://github.com/justinbaker/huh.git
|
14
|
+
cd huh
|
15
|
+
rake
|
16
|
+
gem install huh-1.0.0.gem
|
17
17
|
|
18
18
|
Usage
|
19
19
|
=========
|
20
20
|
|
21
|
-
class PostTest < Huh
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
class PostTest < Huh
|
22
|
+
|
23
|
+
test "should_not_save" do
|
24
|
+
@post = Post.new
|
25
|
+
assert !@post.save
|
26
|
+
end
|
27
27
|
|
28
|
-
|
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.
|
29
33
|
|
30
34
|
Assertions
|
31
35
|
============
|
data/examples/basic.rb
ADDED
data/examples/flunk.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "huh"
|
2
|
+
|
3
|
+
class PostTest < Huh
|
4
|
+
|
5
|
+
test "post_should_not_save" do
|
6
|
+
@post = Post.new
|
7
|
+
assert !@post.save
|
8
|
+
end
|
9
|
+
|
10
|
+
test "post_should_not_save_without_title" do
|
11
|
+
@post = Post.new(:content = "Lorem blah blah..")
|
12
|
+
assert !@post.save
|
13
|
+
end
|
14
|
+
|
15
|
+
test "post_should_save" do
|
16
|
+
@post = Post.new(:content = "Lorem blah blah..", :title => "My First Post")
|
17
|
+
assert @post.save
|
18
|
+
end
|
19
|
+
|
20
|
+
test "post_should_be_published" do
|
21
|
+
@post = Post.first
|
22
|
+
assert @post.published?
|
23
|
+
end
|
24
|
+
|
25
|
+
test "post_should_not_be_published" do
|
26
|
+
@post = Post.last
|
27
|
+
assert @post.published?
|
28
|
+
end
|
29
|
+
|
30
|
+
finish!
|
31
|
+
|
32
|
+
end
|
data/lib/huh.rb
CHANGED
@@ -3,7 +3,7 @@ class Huh
|
|
3
3
|
class << self
|
4
4
|
attr_accessor :a, :t, :f
|
5
5
|
def test(name, &block)
|
6
|
-
@t= oz(@t)+1
|
6
|
+
@t= oz(@t) + 1
|
7
7
|
begin
|
8
8
|
yield
|
9
9
|
rescue Failure => e
|
@@ -13,18 +13,13 @@ class Huh
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
def assert(truth)
|
16
|
-
|
17
|
-
@f = oz(@f) + 1
|
18
|
-
raise Failure
|
19
|
-
else
|
20
|
-
@a = oz(@a)+1
|
21
|
-
end
|
16
|
+
!!truth ? (@a = oz(@a) + 1) : (@f = oz(@f) + 1; raise Failure)
|
22
17
|
end
|
23
18
|
def oz(v); v or 0; end # value or_zero
|
24
19
|
def flunk; assert(false); end # always fails
|
25
20
|
def assert_equal(a,b); assert(a == b); end # true == true..yes
|
26
21
|
def assert_nil(a); assert(a.nil?); end # true == true..yes
|
27
|
-
def finish!;puts "\n#{oz(@t)} tests, #{oz(@a)} assertions, #{oz(@f)} failures. #{(((@t
|
22
|
+
def 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 # spit out info
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
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-19 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -30,6 +30,9 @@ extra_rdoc_files: []
|
|
30
30
|
|
31
31
|
files:
|
32
32
|
- lib/huh.rb
|
33
|
+
- examples/flunk.rb
|
34
|
+
- examples/post_test.rb
|
35
|
+
- examples/basic.rb
|
33
36
|
- LICENSE
|
34
37
|
- README.md
|
35
38
|
has_rdoc: true
|