micro_test 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/micro_test.rb +42 -30
  2. metadata +2 -2
data/lib/micro_test.rb CHANGED
@@ -1,54 +1,66 @@
1
- class MicroTest
2
- class << self
3
- def inherited(subclass)
4
- @subclasses ||= []
5
- @subclasses << subclass
1
+ module MicroTest
2
+ module Runner
3
+
4
+ def self.red(text)
5
+ "\e[31m#{text}\e[0m"
6
6
  end
7
7
 
8
- attr_accessor :passed, :failed
8
+ def self.green(text)
9
+ "\e[32m#{text}\e[0m"
10
+ end
9
11
 
10
- def reset
11
- @passed = 0
12
- @failed = 0
12
+ def self.test_classes
13
+ @test_classes ||= []
13
14
  end
14
15
 
15
- def tests
16
- @tests ||= {}
16
+ def self.log(value)
17
+ if value
18
+ puts " #{green :PASS} #{caller[1]}"
19
+ @passed += 1
20
+ else
21
+ puts " #{red :FAIL} #{caller[1]}"
22
+ @failed += 1
23
+ end
17
24
  end
18
25
 
19
- def run_tests
20
- reset
21
- @subclasses.each do |subclass|
22
- puts subclass.name
23
- subclass.tests.each do |desc, block|
24
- puts " Test #{desc}: "
26
+ def self.run
27
+ @passed = @failed = 0
28
+ test_classes.each do |test_class|
29
+ puts test_class.name
30
+ test_class.tests.each do |desc, block|
31
+ puts "- test #{desc}: "
25
32
  block.call
26
33
  end
27
34
  end
28
- puts "Passed Asserts: \e[32m#{MicroTest.passed}\e[0m, Failed Asserts: \e[31m#{MicroTest.failed}\e[0m"
35
+ puts "Passed Asserts: #{green @passed}, Failed Asserts: #{red @failed}"
29
36
  end
37
+ end
30
38
 
31
- def test(description, &block)
32
- tests[description] = block
39
+ class Test
40
+ def self.inherited(subclass)
41
+ MicroTest::Runner.test_classes << subclass
33
42
  end
34
43
 
35
- def assert(value)
36
- if value
37
- MicroTest.passed += 1
38
- puts " \e[32mPASS\e[0m: #{caller[0]}"
39
- else
40
- MicroTest.failed += 1
41
- puts " \e[31mFAIL\e[0m: #{caller[0]}"
42
- end
44
+ def self.tests
45
+ @tests ||= {}
46
+ end
47
+
48
+ def self.test(desc, &block)
49
+ tests[desc] = block
50
+ end
51
+
52
+ def self.assert(value)
53
+ MicroTest::Runner.log(value)
43
54
  end
44
55
  end
45
56
  end
46
57
 
47
- # class ExampleTest < MicroTest
58
+ # class ExampleTest < MicroTest::Test
48
59
  # test "booleans" do
49
60
  # assert true
61
+ # assert true
50
62
  # assert false
51
63
  # end
52
64
  # end
53
65
 
54
- # MicroTest.run_tests
66
+ # MicroTest::Runner.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! ' A testing "framework" in 45 lines.
14
+ description: ! ' A micro testing "framework".
15
15
 
16
16
  '
17
17
  email: