test_javalos 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/lib/failure.rb +35 -0
- data/lib/printer.rb +56 -0
- data/lib/test_javalos.rb +34 -0
- data/lib/test_javalos_runner.rb +71 -0
- metadata +48 -0
data/lib/failure.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Failure
|
2
|
+
attr_accessor :message
|
3
|
+
|
4
|
+
def self.assert_equals object_1, object_2
|
5
|
+
failure = Failure.new
|
6
|
+
failure.message = assert_equals_fail_message object_1, object_2
|
7
|
+
failure
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.assert_not_null
|
11
|
+
failure = Failure.new
|
12
|
+
failure.message = assert_not_null_fail_message
|
13
|
+
failure
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.assert_equals_fail_message object_1, object_2
|
22
|
+
"Assertion failed.\n" +
|
23
|
+
" Expected: <#{object_1.class.name}> #{object_1.nil? ? "nil" : object_1} \n" +
|
24
|
+
" Got: <#{object_2.class.name}> #{object_2.nil? ? "nil" : object_2} \n" +
|
25
|
+
"in: #{caller[3]}\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.assert_not_null_fail_message
|
29
|
+
"Assertion failed.\n" +
|
30
|
+
" Expected: Not nil \n" +
|
31
|
+
" Got: nil \n" +
|
32
|
+
"in: #{caller[2]}\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/printer.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
class Printer
|
2
|
+
|
3
|
+
def self.test_passes
|
4
|
+
printf '.'
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.test_fails
|
8
|
+
printf 'F'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.test_error
|
12
|
+
printf 'E'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.new_line
|
16
|
+
puts ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.results_for total_passes, failures, exceptions
|
20
|
+
new_line
|
21
|
+
if exceptions.length > 0
|
22
|
+
print_exceptions exceptions
|
23
|
+
end
|
24
|
+
if failures.length > 0
|
25
|
+
print_failures failures
|
26
|
+
end
|
27
|
+
print_summary total_passes, failures, exceptions
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.print_exceptions exceptions
|
31
|
+
puts "\nErrors:\n"
|
32
|
+
exceptions.each_with_index do |exception, index|
|
33
|
+
new_line
|
34
|
+
puts (index + 1).to_s + ") " + exception.message
|
35
|
+
puts "in " + exception.backtrace[0]
|
36
|
+
end
|
37
|
+
new_line
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.print_failures failures
|
41
|
+
puts "\nFailures:\n"
|
42
|
+
failures.each_with_index do |failure, index|
|
43
|
+
new_line
|
44
|
+
puts (index + 1).to_s + ") " + failure.message
|
45
|
+
end
|
46
|
+
new_line
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.print_summary total_passes, failures, exceptions
|
50
|
+
puts "#{total_passes + failures.length} assertions, " +
|
51
|
+
"#{total_passes} passed, " +
|
52
|
+
"#{failures.length} failed, " +
|
53
|
+
"with #{exceptions.length} errors"
|
54
|
+
new_line
|
55
|
+
end
|
56
|
+
end
|
data/lib/test_javalos.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class TestJavalos
|
2
|
+
|
3
|
+
def initialize(runner)
|
4
|
+
@runner = runner
|
5
|
+
end
|
6
|
+
|
7
|
+
def j_assert_equals object_1, object_2
|
8
|
+
if object_1 == object_2
|
9
|
+
@runner.test_passes
|
10
|
+
else
|
11
|
+
@runner.assert_equals_fails object_1, object_2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def j_assert_not_null object
|
16
|
+
if not(object.nil?)
|
17
|
+
@runner.test_passes
|
18
|
+
else
|
19
|
+
@runner.assert_not_null_fails
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def before_all
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_all
|
27
|
+
end
|
28
|
+
|
29
|
+
def before_each
|
30
|
+
end
|
31
|
+
|
32
|
+
def after_each
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'failure'
|
2
|
+
require_relative 'printer'
|
3
|
+
|
4
|
+
class TestJavalosRunner
|
5
|
+
attr_reader :exceptions, :failures, :total_passes
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@exceptions = Array.new
|
9
|
+
@failures = Array.new
|
10
|
+
@total_passes = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
run_tests
|
15
|
+
print_results
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_passes
|
19
|
+
Printer.test_passes
|
20
|
+
@total_passes = total_passes + 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_equals_fails object_1, object_2
|
24
|
+
Printer.test_fails
|
25
|
+
failures << Failure.assert_equals(object_1, object_2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_not_null_fails
|
29
|
+
Printer.test_fails
|
30
|
+
failures << Failure.assert_not_null
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_error_by exception
|
34
|
+
Printer.test_error
|
35
|
+
exceptions << exception
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def run_tests
|
41
|
+
classes = ObjectSpace.each_object(Class).to_a
|
42
|
+
test_classes = classes.find_all{|object_class| object_class.name =~ /(.*)Test$/ and object_class < TestJavalos }
|
43
|
+
test_classes.each do |test_class|
|
44
|
+
run_tests_for test_class
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def print_results
|
49
|
+
Printer.results_for total_passes, failures, exceptions
|
50
|
+
end
|
51
|
+
|
52
|
+
def run_tests_for test_class
|
53
|
+
instance = test_class.new(self)
|
54
|
+
instance.before_all
|
55
|
+
test_class.instance_methods.grep(/^test/).each do |method|
|
56
|
+
run_method_test_with instance, method
|
57
|
+
end
|
58
|
+
instance.after_all
|
59
|
+
end
|
60
|
+
|
61
|
+
def run_method_test_with instance, method
|
62
|
+
begin
|
63
|
+
instance.before_each
|
64
|
+
instance.send(method)
|
65
|
+
rescue => exception
|
66
|
+
test_error_by exception
|
67
|
+
ensure
|
68
|
+
instance.after_each
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_javalos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Avalos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: test_javalos
|
15
|
+
email: javalosmen@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/failure.rb
|
21
|
+
- lib/printer.rb
|
22
|
+
- lib/test_javalos.rb
|
23
|
+
- lib/test_javalos_runner.rb
|
24
|
+
homepage: http://rubygems.org/gems/test_javalos
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.10
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: test_javalos
|
48
|
+
test_files: []
|