Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pry::MethodInfo.gem_root: return gem root instead of ruby root #19

Merged
merged 1 commit into from
Mar 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pry-doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def self.method_host(meth)
# FIXME: this is unnecessarily limited to ext/ and lib/ folders
# @return [String] The root folder of a given gem directory.
def self.gem_root(dir)
dir.split(/\/(?:lib|ext)(?:\/|$)/).first
if index = dir.rindex(/\/(?:lib|ext)(?:\/|$)/)
dir[0..index-1]
end
end

# @param [Method, UnboundMethod] meth The method object.
Expand Down
18 changes: 18 additions & 0 deletions spec/pry-doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,25 @@ def self.my_method; end

lambda { Pry::MethodInfo.aliases(c.method(:my_method)) }.should.not.raise NameError
end
end

describe ".gem_root" do
it "should return the path to the gem" do
path = Pry::WrappedModule.new(Sample).source_location[0]

Pry::MethodInfo.gem_root(path).should ==
File.expand_path("gem_with_cext/gems", direc)
end

it "should not be fooled by a parent 'lib' or 'ext' dir" do
path = "/foo/.rbenv/versions/1.9.3-p429/lib/ruby/gems/"\
"1.9.1/gems/activesupport-4.0.2/lib/active_support/"\
"core_ext/kernel/reporting.rb"

Pry::MethodInfo.gem_root(path).should ==
"/foo/.rbenv/versions/1.9.3-p429/lib/ruby/"\
"gems/1.9.1/gems/activesupport-4.0.2"
end
end

if Pry::Helpers::BaseHelpers.mri_18?
Expand Down