Skip to content

Commit

Permalink
Works for objects with missing/pathalogical inspect methods Fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCheek committed Feb 28, 2014
1 parent a968813 commit 3beb5da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/seeing_is_believing/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def initialize(array = [], max_number_of_captures=Float::INFINITY)
end

def record_result(value)
inspected = value.inspect # only invoke inspect once, b/c the inspection may be recorded
begin
inspected = value.inspect.to_str # only invoke inspect once, b/c the inspection may be recorded
rescue NoMethodError
inspected = "#<no inspect available>"
end

if size < @max_number_of_captures then @array << inspected
elsif size == @max_number_of_captures then @array << '...'
end
Expand Down
13 changes: 13 additions & 0 deletions spec/line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ def line_for(*args)
line.inspect.should == '#<SIB:Line[] (0, 0) RuntimeError:"omg">'
end

it "doesn't blow up when there is no #inspect available e.g. BasicObject" do
obj = BasicObject.new
line_for(obj).inspect.should == '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
end

it "doesn't blow up when #inspect returns a not-String (e.g. pathalogical libraries like FactoryGirl)" do
obj = BasicObject.new
def obj.inspect
nil
end
line_for(obj).inspect.should == '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
end

it 'knows when it has an exception' do
exception = RuntimeError.new 'omg'
line = Line.new
Expand Down

0 comments on commit 3beb5da

Please sign in to comment.