Skip to content

Commit

Permalink
Make Expectation#inspect less verbose and more useful. Fixes freera…
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Jan 4, 2013
1 parent 03a8c01 commit b16ed30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/mocha/expectation.rb
Expand Up @@ -580,6 +580,13 @@ def used?
@cardinality.used?(@invocation_count)
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}, "
Expand Down
17 changes: 17 additions & 0 deletions test/unit/expectation_test.rb
Expand Up @@ -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.