Skip to content

Commit

Permalink
Fix crash for MethodObjects#{file,line} returning nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jan 15, 2014
1 parent 7c681c2 commit 70a040d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/yardstick/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.documents
# @api private
def self.method_objects
YARD::Registry.all(:method).sort_by do |method_object|
[method_object.file, method_object.line]
[method_object.file || '', method_object.line || 0]

This comment has been minimized.

Copy link
@dkubb

dkubb Jan 16, 2014

Owner

What about doing:

[method_object.file.to_s, method_object.line.to_i]

This comment has been minimized.

Copy link
@mbj

mbj Jan 16, 2014

Author Collaborator

Better.

This comment has been minimized.

Copy link
@mbj

mbj Jan 16, 2014

Author Collaborator

@dkubb Pls note I do a different strategy in followup commits. Just removing the methods objects from report that dont have a source location. For these objects yardstick would crash. No file could be read etc.

end
ensure
YARD::Registry.clear
Expand Down
15 changes: 14 additions & 1 deletion spec/unit/yardstick/parser/class_methods/parse_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
let(:method_object) { double(:file => 'foo.rb', :line => 4, :docstring => docstring) }
let(:docstring) { double('docstring') }

let(:method_objects) { [method_object] }

before do
YARD.should_receive(:parse_string).with('body')
YARD::Registry.stub(:all).with(:method).and_return([method_object])
YARD::Registry.stub(:all).with(:method).and_return(method_objects)
end

it { should be_a(Yardstick::DocumentSet) }
Expand All @@ -25,4 +27,15 @@

its(:docstring) { should eq(docstring) }
end

context 'when method one object does not have file information' do
let(:method_objects) do
[
method_object,
double(:file => nil, :line => nil, :docstring => docstring)
]
end

it { should be_a(Yardstick::DocumentSet) }
end
end

0 comments on commit 70a040d

Please sign in to comment.