File: utils_test.rb

package info (click to toggle)
ruby-minitest-utils 0.2.4%2Bdebian-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 156 kB
  • ctags: 55
  • sloc: ruby: 355; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'test_helper'

class MinitestUtilsTest < Minitest::Test
  def capture_exception
    yield
  rescue Exception => exception
    exception
  end

  test 'defines method name' do
    assert MinitestUtilsTest.instance_methods.include?(:test_defines_method_name)
  end

  test 'improves assert message' do
    exception = capture_exception { assert nil }
    assert_equal "expected: truthy value\ngot: nil", exception.message
  end

  test 'improves refute message' do
    exception = capture_exception { refute 1234 }
    assert_equal "expected: falsy value\ngot: 1234", exception.message
  end

  test 'raises exception for duplicated method name' do
    assert_raises(RuntimeError) {
      Class.new(Minitest::Test) do
        test 'some test'
        test 'some test'
      end
    }
  end

  test 'flunks method without block' do
    test_case = Class.new(Minitest::Test) do
      test 'flunk test'
    end

    assert_raises(Minitest::Assertion) {
      test_case.new('test').test_flunk_test
    }
  end

  test 'defines setup steps' do
    setups = []

    test_case = Class.new(Minitest::Test) do
      setup { setups << 1 }
      setup { setups << 2 }
      setup { setups << 3 }

      test('do something') {}
    end

    test_case.new(Minitest::AbstractReporter).run

    assert_equal [1, 2, 3], setups
  end

  test 'defines teardown steps' do
    teardowns = []

    test_case = Class.new(Minitest::Test) do
      teardown { teardowns << 1 }
      teardown { teardowns << 2 }
      teardown { teardowns << 3 }

      test('do something') {}
    end

    test_case.new(Minitest::AbstractReporter).run

    assert_equal [1, 2, 3], teardowns
  end
end