Sha256: 844015c399ca369647bb2368021fbbca779fdd5deddf2eba306b5abee2ec4ae2

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

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

class ObjectInspectTest < Mocha::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 Mocha::PRE_RUBY_V19
    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

6 entries across 6 versions & 1 rubygems

Version Path
mocha-1.6.0 test/unit/object_inspect_test.rb
mocha-1.5.0 test/unit/object_inspect_test.rb
mocha-1.4.0 test/unit/object_inspect_test.rb
mocha-1.3.0 test/unit/object_inspect_test.rb
mocha-1.2.1 test/unit/object_inspect_test.rb
mocha-1.2.0 test/unit/object_inspect_test.rb