aki-testrocket 0.0.2 → 0.0.3
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.
- data/.travis.yml +1 -6
- data/Gemfile +4 -0
- data/README.md +53 -14
- data/lib/testrocket.rb +10 -5
- data/lib/testrocket/launcher.rb +19 -0
- data/lib/testrocket/version.rb +1 -1
- data/test/helper.rb +2 -1
- data/test/test_testrocket.rb +47 -0
- data/testrocket.gemspec +1 -0
- metadata +2 -2
- data/Gemfile.travis +0 -6
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,23 +6,26 @@
|
|
6
6
|
|
7
7
|
Testrocket is a super simple (as simple as it gets really) testing library for Ruby.
|
8
8
|
|
9
|
-
It was initially developed for [this CodeBrawl competition](http://codebrawl.com/articles/contest-rundown-ruby-testing-libraries) and it won! People then asked me to release it 'for real' so here we are.
|
9
|
+
It was initially developed for [this CodeBrawl competition](http://codebrawl.com/articles/contest-rundown-ruby-testing-libraries) and it won! People then asked me to release it 'for real' so here we are. | _peterc_
|
10
10
|
|
11
|
-
|
11
|
+
## Install
|
12
12
|
|
13
|
-
|
13
|
+
**Notice** This is a forked version of the origin [testrocket](https://github.com/peterc/testrocket) gem!
|
14
|
+
|
15
|
+
You have to install this fork by: `gem install aki-testrocket`
|
16
|
+
|
17
|
+
In Gemfile: `gem "aki-testrocket"`
|
14
18
|
|
15
19
|
As yet there are no useful bits and pieces for creating test files (look at the example, it's easy!) or Rake tasks. But it's all crazy simple. A few things may be added later on.
|
16
20
|
|
17
|
-
Dependencies
|
18
|
-
------------
|
21
|
+
## Dependencies
|
19
22
|
|
20
23
|
- Ruby 1.9
|
21
24
|
- minitest/spec (part of MRI 1.9 stdlib)
|
22
25
|
- Unix/Unix-like/POSIX system
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
|
28
|
+
## Example
|
26
29
|
|
27
30
|
require 'testrocket'
|
28
31
|
|
@@ -43,12 +46,49 @@ Example
|
|
43
46
|
|
44
47
|
# A 'pending' test
|
45
48
|
~-> { "this is a pending test" }
|
46
|
-
|
49
|
+
|
47
50
|
# A description
|
48
51
|
!-> { "use this for descriptive output and to separate your test parts" }
|
49
52
|
|
50
|
-
|
51
|
-
|
53
|
+
## Launcher Extension
|
54
|
+
|
55
|
+
require 'testrocket'
|
56
|
+
require 'testrocket/launcher' # <-- has to be added manually!
|
57
|
+
|
58
|
+
launcher "my bigger test suite" do
|
59
|
+
fire "first test part" do
|
60
|
+
+-> { true }
|
61
|
+
--> { false }
|
62
|
+
end
|
63
|
+
fire "second test part" do
|
64
|
+
+-> { true }
|
65
|
+
--> { false }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
OUTPUT will be:
|
70
|
+
|
71
|
+
LAUNCHING 'my bigger test suite'
|
72
|
+
FIRE 'first test part'!
|
73
|
+
OK
|
74
|
+
OK
|
75
|
+
/FIRED
|
76
|
+
FIRE 'second test part'!
|
77
|
+
OK
|
78
|
+
OK
|
79
|
+
/FIRED
|
80
|
+
HIT 4 of 4 TARGET(S) AND MISSED 0, LOST 0 ROCKET(S)
|
81
|
+
=> "HIT 4 of 4 TARGET(S) AND MISSED 0, LOST 0 ROCKET(S)"
|
82
|
+
|
83
|
+
_launcher_ = something like "describe" in other test suites
|
84
|
+
|
85
|
+
The _launcher_ also collects test counts, the positive/negative hits and "lost rockets" (= pending).
|
86
|
+
|
87
|
+
_fire_ = something like "it" in other test suites
|
88
|
+
|
89
|
+
The _fire_ blocks utilize the _description rocket_, so you don't have to do it in an extra step, it also adds a closing output line for each fire-block.
|
90
|
+
|
91
|
+
## Other Features
|
52
92
|
|
53
93
|
By default, output is written to STDOUT (as well as returned by the test expressions themselves). You can override where test output goes like so:
|
54
94
|
|
@@ -56,9 +96,8 @@ By default, output is written to STDOUT (as well as returned by the test express
|
|
56
96
|
|
57
97
|
TestRocket.out also supports Logger instances.
|
58
98
|
|
59
|
-
Authors
|
60
|
-
-------
|
99
|
+
## Authors
|
61
100
|
|
62
|
-
Initial concept and maintenance by Peter Cooper
|
101
|
+
Initial concept and maintenance by [Peter Cooper](https://github.com/asaaki).
|
63
102
|
|
64
|
-
Extra concepts and code by Christoph Grabo
|
103
|
+
Extra concepts and code by [Christoph Grabo](https://github.com/peterc).
|
data/lib/testrocket.rb
CHANGED
@@ -4,16 +4,21 @@ module TestRocket
|
|
4
4
|
def _test(a, b)
|
5
5
|
send((call rescue()) ? a : b)
|
6
6
|
end
|
7
|
+
|
8
|
+
def launched?
|
9
|
+
!!($launched rescue())
|
10
|
+
end
|
7
11
|
|
8
12
|
def +@; r = _test :_pass, :_fail; (TestRocket.out || $>) << r; r end
|
9
13
|
def -@; r = _test :_fail, :_pass; (TestRocket.out || $>) << r; r end
|
10
14
|
def ~@; r = _pend; (TestRocket.out || $>) << r; r end
|
11
15
|
def !@; r = _desc; (TestRocket.out || $>) << r; r end
|
12
16
|
|
13
|
-
def _pass; "
|
14
|
-
def _fail; "
|
15
|
-
def _pend; "PENDING '#{call.to_s}' @ #{source_location.join(':')}\n"; end
|
16
|
-
def _desc;
|
17
|
-
end
|
17
|
+
def _pass; ($targets += 1; $hits += 1) if launched?; " OK\n"; end
|
18
|
+
def _fail; ($targets += 1) if launched?; " FAIL @ #{source_location.join(':')}\n"; end
|
19
|
+
def _pend; ($targets += 1; $lost += 1) if launched?; " PENDING '#{call.to_s}' @ #{source_location.join(':')}\n"; end
|
20
|
+
def _desc; " FIRE '#{call.to_s}'!\n"; end
|
18
21
|
|
22
|
+
end
|
19
23
|
Proc.send :include, TestRocket
|
24
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module TestRocketLauncher
|
2
|
+
def fire(d,&b)
|
3
|
+
!->{ d.to_s }
|
4
|
+
b.call
|
5
|
+
r = " /FIRED"
|
6
|
+
(TestRocket.out || $>).puts r; r
|
7
|
+
end
|
8
|
+
def launcher(d,&b)
|
9
|
+
$targets = 0; $hits = 0; $lost = 0
|
10
|
+
(TestRocket.out || $>).puts "LAUNCHING '#{d}'"
|
11
|
+
$launched = true
|
12
|
+
b.call
|
13
|
+
$launched = false
|
14
|
+
r = "HIT #{$hits} of #{$targets} TARGET(S) AND MISSED #{$targets-$lost-$hits}, LOST #{$lost} ROCKET(S)"
|
15
|
+
(TestRocket.out || $>).puts r; r
|
16
|
+
end
|
17
|
+
end
|
18
|
+
self.send :include, TestRocketLauncher
|
19
|
+
|
data/lib/testrocket/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_testrocket.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe TestRocket do
|
4
|
+
|
4
5
|
it "should find emptiness non-truthful by default" do
|
5
6
|
(+->{}).must_match(/FAIL/)
|
6
7
|
end
|
@@ -30,4 +31,50 @@ describe TestRocket do
|
|
30
31
|
(!->{ "a description" }).must_match(/FIRE/)
|
31
32
|
(!->{ "a description" }).must_match(/a description/)
|
32
33
|
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe TestRocketLauncher do
|
38
|
+
|
39
|
+
it "should parse a whole 'fire block'" do
|
40
|
+
(fire "my test suite" do
|
41
|
+
+-> { 1 + 2 == 3 }
|
42
|
+
--> { 1 - 2 == 3 }
|
43
|
+
end).must_match(/FIRED/)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should also work with nested fire blocks" do
|
47
|
+
(fire "my test suite" do
|
48
|
+
fire "my nested tests 1" do
|
49
|
+
+-> { 1 + 2 == 3 }
|
50
|
+
--> { 1 - 2 == 3 }
|
51
|
+
end
|
52
|
+
fire "my nested tests 2" do
|
53
|
+
+-> { 23 != 42 }
|
54
|
+
--> { 23 == 42 }
|
55
|
+
end
|
56
|
+
end).must_match(/\/FIRED/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should launch the rocket!" do
|
60
|
+
result = (launcher "my test suite" do
|
61
|
+
fire "my nested tests 1" do
|
62
|
+
fire "my nested test 1.1" do
|
63
|
+
+-> { 1 + 2 == 3 }
|
64
|
+
end
|
65
|
+
fire "my nested test 1.2" do
|
66
|
+
--> { 1 - 2 == 3 }
|
67
|
+
end
|
68
|
+
fire "my nested test 1.3" do
|
69
|
+
~-> { "not defined yet" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
fire "my nested tests 2" do
|
73
|
+
+-> { 23 != 42 }
|
74
|
+
--> { 23 == 42 }
|
75
|
+
--> { true }
|
76
|
+
end
|
77
|
+
end).must_match("HIT 4 of 6 TARGET(S) AND MISSED 1, LOST 1 ROCKET(S)")
|
78
|
+
end
|
79
|
+
|
33
80
|
end
|
data/testrocket.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aki-testrocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,12 +23,12 @@ files:
|
|
23
23
|
- .gitignore
|
24
24
|
- .travis.yml
|
25
25
|
- Gemfile
|
26
|
-
- Gemfile.travis
|
27
26
|
- HISTORY
|
28
27
|
- LICENSE
|
29
28
|
- README.md
|
30
29
|
- Rakefile
|
31
30
|
- lib/testrocket.rb
|
31
|
+
- lib/testrocket/launcher.rb
|
32
32
|
- lib/testrocket/version.rb
|
33
33
|
- test/helper.rb
|
34
34
|
- test/test_testrocket.rb
|