aki-testrocket 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,2 @@
1
- rvm:
2
- - 1.9.2
3
- gemfile: gemfiles/Gemfile.travis
4
- notifications:
5
- recipients:
6
- - chris@dinarrr.com
1
+ rvm: 1.9.2
7
2
 
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ group :test do
4
+ gem "rake"
5
+ end
6
+
3
7
  # Specify your gem's dependencies in testrocket.gemspec
4
8
  gemspec
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
- To install:
11
+ ## Install
12
12
 
13
- gem install testrocket
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
- Example
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
- Other Features
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).
@@ -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; " OK\n"; end
14
- def _fail; " FAIL @ #{source_location.join(':')}\n"; end
15
- def _pend; "PENDING '#{call.to_s}' @ #{source_location.join(':')}\n"; end
16
- def _desc; " FIRE '#{call.to_s}'!\n"; end
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
+
@@ -1,3 +1,3 @@
1
1
  module Testrocket
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'minitest/autorun'
2
2
  require 'testrocket'
3
+ require 'testrocket/launcher'
3
4
 
4
- TestRocket.out = File.new('/dev/null', 'w')
5
+ TestRocket.out = File.new('/dev/null', 'w')
@@ -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
@@ -19,3 +19,4 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
  end
22
+
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.2
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
@@ -1,6 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rake" # added for travis-ci.org
4
-
5
- # Specify your gem's dependencies in testrocket.gemspec
6
- gemspec