File: mocha_test_result_test.rb

package info (click to toggle)
ruby-mocha 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,652 kB
  • sloc: ruby: 12,324; javascript: 499; makefile: 14
file content (100 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true

require File.expand_path('../acceptance_test_helper', __FILE__)
require 'execution_point'

class MochaTestResultTest < Mocha::TestCase
  include AcceptanceTestHelper

  def setup
    setup_acceptance_test
  end

  def teardown
    teardown_acceptance_test
  end

  def test_should_include_expectation_verification_in_assertion_count
    test_result = run_as_test do
      object = mock
      object.expects(:message)
      object.message
    end
    assert_equal 1, test_result.assertion_count
  end

  def test_should_not_include_unexpected_invocation_failure_in_assertion_count
    test_result = run_as_test do
      object = mock
      object.message
    end
    assert_equal 0, test_result.assertion_count
  end

  def test_should_include_never_expected_invocation_failure_in_assertion_count
    test_result = run_as_test do
      object = mock
      object.expects(:message).never
      object.message
    end
    assert_equal 1, test_result.assertion_count
  end

  def test_should_include_assertions_in_assertion_count
    test_result = run_as_test do
      assert true
    end
    assert_equal 1, test_result.assertion_count
  end

  def test_should_not_include_stubbing_expectation_verification_in_assertion_count
    test_result = run_as_test do
      object = mock
      object.stubs(:message)
      object.message
    end
    assert_equal 0, test_result.assertion_count
  end

  def test_should_include_expectation_verification_failure_in_failure_count
    test_result = run_as_test do
      object = mock
      object.expects(:message)
    end
    assert_equal 1, test_result.failure_count
  end

  def test_should_include_unexpected_invocation_failure_in_failure_count
    test_result = run_as_test do
      object = mock
      object.message
    end
    assert_equal 1, test_result.failure_count
  end

  def test_should_include_assertion_failure_in_failure_count
    test_result = run_as_test do
      flunk
    end
    assert_equal 1, test_result.failure_count
  end

  def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
    execution_point = nil
    test_result = run_as_test do
      object = mock
      execution_point = ExecutionPoint.current; object.message
    end
    assert_equal 1, test_result.failure_count
    assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
  end

  def est_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
    execution_point = nil
    test_result = run_as_test do
      execution_point = ExecutionPoint.current; flunk
    end
    assert_equal 1, test_result.failure_count
    assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
  end
end