adispec 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/adispec +17 -0
- data/lib/adispec.rb +58 -0
- data/lib/assertions.rb +25 -0
- data/lib/exceptions.rb +22 -0
- data/lib/section.rb +64 -0
- data/lib/suite.rb +36 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee38261159f2ed51617c39f483e56f07b9cfbd7d
|
4
|
+
data.tar.gz: cf0ca21b56fa48ee9911164f6c6116f77bab3933
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0abc75ceb603b5f9186c7d23b4462e3a6c8286240c38d0bed959669d17816db0f5587a977b30964493bf3401b6d5f596aa68f3f8cf32ef2278c186e76f44663
|
7
|
+
data.tar.gz: d90ecb38a280c8ac0aaf1c711575cfac05953184957b7285f7a1c6d5c763fc1c1a2671cac33ea5e9ca7bba57474f04de10a083d0fec45beb087d1417b2d235e1
|
data/bin/adispec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'adispec'
|
4
|
+
|
5
|
+
dirname = ARGV.empty? ? "specs" : ARGV[0]
|
6
|
+
raise "Could not find #{dirname}: No such file or directory" unless Dir.exist?(dirname)
|
7
|
+
|
8
|
+
Suite.new()
|
9
|
+
|
10
|
+
Dir["#{dirname}/**/*spec.rb"].each { |file|
|
11
|
+
Suite.stacks.push file
|
12
|
+
}
|
13
|
+
|
14
|
+
Dir["#{dirname}/**/*spec.rb"].each { |file|
|
15
|
+
load file
|
16
|
+
}
|
17
|
+
|
data/lib/adispec.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'sourcify'
|
2
|
+
require 'colorize'
|
3
|
+
require_relative './exceptions'
|
4
|
+
require_relative './assertions'
|
5
|
+
require_relative './section'
|
6
|
+
require_relative './suite'
|
7
|
+
|
8
|
+
def describe(desc, &func)
|
9
|
+
sp = Section.new(desc)
|
10
|
+
pad = [' '] * Section::specstack.length * ''
|
11
|
+
puts
|
12
|
+
puts pad + desc.blue + ":"
|
13
|
+
func.call
|
14
|
+
Section::specstack.pop
|
15
|
+
if Section::specstack.empty?
|
16
|
+
puts
|
17
|
+
Suite::stacks.pop
|
18
|
+
Suite.inc_tests sp.tests
|
19
|
+
Suite.inc_passes sp.passes
|
20
|
+
Suite.inc_fails sp.fails
|
21
|
+
puts "Result: #{Suite::tests} ran, "\
|
22
|
+
"#{Suite::passes.to_s.green} "\
|
23
|
+
"#{"passed".green}, "\
|
24
|
+
"#{Suite::fails.to_s.red} "\
|
25
|
+
"#{"failed".red}" if Suite::stacks.empty?
|
26
|
+
else
|
27
|
+
Section::lastspec.inc_tests sp.tests
|
28
|
+
Section::lastspec.inc_passes sp.passes
|
29
|
+
Section::lastspec.inc_fails sp.fails
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def it(desc, &func)
|
34
|
+
pad = [' '] * Section::specstack.length * ''
|
35
|
+
print pad + desc + ": "
|
36
|
+
Section::lastspec.inc_tests
|
37
|
+
begin
|
38
|
+
Section::specstack.each do |spec|
|
39
|
+
spec.run_setups
|
40
|
+
end
|
41
|
+
func.call
|
42
|
+
Section::lastspec.run_cleanups
|
43
|
+
rescue BlockError
|
44
|
+
Section::lastspec.inc_fails
|
45
|
+
puts
|
46
|
+
return
|
47
|
+
end
|
48
|
+
Section::lastspec.inc_passes
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup(&func)
|
53
|
+
Section::lastspec.push_setup(func)
|
54
|
+
end
|
55
|
+
|
56
|
+
def cleanup(&func)
|
57
|
+
Section::lastspec.push_cleanup(func)
|
58
|
+
end
|
data/lib/assertions.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
def assert &block
|
2
|
+
begin
|
3
|
+
raise AssertionError.new(&block) unless yield
|
4
|
+
print "\u2713".green
|
5
|
+
rescue AssertionError => e
|
6
|
+
print "x".red + " " + e.message
|
7
|
+
raise BlockError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def assertRaise &block
|
12
|
+
begin
|
13
|
+
begin
|
14
|
+
yield
|
15
|
+
rescue Exception => e
|
16
|
+
print "\u2713".green
|
17
|
+
return
|
18
|
+
end
|
19
|
+
raise AssertExceptionError.new(&block)
|
20
|
+
rescue AssertExceptionError => e
|
21
|
+
puts "x".red + " " + e.message
|
22
|
+
raise BlockError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/exceptions.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class AssertionError < RuntimeError
|
2
|
+
def initialize(&block)
|
3
|
+
@msg = "Assertion " + block.to_source + " failed"
|
4
|
+
end
|
5
|
+
|
6
|
+
def message
|
7
|
+
@msg
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class AssertExceptionError < RuntimeError
|
12
|
+
def initialize(&block)
|
13
|
+
@msg = "Assertion " + block.to_source + " failed to throw an exception"
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
@msg
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class BlockError < RuntimeError
|
22
|
+
end
|
data/lib/section.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
class Section
|
2
|
+
def initialize(desc)
|
3
|
+
@desc = 0
|
4
|
+
@tests = 0
|
5
|
+
@passes = 0
|
6
|
+
@fails = 0
|
7
|
+
@setups = []
|
8
|
+
@cleanups = []
|
9
|
+
@@specstack ||= []
|
10
|
+
@@specstack.push self
|
11
|
+
end
|
12
|
+
|
13
|
+
def tests
|
14
|
+
@tests
|
15
|
+
end
|
16
|
+
|
17
|
+
def passes
|
18
|
+
@passes
|
19
|
+
end
|
20
|
+
|
21
|
+
def fails
|
22
|
+
@fails
|
23
|
+
end
|
24
|
+
|
25
|
+
def inc_tests(n = 1)
|
26
|
+
@tests += n
|
27
|
+
end
|
28
|
+
|
29
|
+
def inc_passes(n = 1)
|
30
|
+
@passes += n
|
31
|
+
end
|
32
|
+
|
33
|
+
def inc_fails(n = 1)
|
34
|
+
@fails += n
|
35
|
+
end
|
36
|
+
|
37
|
+
def push_setup(block)
|
38
|
+
@setups << block
|
39
|
+
end
|
40
|
+
|
41
|
+
def push_cleanup(block)
|
42
|
+
@cleanups << block
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_setups
|
46
|
+
@setups.each do |setup|
|
47
|
+
setup.call
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_cleanups
|
52
|
+
@cleanups.each do |cleanup|
|
53
|
+
cleanup.call
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.lastspec
|
58
|
+
@@specstack.last
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.specstack
|
62
|
+
@@specstack
|
63
|
+
end
|
64
|
+
end
|
data/lib/suite.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Suite
|
2
|
+
def initialize
|
3
|
+
@@passes = 0
|
4
|
+
@@fails = 0
|
5
|
+
@@tests = 0
|
6
|
+
@@stacks = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.inc_tests n
|
10
|
+
@@tests += n
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.inc_passes n
|
14
|
+
@@passes += n
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.inc_fails n
|
18
|
+
@@fails += n
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.tests
|
22
|
+
@@tests
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.passes
|
26
|
+
@@passes
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.fails
|
30
|
+
@@fails
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.stacks
|
34
|
+
@@stacks
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adispec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aditya Anchuri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Testing/assertion library for Ruby
|
14
|
+
email: aditya.anchuri@gmail.com
|
15
|
+
executables:
|
16
|
+
- adispec
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/adispec
|
21
|
+
- lib/adispec.rb
|
22
|
+
- lib/assertions.rb
|
23
|
+
- lib/exceptions.rb
|
24
|
+
- lib/section.rb
|
25
|
+
- lib/suite.rb
|
26
|
+
homepage: http://rubygems.org/gems/adispec
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.5.1
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Keep ruby tests simple
|
50
|
+
test_files: []
|