Sha256: dd119fd100e0a5e1e7a78e7d829afa44eb85080a8addd6465f7c2abfefb5db5b

Contents?: true

Size: 1.79 KB

Versions: 33

Compression:

Stored size: 1.79 KB

Contents

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

class FailureMessagesTest < Test::Unit::TestCase

  OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'

  include AcceptanceTest

  def setup
    setup_acceptance_test
  end

  def teardown
    teardown_acceptance_test
  end

  class Foo; end

  def test_should_display_class_name_when_expectation_was_on_class
    test_result = run_as_test do
      Foo.expects(:bar)
    end
    assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
  end

  def test_should_display_class_name_and_address_when_expectation_was_on_instance
    test_result = run_as_test do
      Foo.new.expects(:bar)
    end
    assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
  end

  def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
    test_result = run_as_test do
      Foo.any_instance.expects(:bar)
    end
    assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
  end

  def test_should_display_mock_name_when_expectation_was_on_named_mock
    test_result = run_as_test do
      foo = mock('foo')
      foo.expects(:bar)
    end
    assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
  end

  def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
    test_result = run_as_test do
      foo = mock()
      foo.expects(:bar)
    end
    assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
  end

  def test_should_display_string_when_expectation_was_on_string
    test_result = run_as_test do
      'Foo'.expects(:bar)
    end
    assert_match Regexp.new("'Foo'"), test_result.failures[0].message
  end

end

Version data entries

33 entries across 28 versions & 3 rubygems

Version Path
mocha-0.12.3 test/acceptance/failure_messages_test.rb
challah-0.7.0.pre vendor/bundle/gems/mocha-0.12.2/test/acceptance/failure_messages_test.rb
mocha-0.12.2 test/acceptance/failure_messages_test.rb
mocha-0.12.1 test/acceptance/failure_messages_test.rb
mocha-0.12.0 test/acceptance/failure_messages_test.rb
challah-0.6.2 vendor/bundle/gems/mocha-0.11.4/test/acceptance/failure_messages_test.rb
challah-0.6.1 vendor/bundle/gems/mocha-0.11.4/test/acceptance/failure_messages_test.rb
challah-0.6.0 vendor/bundle/gems/mocha-0.11.4/test/acceptance/failure_messages_test.rb
mocha-0.11.4 test/acceptance/failure_messages_test.rb
mocha-0.11.3 test/acceptance/failure_messages_test.rb
mocha-0.11.2 test/acceptance/failure_messages_test.rb
mocha-0.11.1 test/acceptance/failure_messages_test.rb
mocha-0.11.0 test/acceptance/failure_messages_test.rb