Class: NRSER::Rash::Testing::FunctionTestCase
- Defined in:
- lib/nrser/rash/testing.rb
Defined Under Namespace
Classes: Raises
Instance Method Summary collapse
- #assert_map(hash) ⇒ Object
-
#assert_raise_with_message(exception, expected, msg = nil, &block) ⇒ Object
this was added sometime after 1.9.3, backport:.
- #raises(cls, msg = nil) ⇒ Object
Instance Method Details
#assert_map(hash) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/nrser/rash/testing.rb', line 122 def assert_map(hash) hash.each do |input, output| input = [input] unless input.is_a?(Array) # allow mapping to an Exception class as an assert_raise if output.is_a?(Raises) if output.msg.nil? assert_raise output.cls do apply_target *input end else (output.cls, output.msg) do apply_target *input end end else assert_equal output, apply_target(*input) end end end |
#assert_raise_with_message(exception, expected, msg = nil, &block) ⇒ Object
this was added sometime after 1.9.3, backport:
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/nrser/rash/testing.rb', line 143 def (exception, expected, msg = nil, &block) case expected when String assert = :assert_equal when Regexp assert = :assert_match else raise TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}" end ex = assert_raise(exception, *msg) {yield} msg = (msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"} if assert == :assert_equal assert_equal(expected, ex., msg) else msg = (msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.}" } assert expected =~ ex., msg block.binding.eval("proc{|_|$~=_}").call($~) end ex end |