mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
more tightly spec WrappedModule, and ensure WM#source_location doesn't raise
This commit is contained in:
parent
acb2964b3c
commit
37d9e5cbb9
2 changed files with 22 additions and 2 deletions
|
@ -114,10 +114,12 @@ class Pry
|
|||
# cannot be found this method returns `nil`.
|
||||
#
|
||||
# @param [Module] mod The module (or class).
|
||||
# @return [Array<String, Fixnum>] The source location of the
|
||||
# module (or class).
|
||||
# @return [Array<String, Fixnum>, nil] The source location of the
|
||||
# module (or class), or `nil` if no source location found.
|
||||
def source_location
|
||||
@source_location ||= primary_candidate.source_location
|
||||
rescue Pry::RescuableException
|
||||
nil
|
||||
end
|
||||
|
||||
# @return [String, nil] The associated file for the module (i.e
|
||||
|
|
|
@ -23,6 +23,9 @@ describe Pry::WrappedModule do
|
|||
def test6
|
||||
end
|
||||
end
|
||||
|
||||
class ForeverAlone
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,6 +33,10 @@ describe Pry::WrappedModule do
|
|||
it 'should return the correct number of candidates' do
|
||||
Pry::WrappedModule(Host::CandidateTest).number_of_candidates.should == 3
|
||||
end
|
||||
|
||||
it 'should return 0 candidates for a class with no methods and no other definitions' do
|
||||
Pry::WrappedModule(Host::ForeverAlone).number_of_candidates.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "ordering of candidates" do
|
||||
|
@ -50,6 +57,17 @@ describe Pry::WrappedModule do
|
|||
end
|
||||
end
|
||||
|
||||
describe "source_location" do
|
||||
it 'should return primary candidates source_location by default' do
|
||||
wm = Pry::WrappedModule(Host::CandidateTest)
|
||||
wm.source_location.should == wm.candidate(0).source_location
|
||||
end
|
||||
|
||||
it 'should return nil if no source_location can be found' do
|
||||
Pry::WrappedModule(Host::ForeverAlone).source_location.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "source" do
|
||||
it 'should return primary candidates source by default' do
|
||||
wm = Pry::WrappedModule(Host::CandidateTest)
|
||||
|
|
Loading…
Add table
Reference in a new issue