Browse files

Make `Expectation#inspect` less verbose and more useful. Fixes #122.

  • Loading branch information...
1 parent 03a8c01 commit b16ed30a9923ae52322d5bb44a010692d3e9ed62 @floehopper floehopper committed Jan 4, 2013
Showing with 24 additions and 0 deletions.
  1. +7 −0 lib/mocha/expectation.rb
  2. +17 −0 test/unit/expectation_test.rb
View
7 lib/mocha/expectation.rb
@@ -581,6 +581,13 @@ def used?
end
# @private
+ def inspect
+ address = __id__ * 2
+ address += 0x100000000 if address < 0
+ "#<Expectation:0x#{'%x' % address} #{mocha_inspect} >"
+ end
+
+ # @private
def mocha_inspect
message = "#{@cardinality.mocha_inspect}, "
message << case @invocation_count
View
17 test/unit/expectation_test.rb
@@ -477,4 +477,21 @@ def test_should_match_when_state_is_active
assert expectation.match?(:method_one)
end
+ def test_should_include_default_representation_of_object_in_inspect
+ object = Object.new
+ class << object
+ define_method(:inspect) { 'mock' }
+ end
+ expectation = Expectation.new(object, :method_one)
+ assert_match Regexp.new("^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$"), expectation.inspect
+ end
+
+ def test_should_include_output_of_mocha_inspect_in_inspect
+ object = Object.new
+ class << object
+ define_method(:inspect) { 'mock' }
+ end
+ expectation = Expectation.new(object, :method_one)
+ assert expectation.inspect.include?(expectation.mocha_inspect)
+ end
end

0 comments on commit b16ed30

Please sign in to comment.