Class: Gemmy::Tests::PatchTests::PatchedClass

Inherits:
Object
  • Object
show all
Extended by:
Error
Defined in:
lib/gemmy/tests/patch_test.rb

Class Method Summary collapse

Methods included from Error

error

Class Method Details

.add(a, b) ⇒ Object

Method#bind



83
84
85
# File 'lib/gemmy/tests/patch_test.rb', line 83

def self.add(a,b)
  a + b
end

.array_testObject



66
67
68
69
70
71
72
# File 'lib/gemmy/tests/patch_test.rb', line 66

def self.array_test
  # Array#any_not?
  false_case = [[]].any_not? &:empty?
  true_case = [[1]].any_not? &:empty?
  error unless true_case && !false_case
  puts "  Array#any_not?".blue
end

.global_testObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gemmy/tests/patch_test.rb', line 91

def self.global_test
  # m is an alias for method
  def self.sample_method(x)
    x
  end
  result = [0].map &m(:sample_method)
  error unless result == [0]
  puts "  Object#m".blue

  # error_if_blank
  # error an error if an object is blank
  blank = nil
  not_blank = 0
  error_if_blank not_blank
  begin
    error_if_blank blank
    error("this won't be raised")
  rescue RuntimeError => e
    error if e.message == "this won't be raised"
    puts "  Object#error_if_blank".blue
  end
end

.hash_testObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gemmy/tests/patch_test.rb', line 42

def self.hash_test
  # Hash#autovivified
  hash = {}.autovivified
  hash[:a][:b] = 0
  error unless hash[:a][:b] == 0
  puts "  Hash#autovivified".blue

  # Hash#bury
  hash = { a: { b: { } } }
  hash.bury(:a, :b, :c, 0)
  error unless hash[:a][:b][:c] == 0
  puts "  Hash#bury".blue

  # Hash#persisted
  db = "test_db.yaml"
  hash = {}.persisted db
  hash.set(:a, :b, 0)
  error unless hash.get(:a, :b) == 0
  error unless hash.get(:a, :b, disk: true) == 0
  error unless YAML.load(File.read db)[:data][:a][:b] == 0
  File.delete(db)
  puts "  Hash#persisted".blue
end

.method_testObject



81
82
83
84
85
86
87
88
89
# File 'lib/gemmy/tests/patch_test.rb', line 81

def self.method_test
  # Method#bind
  def self.add(a,b)
    a + b
  end
  result = [0].map &method(:add).bind(1)
  error unless result == [1]
  puts "  Method#bind".blue
end

.sample_method(x) ⇒ Object

m is an alias for method



93
94
95
# File 'lib/gemmy/tests/patch_test.rb', line 93

def self.sample_method(x)
  x
end

.string_testObject



114
115
116
117
118
119
# File 'lib/gemmy/tests/patch_test.rb', line 114

def self.string_test
  # String#unindent
  result = "  0".unindent
  error unless result == "0"
  puts "  String#unindent".blue
end

.symbol_testObject



74
75
76
77
78
79
# File 'lib/gemmy/tests/patch_test.rb', line 74

def self.symbol_test
  # Symbol#with
  result = [[]].map &:concat.with([1])
  error unless result == [[1]]
  puts "  Symbol#with".blue
end

.thread_testObject



33
34
35
36
37
38
39
40
# File 'lib/gemmy/tests/patch_test.rb', line 33

def self.thread_test
  # Threads abort on exception
  Thread.new { fail }
  sleep 0.25
  error "thread didn't bubble up error"
rescue
  puts "  Threads abort on exception".blue
end