Sha256: 4d1e908ebded79eeb3951c16efde475c743d4ed3220486e003413806a8e13ebd

Contents?: true

Size: 1.82 KB

Versions: 15

Compression:

Stored size: 1.82 KB

Contents

require File.join(File.dirname(__FILE__), "acceptance_test_helper")
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

15 entries across 15 versions & 5 rubygems

Version Path
floehopper-mocha-0.9.6.20090629164857 test/acceptance/failure_messages_test.rb
floehopper-mocha-0.9.6.20090629165308 test/acceptance/failure_messages_test.rb
floehopper-mocha-0.9.6.20090701111305 test/acceptance/failure_messages_test.rb
floehopper-mocha-0.9.7.20090701124354 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.5.0.1240002286 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.5.0.1240351621 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.5.0.1241126838 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.7.0.1247796736 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.7.20090701124354 test/acceptance/failure_messages_test.rb
jferris-mocha-0.9.7.20090911190113 test/acceptance/failure_messages_test.rb
mocha-macruby-0.9.8.20100129120100 test/acceptance/failure_messages_test.rb
mcmire-mocha-0.9.8 test/acceptance/failure_messages_test.rb
mocha-0.9.8 test/acceptance/failure_messages_test.rb
mocha-0.9.6 test/acceptance/failure_messages_test.rb
mocha-0.9.7 test/acceptance/failure_messages_test.rb