micro_test 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/README.md +60 -38
- data/bin/mt +30 -14
- data/lib/{micro_test/formatter.rb → formatters/default.rb} +12 -5
- data/lib/micro_test/runner.rb +11 -12
- metadata +41 -8
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -1,40 +1,77 @@
|
|
1
1
|
# MicroTest
|
2
2
|
|
3
|
-
|
3
|
+
## Ruby's no-nonsense testing framework
|
4
4
|
|
5
|
-
|
6
|
-
MiniTest is a step in the right direction, but still feels bigger than it should.
|
5
|
+
[View the product page for prettier docs.](http://hopsoft.github.com/micro_test/)
|
7
6
|
|
8
|
-
|
7
|
+
Testing frameworks often lose their focus and become an end unto themselves.
|
8
|
+
MicroTest avoids this pitfall with a relentless focus on simplicity.
|
9
9
|
|
10
|
-
|
10
|
+
### Testing should be simple
|
11
11
|
|
12
|
-
|
13
|
-
* __Only one assert method: `assert`__ - _since this is the heart of testing_
|
14
|
-
* __Tests run in random order__ - _to prevent the bad practice of run order depenencies_
|
15
|
-
* __Plays nice with others__ - _easy to introduce to an existing codebase_
|
12
|
+
Here's what MicroTest brings to the table.
|
16
13
|
|
17
|
-
|
14
|
+
* __Simplicity__
|
15
|
+
A tiny API with only 4 methods. You'll be up and running faster than ever before.
|
16
|
+
* __Only 1 Assert Method__
|
17
|
+
Forget the copious expections and assert methods from other frameworks and start focusing on what really matters.
|
18
|
+
* __Small Footprint__
|
19
|
+
Weighs in around 140 lines of code. Less code means less to learn and less that can go wrong.
|
20
|
+
* __Plays Nice__
|
21
|
+
Runs side by side with other test frameworks which makes it easy to integrate into existing projects.
|
22
|
+
* __Random Run Order__
|
23
|
+
Prevents the bad practice of run order dependencies by running tests in random order.
|
24
|
+
* __Customizable
|
25
|
+
Output__ Customize test output with pluggable formatters, or give back by writing your own.
|
26
|
+
|
27
|
+
## Quick Start
|
28
|
+
|
29
|
+
1. Install
|
18
30
|
|
19
31
|
```bash
|
20
|
-
gem install micro_test
|
32
|
+
$ gem install micro_test
|
33
|
+
```
|
34
|
+
|
35
|
+
2. Write a test
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'micro_test'
|
39
|
+
class MyTest < MicroTest::Test
|
40
|
+
test "some assumption" do
|
41
|
+
assert true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
3. Run tests
|
47
|
+
|
48
|
+
```bash
|
49
|
+
$ mt
|
21
50
|
```
|
22
51
|
|
23
|
-
##
|
52
|
+
## The interface
|
24
53
|
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
* Assert statements with `assert [statement]`
|
30
|
-
* Run tests from the terminal with `$ mt`
|
31
|
-
* Run tests from Ruby with `MicroTest::Runner.run`
|
54
|
+
* `MicroTest::Test` Superclass for all tests.
|
55
|
+
* `test(desc, &block)` Defines a test method.
|
56
|
+
* `desc` - a description of what is being tested
|
57
|
+
* `&block` - a block of code which defines the test
|
32
58
|
|
33
|
-
|
59
|
+
* `assert(value)` Verifies the truthiness of a value.
|
60
|
+
* `value` - the value to assert
|
34
61
|
|
35
|
-
|
62
|
+
* `before(what, &block)` A callback that runs before the specified 'what'.
|
63
|
+
* `what` - indicates the callback type
|
64
|
+
* `:all` - runs before all tests in the class
|
65
|
+
* `:each` - runse before each test in the class
|
66
|
+
* `&block` - the block of code to execute
|
36
67
|
|
37
|
-
|
68
|
+
* `after(what, &block)` A callback that runs after the specified 'what'.
|
69
|
+
* `what` - indicates the callback type
|
70
|
+
* `:all` - runs after all tests in the class
|
71
|
+
* `:each` - runse after each test in the class
|
72
|
+
* `&block` - the block of code to execute
|
73
|
+
|
74
|
+
## Example
|
38
75
|
|
39
76
|
```ruby
|
40
77
|
# /example/test/math_test.rb
|
@@ -80,24 +117,9 @@ class MathTest < MicroTest::Test
|
|
80
117
|
end
|
81
118
|
```
|
82
119
|
|
83
|
-
Run
|
120
|
+
Run tests.
|
84
121
|
|
85
122
|
```bash
|
86
123
|
$ mt
|
87
|
-
```
|
88
|
-
|
89
|
-
Run all tests in a directory.
|
90
|
-
|
91
|
-
```bash
|
92
124
|
$ mt /example/test
|
93
|
-
```
|
94
|
-
|
95
|
-
Run all tests in a file.
|
96
|
-
|
97
|
-
```bash
|
98
125
|
$ mt /example/test/math_test.rb
|
99
|
-
```
|
100
|
-
|
101
|
-
Test output.
|
102
|
-
|
103
|
-
![MicroTest output](http://hopsoft.github.com/micro_test/images/micro_test.png)
|
data/bin/mt
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require "slop"
|
3
|
+
require "pry"
|
3
4
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "micro_test"))
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts "Usage:"
|
11
|
-
puts " $mt /path/to/test_file_or_dir"
|
12
|
-
exit
|
6
|
+
opts = Slop.parse(:strict => true, :help => true) do
|
7
|
+
banner "mt [options]"
|
8
|
+
on :p, :path, "The path to the test directory or file.", :argument => true
|
9
|
+
on :f, :formatter, "The name of the formatter to use.", :argument => true
|
10
|
+
on :pry, "Starts a pry session when tests fail or have errors."
|
13
11
|
end
|
14
12
|
|
13
|
+
exit if opts[:help]
|
14
|
+
|
15
|
+
path = opts[:path] || "test"
|
15
16
|
path = File.join(Dir.pwd, path) unless path =~ /^\//
|
16
17
|
unless File.exist?(path)
|
17
18
|
puts "#{path} not found."
|
18
19
|
puts "Please check the path and try again."
|
19
20
|
exit
|
20
21
|
end
|
21
|
-
|
22
|
-
if File.directory?(path)
|
23
|
-
Dir[File.join(path, "**", "*.rb")].each { |p| require p }
|
24
|
-
else
|
22
|
+
if path =~ /\.rb$/
|
25
23
|
require path
|
24
|
+
else
|
25
|
+
Dir[File.join(path, "**", "*.rb")].each { |p| require p }
|
26
|
+
end
|
27
|
+
|
28
|
+
formatter_name = opts[:formatter] || "default"
|
29
|
+
formatter_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "formatters", formatter_name + ".rb"))
|
30
|
+
unless File.exist?(formatter_path)
|
31
|
+
puts "#{formatter_path} not found."
|
32
|
+
puts "Please check the formatter name and try again."
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
begin
|
36
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "formatters", formatter_name))
|
37
|
+
formatter = MicroTest.const_get("Formatter").new
|
38
|
+
rescue Exception => ex
|
39
|
+
puts "Failed to load the formatter."
|
40
|
+
puts ex.message
|
41
|
+
exit
|
26
42
|
end
|
27
43
|
|
28
|
-
MicroTest::Runner.run
|
44
|
+
MicroTest::Runner.run formatter, :pry => !!opts[:pry]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module MicroTest
|
2
2
|
class Formatter
|
3
|
+
|
3
4
|
def initialize
|
4
5
|
@total = 0
|
5
6
|
@passed = 0
|
@@ -18,13 +19,19 @@ module MicroTest
|
|
18
19
|
@total += 1
|
19
20
|
info[:passed] ? @passed += 1 : @failed += 1
|
20
21
|
print "- #{info[:name]} "
|
21
|
-
info[:
|
22
|
-
|
23
|
-
|
22
|
+
if info[:passed]
|
23
|
+
puts green(:PASS)
|
24
|
+
else
|
25
|
+
if info[:error]
|
26
|
+
puts "#{red :ERROR} #{red info[:error].message}"
|
27
|
+
puts " #{red info[:error].backtrace[0]}"
|
24
28
|
else
|
25
29
|
puts red(:FAIL)
|
26
|
-
|
27
|
-
|
30
|
+
info[:asserts].each do |assert|
|
31
|
+
next if assert[:passed]
|
32
|
+
puts " #{red assert[:line]}"
|
33
|
+
puts " #{red assert[:path]}:#{yellow assert[:line_num]}"
|
34
|
+
end
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
data/lib/micro_test/runner.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "formatter"))
|
2
|
-
|
3
1
|
module MicroTest
|
4
2
|
module Runner
|
5
3
|
class << self
|
@@ -8,10 +6,6 @@ module MicroTest
|
|
8
6
|
send event, arg
|
9
7
|
end
|
10
8
|
|
11
|
-
def formatter
|
12
|
-
@formatter ||= MicroTest::Formatter.new
|
13
|
-
end
|
14
|
-
|
15
9
|
def add_test_class(klass)
|
16
10
|
test_classes << klass
|
17
11
|
end
|
@@ -22,7 +16,7 @@ module MicroTest
|
|
22
16
|
|
23
17
|
def file(path)
|
24
18
|
@files ||= {}
|
25
|
-
@files[path] ||= File.
|
19
|
+
@files[path] ||= File.read(path).split("\n")
|
26
20
|
end
|
27
21
|
|
28
22
|
def file_info(callstack_entry)
|
@@ -40,11 +34,10 @@ module MicroTest
|
|
40
34
|
|
41
35
|
def assert(value)
|
42
36
|
@failed ||= !value
|
43
|
-
@asserts << file_info(caller[6]).merge(:
|
37
|
+
@asserts << file_info(caller[6]).merge(:passed => value)
|
44
38
|
end
|
45
39
|
|
46
|
-
def run(
|
47
|
-
@formatter = f
|
40
|
+
def run(formatter, opts={})
|
48
41
|
formatter.header
|
49
42
|
|
50
43
|
test_classes.shuffle.each do |test_class|
|
@@ -55,8 +48,14 @@ module MicroTest
|
|
55
48
|
@failed = false
|
56
49
|
@asserts = []
|
57
50
|
test_class.invoke :before, :each
|
58
|
-
|
59
|
-
|
51
|
+
begin
|
52
|
+
test_class.tests[desc].call
|
53
|
+
rescue Exception => e
|
54
|
+
@failed = true
|
55
|
+
error = e
|
56
|
+
end
|
57
|
+
test_class.tests[desc].pry if @failed && opts[:pry]
|
58
|
+
formatter.test :name => desc, :passed => !@failed, :asserts => @asserts, :error => error
|
60
59
|
test_class.invoke :after, :each
|
61
60
|
end
|
62
61
|
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,42 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: slop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! " Testing frameworks often lose their focus and become an end unto
|
47
|
+
themselves.\n MicroTest avoids this pitfall with a relentless focus on simplicity.\n"
|
17
48
|
email:
|
18
49
|
- natehop@gmail.com
|
19
50
|
executables:
|
@@ -21,11 +52,13 @@ executables:
|
|
21
52
|
extensions: []
|
22
53
|
extra_rdoc_files: []
|
23
54
|
files:
|
24
|
-
- lib/
|
55
|
+
- lib/formatters/default.rb
|
25
56
|
- lib/micro_test/runner.rb
|
26
57
|
- lib/micro_test/test.rb
|
27
58
|
- lib/micro_test.rb
|
28
59
|
- bin/mt
|
60
|
+
- Gemfile
|
61
|
+
- Gemfile.lock
|
29
62
|
- README.md
|
30
63
|
homepage: http://hopsoft.github.com/micro_test/
|
31
64
|
licenses:
|
@@ -51,5 +84,5 @@ rubyforge_project:
|
|
51
84
|
rubygems_version: 1.8.24
|
52
85
|
signing_key:
|
53
86
|
specification_version: 3
|
54
|
-
summary:
|
87
|
+
summary: Ruby's no-nonsense testing framework.
|
55
88
|
test_files: []
|