gemmyrb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gemmy/tests/patch_test.rb +86 -92
- data/lib/gemmy/version.rb +1 -1
- data/lib/gemmy.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b30fe2939e2251a99af369b5ddd6c8b0ac67a17
|
4
|
+
data.tar.gz: a8bd3b128d659c5cc1db588106ec302f357ddd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 586500544147c163596317533ec51a26a1be5c537ae71084acc2c39d7ba4fa52f1bc32855bf7d470c9993213028bba42e093ba0475d1258cfb70e750e244744b
|
7
|
+
data.tar.gz: 02c9d99ba878a1e7f15892daea36ec72fb2dd53d067e6f0df5fbb9bd2a3f7e13b69e00301e46e0e55133bad71281fb79a57ace33e88db60725cc60c9781ecc5f
|
@@ -3,7 +3,6 @@ module Gemmy::Tests
|
|
3
3
|
module PatchTests
|
4
4
|
|
5
5
|
def self.run
|
6
|
-
# call each of the patch_class methods
|
7
6
|
%i{
|
8
7
|
array_test symbol_test method_test thread_test
|
9
8
|
global_test string_test hash_test
|
@@ -11,116 +10,111 @@ module Gemmy::Tests
|
|
11
10
|
end
|
12
11
|
|
13
12
|
module Error
|
14
|
-
# Allow using raise with one argument only
|
15
|
-
# raises RuntimeError
|
16
|
-
#
|
17
|
-
# this is included in the global patches,
|
18
|
-
# but the test suite doesn't depend on it.
|
19
|
-
#
|
20
|
-
# @param msg [String]
|
21
|
-
#
|
22
13
|
def error(msg='')
|
23
14
|
raise(RuntimeError, msg)
|
24
15
|
end
|
25
16
|
end
|
26
17
|
|
27
|
-
|
18
|
+
BuildPatchedClass = Proc.new {
|
19
|
+
class PatchedClass
|
28
20
|
|
29
|
-
|
21
|
+
Gemmy::Patches.class_refinements.each { |r| using r }
|
30
22
|
|
31
|
-
|
23
|
+
extend Gemmy::Tests::PatchTests::Error
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
def self.thread_test
|
26
|
+
# Threads abort on exception
|
27
|
+
Thread.new { fail }
|
28
|
+
sleep 0.25
|
29
|
+
error "thread didn't bubble up error"
|
30
|
+
rescue
|
31
|
+
puts " Threads abort on exception".blue
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
34
|
+
def self.hash_test
|
35
|
+
# Hash#autovivified
|
36
|
+
hash = {}.autovivified
|
37
|
+
hash[:a][:b] = 0
|
38
|
+
error unless hash[:a][:b] == 0
|
39
|
+
puts " Hash#autovivified".blue
|
40
|
+
|
41
|
+
# Hash#bury
|
42
|
+
hash = { a: { b: { } } }
|
43
|
+
hash.bury(:a, :b, :c, 0)
|
44
|
+
error unless hash[:a][:b][:c] == 0
|
45
|
+
puts " Hash#bury".blue
|
46
|
+
|
47
|
+
# Hash#persisted
|
48
|
+
db = "test_db.yaml"
|
49
|
+
hash = {}.persisted db
|
50
|
+
hash.set(:a, :b, 0)
|
51
|
+
error unless hash.get(:a, :b) == 0
|
52
|
+
error unless hash.get(:a, :b, disk: true) == 0
|
53
|
+
error unless YAML.load(File.read db)[:data][:a][:b] == 0
|
54
|
+
File.delete(db)
|
55
|
+
puts " Hash#persisted".blue
|
56
|
+
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
58
|
+
def self.array_test
|
59
|
+
# Array#any_not?
|
60
|
+
false_case = [[]].any_not? &:empty?
|
61
|
+
true_case = [[1]].any_not? &:empty?
|
62
|
+
error unless true_case && !false_case
|
63
|
+
puts " Array#any_not?".blue
|
64
|
+
end
|
73
65
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
66
|
+
def self.symbol_test
|
67
|
+
# Symbol#with
|
68
|
+
result = [[]].map &:concat.with([1])
|
69
|
+
error unless result == [[1]]
|
70
|
+
puts " Symbol#with".blue
|
71
|
+
end
|
80
72
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
73
|
+
def self.method_test
|
74
|
+
# Method#bind
|
75
|
+
def self.add(a,b)
|
76
|
+
a + b
|
77
|
+
end
|
78
|
+
result = [0].map &method(:add).bind(1)
|
79
|
+
error unless result == [1]
|
80
|
+
puts " Method#bind".blue
|
85
81
|
end
|
86
|
-
result = [0].map &method(:add).bind(1)
|
87
|
-
error unless result == [1]
|
88
|
-
puts " Method#bind".blue
|
89
|
-
end
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
83
|
+
def self.global_test
|
84
|
+
# m is an alias for method
|
85
|
+
def self.sample_method(x)
|
86
|
+
x
|
87
|
+
end
|
88
|
+
result = [0].map &m(:sample_method)
|
89
|
+
error unless result == [0]
|
90
|
+
puts " Object#m".blue
|
91
|
+
|
92
|
+
# error_if_blank
|
93
|
+
# error an error if an object is blank
|
94
|
+
blank = nil
|
95
|
+
not_blank = 0
|
96
|
+
error_if_blank not_blank
|
97
|
+
begin
|
98
|
+
error_if_blank blank
|
99
|
+
error("this won't be raised")
|
100
|
+
rescue RuntimeError => e
|
101
|
+
error if e.message == "this won't be raised"
|
102
|
+
puts " Object#error_if_blank".blue
|
103
|
+
end
|
95
104
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
blank = nil
|
103
|
-
not_blank = 0
|
104
|
-
error_if_blank not_blank
|
105
|
-
begin
|
106
|
-
error_if_blank blank
|
107
|
-
error("this won't be raised")
|
108
|
-
rescue RuntimeError => e
|
109
|
-
error if e.message == "this won't be raised"
|
110
|
-
puts " Object#error_if_blank".blue
|
105
|
+
|
106
|
+
def self.string_test
|
107
|
+
# String#unindent
|
108
|
+
result = " 0".unindent
|
109
|
+
error unless result == "0"
|
110
|
+
puts " String#unindent".blue
|
111
111
|
end
|
112
|
-
end
|
113
112
|
|
114
|
-
|
115
|
-
# String#unindent
|
116
|
-
result = " 0".unindent
|
117
|
-
error unless result == "0"
|
118
|
-
puts " String#unindent".blue
|
119
|
-
end
|
113
|
+
end # PatchedClass
|
120
114
|
|
121
|
-
|
115
|
+
} # BuildPatchedClass
|
122
116
|
|
123
|
-
end
|
117
|
+
end # PatchedTests
|
124
118
|
|
125
119
|
TestSets << PatchTests
|
126
120
|
|
data/lib/gemmy/version.rb
CHANGED
data/lib/gemmy.rb
CHANGED