ruby_test 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/bin/rtest +7 -0
- data/lib/rtest.rb +8 -0
- data/lib/rtest/console.rb +14 -0
- data/lib/rtest/equal.rb +40 -0
- data/lib/rtest/expect.rb +30 -0
- data/lib/rtest/file_getter.rb +18 -0
- data/lib/rtest/main_test.rb +39 -0
- data/lib/rtest/nested_test.rb +21 -0
- data/lib/rtest/test.rb +71 -0
- data/lib/rtest/test_failure_error.rb +5 -0
- data/lib/rtest/version.rb +3 -0
- data/spec/constants.rb +18 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Erick Castillo ecastillo@pernix-solutions.com
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/bin/rtest
ADDED
data/lib/rtest.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require_relative 'rtest/console'
|
2
|
+
require_relative 'rtest/equal'
|
3
|
+
require_relative 'rtest/expect'
|
4
|
+
require_relative 'rtest/file_getter'
|
5
|
+
require_relative 'rtest/main_test'
|
6
|
+
require_relative 'rtest/nested_test'
|
7
|
+
require_relative 'rtest/test'
|
8
|
+
require_relative 'rtest/test_failure_error'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
module RTest
|
5
|
+
class Console
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def display_leveled_message(level, message, color = nil)
|
9
|
+
level.times { print "\t" }
|
10
|
+
message = message.send(color) if color
|
11
|
+
puts message
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rtest/equal.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module RTest
|
2
|
+
class Equal
|
3
|
+
|
4
|
+
FAILURE_MESSAGE_FOR_TO = "does not match, expecting {match}, got {compare}"
|
5
|
+
FAILURE_MESSAGE_FOR_NOT_TO = "match, expecting somthing different to {match}, got {compare}"
|
6
|
+
SUCCESS_MESSAGE_FOR_TO = "objects match"
|
7
|
+
SUCCESS_MESSAGE_FOR_NOT_TO = "objects does not match"
|
8
|
+
|
9
|
+
def initialize(object)
|
10
|
+
@match_object = object
|
11
|
+
end
|
12
|
+
|
13
|
+
def match?(compare_object)
|
14
|
+
@compare_object = compare_object
|
15
|
+
@match_object == @compare_object
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message_for_to
|
19
|
+
substitute_comparisons(FAILURE_MESSAGE_FOR_TO)
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_message_for_not_to
|
23
|
+
substitute_comparisons(FAILURE_MESSAGE_FOR_NOT_TO)
|
24
|
+
end
|
25
|
+
|
26
|
+
def success_message_for_to
|
27
|
+
SUCCESS_MESSAGE_FOR_TO
|
28
|
+
end
|
29
|
+
|
30
|
+
def success_message_for_not_to
|
31
|
+
SUCCESS_MESSAGE_FOR_NOT_TO
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def substitute_comparisons(message)
|
36
|
+
message = message.sub(/{match}/, @match_object.to_s)
|
37
|
+
message.sub(/{compare}/, @compare_object.to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rtest/expect.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module RTest
|
2
|
+
class Expect
|
3
|
+
|
4
|
+
attr_reader :failure_message, :passing_message
|
5
|
+
|
6
|
+
def initialize(object)
|
7
|
+
@object = object
|
8
|
+
end
|
9
|
+
|
10
|
+
def to(matcher)
|
11
|
+
if(matcher.match?(@object))
|
12
|
+
@pass = true
|
13
|
+
@passing_message = matcher.success_message_for_to
|
14
|
+
else @failure_message = matcher.failure_message_for_to
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def not_to(matcher)
|
19
|
+
if(matcher.match?(@object)) then @failure_message = matcher.failure_message_for_not_to
|
20
|
+
else
|
21
|
+
@passing_message = matcher.success_message_for_not_to
|
22
|
+
@pass = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def pass?
|
27
|
+
@pass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
module RTest
|
4
|
+
module FileGetter
|
5
|
+
|
6
|
+
def self.files_from_args
|
7
|
+
files = []
|
8
|
+
args.each do |file_path|
|
9
|
+
Find.find(file_path) { |path| files << path if File.file?(path) }
|
10
|
+
end
|
11
|
+
files
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.args
|
15
|
+
ARGV
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RTest
|
2
|
+
module MainTest
|
3
|
+
|
4
|
+
@@tests = []
|
5
|
+
|
6
|
+
def the(message, optional_message = '', &block)
|
7
|
+
@@tests << RTest::NestedTest.new(message, optional_message, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_tests
|
11
|
+
@@tests.each { |test| test.run }
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
files = RTest::FileGetter.files_from_args
|
16
|
+
files.each { |file| process_file(file) }
|
17
|
+
run_tests
|
18
|
+
end
|
19
|
+
|
20
|
+
def tests
|
21
|
+
@@tests
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def process_file(file)
|
26
|
+
add_dir_to_load_path(file)
|
27
|
+
eval(File.read(file))
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_full_path(file)
|
31
|
+
File.dirname(File.expand_path(file))
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_dir_to_load_path(file)
|
35
|
+
path = file_full_path(file)
|
36
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RTest
|
2
|
+
class NestedTest
|
3
|
+
|
4
|
+
attr_reader :tests
|
5
|
+
|
6
|
+
def initialize(message, optional_message = '', &block)
|
7
|
+
@message = message.to_s << optional_message
|
8
|
+
@tests = []
|
9
|
+
instance_eval(&block) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_to(message = nil, &block)
|
13
|
+
@tests << Test.new(message, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
Console.instance.display_leveled_message(0, @message)
|
18
|
+
@tests.map { |test| test.run }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rtest/test.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module RTest
|
2
|
+
class Test
|
3
|
+
|
4
|
+
FAIL = "FAILED"
|
5
|
+
|
6
|
+
attr_reader :expectations
|
7
|
+
|
8
|
+
def initialize(message = nil, &block)
|
9
|
+
@message = message
|
10
|
+
@expectations = []
|
11
|
+
instance_eval(&block) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def expect(object)
|
15
|
+
expectation = Expect.new(object)
|
16
|
+
@expectations << expectation
|
17
|
+
expectation
|
18
|
+
end
|
19
|
+
|
20
|
+
def equal(object)
|
21
|
+
Equal.new(object)
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
unless(empty_test?)
|
26
|
+
run_test_result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def console
|
32
|
+
Console.instance
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_test_result
|
36
|
+
begin
|
37
|
+
run_expectations
|
38
|
+
console.display_leveled_message(1, success_message, :green)
|
39
|
+
rescue TestFailureError => error
|
40
|
+
error_message(error)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def error_message(error)
|
45
|
+
console.display_leveled_message(1, failure_message, :red)
|
46
|
+
console.display_leveled_message(2, error.message, :red)
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_expectations
|
50
|
+
@expectations.each do |expectation|
|
51
|
+
raise TestFailureError, expectation.failure_message unless expectation.pass?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def empty_test?
|
56
|
+
@expectations.size == 0
|
57
|
+
end
|
58
|
+
|
59
|
+
def success_message
|
60
|
+
@message || first_expectation_message
|
61
|
+
end
|
62
|
+
|
63
|
+
def failure_message
|
64
|
+
@message || FAIL
|
65
|
+
end
|
66
|
+
|
67
|
+
def first_expectation_message
|
68
|
+
@expectations[0].passing_message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/constants.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Class
|
2
|
+
end
|
3
|
+
|
4
|
+
A_VALUE = 1
|
5
|
+
ANOTHER_VALUE = 2
|
6
|
+
FAILURE_MESSAGE_FOR_TO = "does not match, expecting #{A_VALUE}, got #{ANOTHER_VALUE}"
|
7
|
+
FAILURE_MESSAGE_FOR_NOT_TO = "match, expecting somthing different to #{A_VALUE}, got #{A_VALUE}"
|
8
|
+
SUCCESS_MESSAGE_FOR_TO = "objects match"
|
9
|
+
SUCCESS_MESSAGE_FOR_NOT_TO = "objects does not match"
|
10
|
+
A_CLASS = Class
|
11
|
+
A_MESSAGE = 'a message'
|
12
|
+
A_TEST = 'test'
|
13
|
+
A_OBJECT = 1
|
14
|
+
PASSING_MESSAGE = 'pass'
|
15
|
+
FAILURE_MESSAGE = 'not pass'
|
16
|
+
FILES = ['file1', 'file2']
|
17
|
+
DIRECTORY_CONTENT = ['file1', 'dir1', 'file2']
|
18
|
+
ABSOLUTE_PATH = 'absolute'
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Erick Castillo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Testing suite for Ruby, allows to test for equality with nested examples
|
15
|
+
email: ecastillo@pernix-solutions.com
|
16
|
+
executables:
|
17
|
+
- rtest
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/rtest
|
22
|
+
- lib/rtest/expect.rb
|
23
|
+
- lib/rtest/test.rb
|
24
|
+
- lib/rtest/file_getter.rb
|
25
|
+
- lib/rtest/version.rb
|
26
|
+
- lib/rtest/test_failure_error.rb
|
27
|
+
- lib/rtest/console.rb
|
28
|
+
- lib/rtest/main_test.rb
|
29
|
+
- lib/rtest/equal.rb
|
30
|
+
- lib/rtest/nested_test.rb
|
31
|
+
- lib/rtest.rb
|
32
|
+
- README.md
|
33
|
+
- LICENSE
|
34
|
+
- spec/constants.rb
|
35
|
+
homepage: https://github.com/erickcsh/rTest
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.23
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Allows testing for equality in ruby
|
60
|
+
test_files:
|
61
|
+
- spec/constants.rb
|