Sha256: 28822e925ffc09aeb28c2ec097debae6fb52166788ba507da685332ae4a18eaf

Contents?: true

Size: 1.51 KB

Versions: 33

Compression:

Stored size: 1.51 KB

Contents

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

class ExceptionRescueTest < Test::Unit::TestCase

  include AcceptanceTest

  def setup
    setup_acceptance_test
  end

  def teardown
    teardown_acceptance_test
  end

  def test_unexpected_invocation_exception_is_not_caught_by_standard_rescue
    test_result = run_as_test do
      mock = mock('mock')
      begin
        mock.some_method
      rescue => e
        flunk "should not rescue #{e.class}"
      end
    end
    assert_failed(test_result)
    assert_equal "unexpected invocation: #<Mock:mock>.some_method()", test_result.failure_message_lines[0]
  end

  def test_invocation_never_expected_exception_is_not_caught_by_standard_rescue
    test_result = run_as_test do
      mock = mock('mock')
      mock.expects(:some_method).never
      begin
        mock.some_method
      rescue => e
        flunk "should not rescue #{e.class}"
      end
    end
    assert_failed(test_result)
    assert_equal "unexpected invocation: #<Mock:mock>.some_method()", test_result.failure_message_lines[0]
  end

  def test_unsatisfied_expectation_exception_is_not_caught_by_standard_rescue
    test_result = run_as_test do
      mock = mock('mock')
      mock.expects(:some_method)
    end
    assert_failed(test_result)
    assert_equal [
      "not all expectations were satisfied",
      "unsatisfied expectations:",
      "- expected exactly once, not yet invoked: #<Mock:mock>.some_method(any_parameters)"
    ], test_result.failure_message_lines
  end
end

Version data entries

33 entries across 28 versions & 3 rubygems

Version Path
mocha-0.12.10 test/acceptance/exception_rescue_test.rb
mocha-0.12.9 test/acceptance/exception_rescue_test.rb
mocha-0.12.8 test/acceptance/exception_rescue_test.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mocha-0.12.3/test/acceptance/exception_rescue_test.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.3/test/acceptance/exception_rescue_test.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-0.8.3 vendor/bundle/gems/mocha-0.12.3/test/acceptance/exception_rescue_test.rb
mocha-0.12.7 test/acceptance/exception_rescue_test.rb
mocha-0.12.6 test/acceptance/exception_rescue_test.rb
mocha-0.12.5 test/acceptance/exception_rescue_test.rb
challah-0.8.1 vendor/bundle/gems/mocha-0.12.3/test/acceptance/exception_rescue_test.rb
mocha-0.12.4 test/acceptance/exception_rescue_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/mocha-0.12.3/test/acceptance/exception_rescue_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-0.8.0.pre vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-0.7.1 vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-0.7.0 vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb
challah-0.7.0.pre2 vendor/bundle/gems/mocha-0.12.2/test/acceptance/exception_rescue_test.rb