minitest_owrapper 0.0.1

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/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ == Overview
2
+
3
+ With ruby or macruby testunit or minitest, results are damnly tied to output and you can't get result of a test as an object after
4
+ its execution and global tests result as an object too.
5
+
6
+ This gem permit to do so, and, have result of a unit test as an TestResult object on which you can call methods
7
+ #success? #failures #errors #skips #current ...
8
+ You can be yielded this TestResult object after each test and the global TestResult after all tests.
9
+
10
+
11
+ Note : For now it just work with macruby interpreter and minitest or testunit tests.
12
+ It is really easy to evolve it for ruby interpreter.
13
+ It will be done soon.
14
+
15
+ == Installation
16
+
17
+ gem install minitest_owrapper
18
+
19
+
20
+ == Usage
21
+
22
+ Suppose :
23
+ - @test_file is the absolute path to your test file.
24
+ - load_path is the load path needed for your path (-I option)
25
+
26
+ Just do :
27
+
28
+ result = MinitestOwrapper.run(@test_file, load_path) do |test_result|
29
+ puts test_result.current
30
+ end
31
+
32
+ And, you will get a test_result after each test, ie an object of class Failure, Error, Skip or Success.
33
+ These objects respond to methods :klass, :method, :line, :message.
34
+
35
+ The final result will respond to
36
+ :errors => array of errors
37
+ :failures => array of failures
38
+ :skips => array of skips
39
+ :successes => array of success
40
+ :tests => number of tests
41
+ :duration => duration of the tests
42
+ :assertions => number of assertions
43
+
44
+ Example of usage in the test file test/test_minitest_owrapper.rb
45
+
46
+ it 'should run FakeTest and get TestResult object whith 2 failure, 1 error, 1 success, 1 skip ' do
47
+ load_path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures'))
48
+
49
+ result = MinitestOwrapper.run(@test_file, load_path) do |test_result|
50
+ puts test_result.current
51
+ end
52
+
53
+ assert_equal 1, result.errors.count
54
+ assert_equal 2, result.failures.count
55
+ assert_equal 1, result.skips.count
56
+ assert_equal 1, result.successes.count
57
+
58
+ assert_equal 5, result.tests
59
+ assert_in_delta result.duration, 1, 1
60
+ assert_equal 4, result.assertions
61
+ end
62
+
63
+
64
+ == Dependencies
65
+
66
+ minitest
67
+
68
+ == TO-DOs
69
+
70
+ Adapt to work with ruby interpreter.
71
+
72
+
73
+ == Licence
74
+
75
+ MIT Licence
@@ -0,0 +1,93 @@
1
+ module MinitestOwrapper
2
+
3
+ class AssertionStatus
4
+ attr_accessor :klass, :method, :line, :message
5
+
6
+ def initialize args={}
7
+ @klass = args[:klass]
8
+ @method = args[:method]
9
+ @line = args[:line]
10
+ @message = args[:message]
11
+ end
12
+
13
+ end
14
+
15
+ class Failure < AssertionStatus
16
+ end
17
+
18
+ class Error < AssertionStatus
19
+ end
20
+
21
+ class Skip < AssertionStatus
22
+ end
23
+
24
+ class Success < AssertionStatus
25
+ end
26
+
27
+ class TestResult
28
+
29
+ attr_reader :skips, :failures, :errors, :successes
30
+ attr_accessor :assertions
31
+
32
+ def initialize
33
+ @skips = []
34
+ @failures = []
35
+ @errors = []
36
+ @successes = []
37
+ @time = 0
38
+ @assertions = 0
39
+ end
40
+
41
+ def current
42
+ case
43
+ when @skip then @skips.last
44
+ when @fail then @failures.last
45
+ when @error then @errors.last
46
+ else Success.new
47
+ end
48
+ end
49
+
50
+ def start
51
+ @start = Time.now
52
+ end
53
+
54
+ def stop
55
+ @time = Time.now - @start
56
+ end
57
+
58
+ def success?
59
+ not (@skip || @fail || @error)
60
+ end
61
+
62
+ def reset
63
+ @successes << Success.new if success?
64
+ @skip = @fail = @error = false
65
+ end
66
+
67
+ def tests
68
+ [skips, failures, errors, successes].inject(0){|total, assertions| total += assertions.count }
69
+ end
70
+
71
+ def duration
72
+ @time
73
+ end
74
+
75
+ def puke klass, method, e
76
+ line = MiniTest::Unit.new.location(e)
77
+ case e
78
+ when MiniTest::Skip then
79
+ @skips << Skip.new(:klass => klass, :method => method, :line => line, :message => e.message)
80
+ @skip = true
81
+ when MiniTest::Assertion then
82
+ @failures << Failure.new(:klass => klass, :method => method, :line => line, :message => e.message)
83
+ @fail = true
84
+ else
85
+ bt = MiniTest::filter_backtrace(e.backtrace).join("\n ")
86
+ message = "#{e.class}: #{e.message}\n #{bt}"
87
+ @errors << Error.new(:klass => klass, :method => method, :line => line, :message => e.message)
88
+ @error = true
89
+ end
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,32 @@
1
+ require 'macruby_test_result'
2
+
3
+ module MinitestOwrapper
4
+
5
+ def self.run test_file, load_path='', &block
6
+ load_path.split(":").each{ |path| $: << path }
7
+ code = File.new(test_file).read
8
+ test_result = TestResult.new
9
+
10
+ injection = %q{
11
+ test_result.start
12
+ klass = self.const_get(test_klass_name(code))
13
+ klass.instance_methods.grep(/^test_/).each do |method|
14
+ runner = klass.new(method)
15
+ runner.run(test_result)
16
+ block.call(test_result) if block
17
+ test_result.assertions += runner._assertions
18
+ test_result.reset
19
+ end
20
+ test_result.stop
21
+ test_result
22
+ }
23
+ eval(code + injection)
24
+ end
25
+
26
+ def self.test_klass_name content
27
+ content.match /class\s*(.*?)\s*</
28
+ $1
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,3 @@
1
+ module MinitestOwrapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+ # Tested with macruby => eval() is macruby eval()
2
+ # So TestResult implements macruby minitest test result interface (#puke)
3
+ # ENV['RUBY'] = 'MACRUBY'
4
+ # ENV['MACRUBY_TESTING'] = '1'
5
+
6
+ require "minitest/autorun"
7
+ require 'minitest_owrapper'
8
+
9
+ class TestMinitestOwrapper < MiniTest::Unit::TestCase
10
+
11
+ describe MinitestOwrapper do
12
+
13
+ before do
14
+ @test_file = File.join(File.dirname(__FILE__), '../fixtures/fake_test.rb')
15
+ end
16
+
17
+ it 'should get klass name of test from file content' do
18
+ code = File.new(@test_file).read
19
+ klass_name = MinitestOwrapper.test_klass_name(code)
20
+
21
+ assert_equal 'FakeTest', klass_name
22
+ end
23
+
24
+ it 'should run FakeTest and get TestResult object whith 2 failure, 1 error, 1 success, 1 skip ' do
25
+ load_path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures'))
26
+
27
+ result = MinitestOwrapper.run(@test_file, load_path) do |test_result|
28
+ puts test_result.current
29
+ end
30
+
31
+ assert_equal 1, result.errors.count
32
+ assert_equal 2, result.failures.count
33
+ assert_equal 1, result.skips.count
34
+ assert_equal 1, result.successes.count
35
+
36
+ assert_equal 5, result.tests
37
+ assert_in_delta result.duration, 1, 1
38
+ assert_equal 4, result.assertions
39
+ end
40
+
41
+ end
42
+
43
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest_owrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Philippe Cantin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-09 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: minitest
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: " With ruby or macruby test unit or minitest, results are damnly tied to output and you can't get result\n of a test as an object after its execution and global tests result as an object too.\n This gem permit to do so, and, have result of a unit test (with minitest testunit and macruby for now but can easily be evolved\n with ruby. See usage on github repository)\n "
36
+ email:
37
+ - anoiaque@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ files:
45
+ - lib/macruby_test_result.rb
46
+ - lib/minitest_owrapper/version.rb
47
+ - lib/minitest_owrapper.rb
48
+ - README.rdoc
49
+ - test/test_minitest_owrapper.rb
50
+ has_rdoc: true
51
+ homepage: https://github.com/anoiaque/minitest_owrapper
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: minitest_owrapper
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Get tests results as a TestResult object instead tied to output
84
+ test_files:
85
+ - test/test_minitest_owrapper.rb