ruby_test2 0.1.0
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.
- checksums.yaml +7 -0
- data/bin/ruby-test +30 -0
- data/lib/ruby_test.rb +108 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4369db8536beb4350463784f7ad5a49d00ecc6ee
|
4
|
+
data.tar.gz: e8705a421d0ebefef45dcb5a33a35e5b7fe1474d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e75f5676446d61d3925071426f71951fb9d615521c342e941a907df91b2d3bf78ef6a5d14d3b4605af3f20ca6fce1b3fd5b19a72fe677df9544d64b7776ccb4c
|
7
|
+
data.tar.gz: 21b94e2a175de00abd6c502bef92837c3cf144786634b8c43342b6f4f5525f2f17f3de38996153ad91a354542b332f390e6b464ed10844f2b37ab8f897d3d1ef
|
data/bin/ruby-test
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.push(File.expand_path('lib'))
|
4
|
+
|
5
|
+
require 'ruby_test'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
module RubyTest
|
9
|
+
VERSION = '0.1.0'
|
10
|
+
def self.run(file)
|
11
|
+
puts("The process may have returned a non-zero exit status: #{$?}") unless system("ruby test/#{file}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: ruby-test [options]"
|
18
|
+
|
19
|
+
opts.on("-v", "--version", "Print version.") { |v| options[:version] = v }
|
20
|
+
opts.on("-r", "--run", "Run every test in test directory.") { |r| options[:run] = r }
|
21
|
+
end.parse!
|
22
|
+
|
23
|
+
puts(RubyTest::VERSION) if options[:version]
|
24
|
+
|
25
|
+
if options[:run]
|
26
|
+
entries = Dir.entries('test')
|
27
|
+
entries.delete('.')
|
28
|
+
entries.delete('..')
|
29
|
+
entries.each { |entry| RubyTest.run(entry) }
|
30
|
+
end
|
data/lib/ruby_test.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'colorator'
|
2
|
+
|
3
|
+
$total = 0
|
4
|
+
$ok = 0
|
5
|
+
$fails = 0
|
6
|
+
$fail_names = []
|
7
|
+
$color_mode = false
|
8
|
+
$sep_switch = true
|
9
|
+
|
10
|
+
class String
|
11
|
+
def color_mode(color)
|
12
|
+
if $color_mode
|
13
|
+
case color
|
14
|
+
when :ok
|
15
|
+
return self.blue
|
16
|
+
when :fail
|
17
|
+
return self.red
|
18
|
+
when :normal
|
19
|
+
return self.green
|
20
|
+
end
|
21
|
+
else
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Test the subject against it's expected return value.
|
28
|
+
# @example
|
29
|
+
# assert('String test', '1'.class, String)
|
30
|
+
# assert('Fixnum test', 1.class, Fixnum)
|
31
|
+
# @param name [String] The name of the test, its used when reporting if it failed.
|
32
|
+
# @param object1 [Object] An expression to test.
|
33
|
+
# @param object2 [Object] The expected return value.
|
34
|
+
# @return [Bool] True if test passed.
|
35
|
+
def assert(name, object1, object2)
|
36
|
+
ret = object1.eql?(object2)
|
37
|
+
if ret
|
38
|
+
$ok += 1
|
39
|
+
else
|
40
|
+
$fails += 1
|
41
|
+
$fail_names.push(name)
|
42
|
+
end
|
43
|
+
$total += 1
|
44
|
+
|
45
|
+
ret
|
46
|
+
end
|
47
|
+
|
48
|
+
alias :test :assert
|
49
|
+
|
50
|
+
def print_bounds(str, plus=0)
|
51
|
+
sep_str = '-'
|
52
|
+
str_size = str.size + plus
|
53
|
+
|
54
|
+
str_size.times { print(sep_str.color_mode(:normal)) }
|
55
|
+
puts(' ') # Printing newlines
|
56
|
+
puts(str.color_mode(:normal))
|
57
|
+
str_size.times { print(sep_str.color_mode(:normal)) }
|
58
|
+
puts(' ')
|
59
|
+
yield
|
60
|
+
str_size.times { print(sep_str.color_mode(:normal)) }
|
61
|
+
puts(' ')
|
62
|
+
end
|
63
|
+
|
64
|
+
# Provides a block for tests that needs to be grouped togther.
|
65
|
+
# When the tests report is printed if the global variable $sep_switch
|
66
|
+
# is set to true(it is true by default), then bounddires are printed
|
67
|
+
# around the test, with the name of the test printed prominently.
|
68
|
+
# @example
|
69
|
+
# assert_block('Foo tests') do
|
70
|
+
# foo = Foo.new
|
71
|
+
#
|
72
|
+
# puts('Foo test start')
|
73
|
+
# assert('Foo test #1', foo.get, true)
|
74
|
+
# assert('Foo test #2', foo.destroy, false)
|
75
|
+
# assert('Foo test #3', foo.destroyed?, true)
|
76
|
+
# puts('Foo test end')
|
77
|
+
# end
|
78
|
+
# @example The result you may get if $sep_switch is true.
|
79
|
+
# ---------
|
80
|
+
# Foo tests
|
81
|
+
# ---------
|
82
|
+
# Foo test start
|
83
|
+
# Foo test end
|
84
|
+
# ---------
|
85
|
+
# @param name [String] The of the group of the tests.
|
86
|
+
# @see report
|
87
|
+
def assert_block(name="")
|
88
|
+
if $sep_switch
|
89
|
+
print_bounds(name) { yield } if $sep_switch
|
90
|
+
else
|
91
|
+
yield
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Prints a report of the tests above it.
|
96
|
+
# @param str [String] A string to be printed as the name of the report.
|
97
|
+
def report(str)
|
98
|
+
print_bounds("Summary for: #{str}") do
|
99
|
+
$fail_names.each { |n| puts("Failed test => #{n}".color_mode(:fail)) }
|
100
|
+
puts("Total: #{$total}".color_mode(:normal))
|
101
|
+
puts("Ok: #{$ok}".color_mode(:ok))
|
102
|
+
puts("Fails: #{$fails}".color_mode(:fail))
|
103
|
+
end
|
104
|
+
|
105
|
+
$total = 0
|
106
|
+
$ok = 0
|
107
|
+
$fails = 0
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_test2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ralph Desir(mav7)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A lightweight testing framework for Ruby programs.
|
14
|
+
email: gehirnmav7@protonmail.com
|
15
|
+
executables:
|
16
|
+
- ruby-test
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/ruby-test
|
21
|
+
- lib/ruby_test.rb
|
22
|
+
homepage:
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A lightweight testing framework for Ruby programs.
|
46
|
+
test_files: []
|