Module: RIO::Assert
- Defined in:
- lib/rio/assert.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #assert(a, msg = nil) ⇒ Object
- #assert!(a, msg = "negative assertion") ⇒ Object
- #assert_array_equal(a, b, msg = "array same regardless of order") ⇒ Object
- #assert_block(msg = nil) ⇒ Object
- #assert_case_equal(a, b, msg = nil) ⇒ Object
- #assert_dirs_equal(exp, d, msg = "") ⇒ Object
- #assert_equal(a, b, msg = nil) ⇒ Object
- #assert_equal_a(a, b, msg = nil) ⇒ Object
- #assert_equal_s(a, b, msg = nil) ⇒ Object
- #assert_instance_of(a, b, msg = nil) ⇒ Object
- #assert_kind_of(a, b, msg = nil) ⇒ Object
- #assert_match(a, b, msg = nil) ⇒ Object
- #assert_nil(a, msg = nil) ⇒ Object
- #assert_not_equal(a, b, msg = nil) ⇒ Object
- #assert_not_nil(a, msg = nil) ⇒ Object
- #assert_raise(exc, msg = nil, &block) ⇒ Object
- #assert_rios_equal(exp, ans, msg = "") ⇒ Object
- #assert_same(a, b, msg = nil) ⇒ Object
- #nok(a, b, msg = nil) ⇒ Object
- #ok(a, b, msg = nil) ⇒ Object
- #smap(a) ⇒ Object
Instance Method Details
#assert(a, msg = nil) ⇒ Object
42 43 44 |
# File 'lib/rio/assert.rb', line 42 def assert(a,msg=nil) assert_equal(true,a,msg) end |
#assert!(a, msg = "negative assertion") ⇒ Object
129 130 131 |
# File 'lib/rio/assert.rb', line 129 def assert!(a,msg="negative assertion") assert((!(a)),msg) end |
#assert_array_equal(a, b, msg = "array same regardless of order") ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/rio/assert.rb', line 135 def assert_array_equal(a,b,msg="array same regardless of order") if a.nil? assert_nil(b) elsif b.nil? assert_nil(a) else assert_equal(smap(a).sort,smap(b).sort,msg) end end |
#assert_block(msg = nil) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rio/assert.rb', line 68 def assert_block(msg=nil) if yield ok(nil,nil,msg) else nok(nil,nil,msg) end end |
#assert_case_equal(a, b, msg = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/rio/assert.rb', line 61 def assert_case_equal(a,b,msg=nil) if a == b ok(a,b,msg) else nok(a,b,msg) end end |
#assert_dirs_equal(exp, d, msg = "") ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rio/assert.rb', line 144 def assert_dirs_equal(exp,d,msg="") exp.each do |ent| ds = rio(d,ent.filename) assert_equal(ent.symlink?,ds.symlink?,"both symlinks, or not") unless ent.symlink? assert(ds.exist?,"entry '#{ds}' exists") end assert_equal(ent.ftype,ds.ftype,"same ftype") assert_rios_equal(ent,ds,"sub rios are the same") end end |
#assert_equal(a, b, msg = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rio/assert.rb', line 54 def assert_equal(a,b,msg=nil) if a == b ok(a,b,msg) else nok(a,b,msg) end end |
#assert_equal_a(a, b, msg = nil) ⇒ Object
127 |
# File 'lib/rio/assert.rb', line 127 def assert_equal_a(a,b,msg=nil) assert_equal(a.sort,b.sort,msg) end |
#assert_equal_s(a, b, msg = nil) ⇒ Object
126 |
# File 'lib/rio/assert.rb', line 126 def assert_equal_s(a,b,msg=nil) assert_equal(a.to_s,b.to_s,msg) end |
#assert_instance_of(a, b, msg = nil) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/rio/assert.rb', line 104 def assert_instance_of(a,b,msg=nil) if b.instance_of?(a) ok(a,b) else nok(a,b) end end |
#assert_kind_of(a, b, msg = nil) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/rio/assert.rb', line 118 def assert_kind_of(a,b,msg=nil) if b.kind_of?(a) ok(a,b.class) else nok(a,b.class) end end |
#assert_match(a, b, msg = nil) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/rio/assert.rb', line 111 def assert_match(a,b,msg=nil) if a =~ b ok(a,b) else nok(a,b) end end |
#assert_nil(a, msg = nil) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/rio/assert.rb', line 83 def assert_nil(a,msg=nil) if a.nil? ok(nil,a) else nok(nil,a) end end |
#assert_not_equal(a, b, msg = nil) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/rio/assert.rb', line 76 def assert_not_equal(a,b,msg=nil) if a != b ok(a,b,msg) else nok(a,b,msg) end end |
#assert_not_nil(a, msg = nil) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/rio/assert.rb', line 90 def assert_not_nil(a,msg=nil) if a.nil? nok(nil,a,msg) else ok(nil,a,msg) end end |
#assert_raise(exc, msg = nil, &block) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/rio/assert.rb', line 45 def assert_raise(exc,msg=nil,&block) begin yield rescue exc return ok(exc,nil,msg) end return nok(exc,nil,msg) end |
#assert_rios_equal(exp, ans, msg = "") ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rio/assert.rb', line 155 def assert_rios_equal(exp,ans,msg="") case when exp.symlink? assert(ans.symlink?,"entry is a symlink") assert_equal(exp.readlink,ans.readlink,"symlinks read the same") when exp.file? assert(ans.file?,"entry is a file") assert_equal(exp.chomp.lines[],ans.chomp.lines[],"file has same contents") when exp.dir? assert(ans.dir?,"entry is a dir") assert_dirs_equal(exp,ans,"directories are the same") end end |
#assert_same(a, b, msg = nil) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/rio/assert.rb', line 97 def assert_same(a,b,msg=nil) if a.equal? b ok(a,b) else nok(a,b) end end |
#nok(a, b, msg = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rio/assert.rb', line 34 def nok(a,b,msg=nil) calla = caller.grep(/^#{Regexp.escape($0)}/) calls = calla.join("\n") + "\n" puts "FAIL" + (msg.nil? ? "" : ": #{msg}") + calls puts " exp: #{a.inspect}" puts " was: #{b.inspect}" end |
#ok(a, b, msg = nil) ⇒ Object
31 32 33 |
# File 'lib/rio/assert.rb', line 31 def ok(a,b,msg=nil) puts "PASS" + (msg.nil? ? "" : ": #{msg}") end |
#smap(a) ⇒ Object
133 |
# File 'lib/rio/assert.rb', line 133 def smap(a) a.map { |el| el.to_s } end |