Sha256: 29eb15ee642bc0c0f9fae0a4c7b8c27146542647d8fc45105a08c61bafd1c23a

Contents?: true

Size: 1.26 KB

Versions: 44

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path('../../test_helper', __FILE__)
require 'mocha/inspect'
require 'method_definer'

class ObjectInspectTest < Test::Unit::TestCase

  def test_should_return_default_string_representation_of_object_not_including_instance_variables
    object = Object.new
    class << object
      attr_accessor :attribute
    end
    object.attribute = 'instance_variable'
    assert_match Regexp.new("^#<Object:0x[0-9A-Fa-f]{1,8}.*>$"), object.mocha_inspect
    assert_no_match(/instance_variable/, object.mocha_inspect)
  end

  def test_should_return_customized_string_representation_of_object
    object = Object.new
    class << object
      define_method(:inspect) { 'custom_inspect' }
    end
    assert_equal 'custom_inspect', object.mocha_inspect
  end

  def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
    calls = []
    object = Object.new
    object.replace_instance_method(:id) { calls << :id; return 1 } if RUBY_VERSION < '1.9'
    object.replace_instance_method(:object_id) { calls << :object_id; return 1 }
    object.replace_instance_method(:__id__) { calls << :__id__; return 1 }
    object.replace_instance_method(:inspect) { "object-description" }

    object.mocha_inspect

    assert_equal [:__id__], calls.uniq
  end

end

Version data entries

44 entries across 36 versions & 3 rubygems

Version Path
mocha-0.12.6 test/unit/object_inspect_test.rb
mocha-0.12.5 test/unit/object_inspect_test.rb
challah-0.8.1 vendor/bundle/gems/mocha-0.12.3/test/unit/object_inspect_test.rb
mocha-0.12.4 test/unit/object_inspect_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
challah-rolls-0.1.0 vendor/bundle/gems/mocha-0.12.3/test/unit/object_inspect_test.rb
challah-0.8.0.pre vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
challah-0.7.1 vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
challah-0.7.0 vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
challah-0.7.0.pre2 vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
mocha-0.12.3 test/unit/object_inspect_test.rb
challah-0.7.0.pre vendor/bundle/gems/mocha-0.12.2/test/unit/object_inspect_test.rb
mocha-0.12.2 test/unit/object_inspect_test.rb
mocha-0.12.1 test/unit/object_inspect_test.rb
mocha-0.12.0 test/unit/object_inspect_test.rb
challah-0.6.2 vendor/bundle/gems/mocha-0.11.4/test/unit/object_inspect_test.rb
challah-0.6.1 vendor/bundle/gems/mocha-0.11.4/test/unit/object_inspect_test.rb
challah-0.6.0 vendor/bundle/gems/mocha-0.11.4/test/unit/object_inspect_test.rb
mocha-0.11.4 test/unit/object_inspect_test.rb