Class: NRSER::Rash::Testing::FunctionTestCase

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/nrser/rash/testing.rb

Defined Under Namespace

Classes: Raises

Instance Method Summary collapse

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
        assert_raise_with_message(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 assert_raise_with_message(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 = message(msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"}

  if assert == :assert_equal
    assert_equal(expected, ex.message, msg)
  else
    msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.message}" }
    assert expected =~ ex.message, msg
    block.binding.eval("proc{|_|$~=_}").call($~)
  end
  ex
end

#raises(cls, msg = nil) ⇒ Object



118
119
120
# File 'lib/nrser/rash/testing.rb', line 118

def raises cls, msg = nil
  Raises.new cls, msg
end