File: assert_raise.rb

package info (click to toggle)
ruby-cutest 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 176 kB
  • sloc: ruby: 376; makefile: 14
file content (45 lines) | stat: -rw-r--r-- 849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
test "catches default exception" do
  assert_raise do
    raise
  end
end

test "catches the right exception" do
  assert_raise(RuntimeError) do
    raise RuntimeError
  end
end

test "catches exceptions lower than StandardError" do
  assert_raise(NotImplementedError) do
    raise NotImplementedError
  end
end

test "raises if nothing raised" do
  assert_raise(Cutest::AssertionFailed) do
    assert_raise {}
  end
end

test "raises if the expectation is not met" do
  assert_raise(Cutest::AssertionFailed) do
    assert_raise(RuntimeError) do
      raise ArgumentError
    end
  end
end

test "returns the exception" do
  exception = assert_raise(RuntimeError) do
    raise RuntimeError, "error"
  end

  assert_equal "error", exception.message
end

test "catches a custom exception" do
  assert_raise do
    raise Class.new(Exception)
  end
end