File: hooks_test.rb

package info (click to toggle)
ruby-mocha 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: ruby: 12,324; javascript: 499; makefile: 14
file content (37 lines) | stat: -rw-r--r-- 880 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
# frozen_string_literal: true

require File.expand_path('../../test_helper', __FILE__)
require 'mocha/hooks'
require 'mocha/mockery'

class HooksTest < Mocha::TestCase
  # rubocop:disable Style/ClassAndModuleChildren
  class Mocha::Mockery
    class << self
      attr_writer :instances
    end
  end
  # rubocop:enable Style/ClassAndModuleChildren

  class FakeMockery
    def verify(*args); end

    def teardown(_origin = nil)
      raise 'exception within Mockery#teardown'
    end
  end

  def test_ensure_mockery_instance_is_reset_even_when_an_exception_is_raised_in_mockery_teardown
    fake_test_case = Object.new.extend(Mocha::Hooks)
    mockery = FakeMockery.new
    Mocha::Mockery.instances = [mockery]

    begin
      fake_test_case.mocha_teardown
    rescue StandardError
      nil
    end

    assert_kind_of Mocha::Mockery::Null, Mocha::Mockery.instance
  end
end