simple_test 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.
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
@@ -0,0 +1,4 @@
1
+ SimpleTest
2
+ ==========
3
+
4
+ Allows to test for equality
data/bin/simple_test ADDED
@@ -0,0 +1,5 @@
1
+ #!usr/bin/ruby
2
+
3
+ require_relative '../lib/simple_test'
4
+
5
+ SimpleTest::Runner.run
@@ -0,0 +1,37 @@
1
+ module SimpleTest
2
+ class Compare
3
+
4
+ attr_reader :method
5
+
6
+ def initialize(expectation)
7
+ @expectation = expectation
8
+ end
9
+
10
+ def ==(comparison)
11
+ set_info(comparison, :==)
12
+ end
13
+
14
+ def !=(comparison)
15
+ set_info(comparison, :!=)
16
+ end
17
+
18
+ def run
19
+ raise FailingTestError, error_message unless pass?
20
+ end
21
+
22
+ private
23
+ def set_info(comparison, method)
24
+ @comparison = comparison
25
+ @method = method
26
+ Object.add_test(self)
27
+ end
28
+
29
+ def pass?
30
+ @expectation.send(@method, @comparison)
31
+ end
32
+
33
+ def error_message
34
+ "expect #{@expectation} to #{@method} #{@comparison}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ require 'singleton'
2
+ require 'colorize'
3
+
4
+ module SimpleTest
5
+ class Console
6
+ include Singleton
7
+
8
+ def result_message(message = PASS, color = :green)
9
+ puts message.send(color)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleTest
2
+ class FailingTestError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,36 @@
1
+ class Object
2
+
3
+ PASS = 'pass'
4
+
5
+ @@tests = []
6
+
7
+ def self.add_test(test)
8
+ @@tests << test
9
+ end
10
+
11
+ def self.run
12
+ @@tests.each { |test| run_test(test) }
13
+ end
14
+
15
+ def self.tests
16
+ @@tests
17
+ end
18
+
19
+ def must
20
+ SimpleTest::Compare.new(self)
21
+ end
22
+
23
+ private
24
+ def run_test(test)
25
+ begin
26
+ test.run
27
+ console.result_message
28
+ rescue SimpleTest::FailingTestError => error
29
+ console.result_message(error.message, :red)
30
+ end
31
+ end
32
+
33
+ def console
34
+ SimpleTest::Console.instance
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'find'
2
+
3
+ module SimpleTest
4
+ module Runner
5
+
6
+ def self.run
7
+ files.each do |file|
8
+ add_dir_to_load_path(file)
9
+ process_file(file)
10
+ end
11
+ Object.run
12
+ end
13
+
14
+ private
15
+ def self.files
16
+ filesnames = []
17
+ ARGV.each do |arg|
18
+ Find.find(arg) { |path| filesnames << path if File.file?(path) }
19
+ end
20
+ filesnames
21
+ end
22
+
23
+ def self.process_file(file)
24
+ add_dir_to_load_path(file)
25
+ eval(File.read(file))
26
+ end
27
+
28
+ def self.file_full_path(file)
29
+ File.dirname(File.expand_path(file))
30
+ end
31
+
32
+ def self.add_dir_to_load_path(file)
33
+ path = file_full_path(file)
34
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleTest
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'simple_test/compare'
2
+ require_relative 'simple_test/console'
3
+ require_relative 'simple_test/failing_test_error'
4
+ require_relative 'simple_test/object'
5
+ require_relative 'simple_test/runner'
data/spec/constants.rb ADDED
@@ -0,0 +1,4 @@
1
+ A_TEST = 'test'
2
+ ANOTHER_TEST = 'another_test'
3
+ A_MESSAGE = 'error'
4
+ PASS = 'pass'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Erick Castillo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Testing suite for Ruby. Allows simple comparisons between to instances
15
+ email: ecastillo@pernix-solutions.com
16
+ executables:
17
+ - simple_test
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/simple_test
22
+ - lib/simple_test/compare.rb
23
+ - lib/simple_test/failing_test_error.rb
24
+ - lib/simple_test/runner.rb
25
+ - lib/simple_test/version.rb
26
+ - lib/simple_test/console.rb
27
+ - lib/simple_test/object.rb
28
+ - lib/simple_test.rb
29
+ - README.md
30
+ - LICENSE
31
+ - spec/constants.rb
32
+ homepage: https://github.com/erickcsh/SimpleTest
33
+ licenses:
34
+ - MIT
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.23
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Allows testing for equality and inequality in ruby in a simple way
57
+ test_files:
58
+ - spec/constants.rb