Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

show gem parents and children in html report

  • Loading branch information...
commit 58597a86a7a04f24df2375cd9f1f9fb9f634ec03 1 parent 389597a
Matthew Kane Parker and Paul Meskers authored
View
10 features/html_report.feature
@@ -36,3 +36,13 @@ Feature: HTML Report
And I should see "1 unapproved" in the html
# gpl_licensed_gem
And I should see "1 GPL" in the html
+
+ Scenario: Implicit dependencies list their parent dependencies
+ Given I have a rails app with license finder
+ When I run "license_finder"
+ Then I should see the "activerecord" in the html with the following details:
+ | parent |
+ | rails |
+ And I should see "rails" in the html with the following details:
+ | children |
+ | activerecord |
View
2  features/step_definitions/steps.rb
@@ -104,7 +104,7 @@
gpl_gem[:class].should == css_class
end
-Then /^I should see the "([^"]*)" in the html with the following details:$/ do |gem_name, table|
+Then /^I should see (?:the )?"([^"]*)" in the html with the following details:$/ do |gem_name, table|
html = File.read(@user.dependencies_html_path)
page = Capybara.string(html)
section = page.find("##{gem_name}")
View
3  lib/license_finder/bundled_gem.rb
@@ -31,7 +31,8 @@ def to_dependency
'bundler_groups' => (@bundler_dependency.groups if @bundler_dependency),
'summary' => @spec.summary,
'description' => @spec.description,
- 'homepage' => @spec.homepage
+ 'homepage' => @spec.homepage,
+ 'children' => @spec.dependencies
)
end
View
26 lib/license_finder/dependency.rb
@@ -4,7 +4,7 @@
module LicenseFinder
class Dependency
attr_accessor :name, :version, :license, :approved, :license_url, :notes, :license_files,
- :readme_files, :source, :bundler_groups, :homepage
+ :readme_files, :source, :bundler_groups, :homepage, :children, :parents
attr_reader :summary, :description
@@ -28,6 +28,8 @@ def initialize(attributes = {})
@summary = attributes['summary']
@description = attributes['description']
@homepage = attributes['homepage']
+ @children = attributes.fetch('children', [])
+ @parents = attributes.fetch('parents', [])
end
def license_url
@@ -48,7 +50,9 @@ def merge(other)
'summary' => other.summary,
'description' => other.description,
'bundler_groups' => other.bundler_groups,
- 'homepage' => other.homepage
+ 'homepage' => other.homepage,
+ 'children' => other.children,
+ 'parents' => other.parents
)
case other.license
@@ -135,6 +139,24 @@ def to_html
</tr>
</tbody>
</table>
+
+ <% if parents.any? %>
+ <dl>
+ <dt>Parents</dt>
+ <% parents.each do |parent| %>
+ <dd><%= parent.name %></dd>
+ <% end %>
+ </dl>
+ <% end %>
+
+ <% if children.any? %>
+ <dl>
+ <dt>Children</dt>
+ <% children.each do |child| %>
+ <dd><%= child.name %></dd>
+ <% end %>
+ </dl>
+ <% end %>
</div>
ERB
View
10 lib/license_finder/dependency_list.rb
@@ -5,7 +5,15 @@ class DependencyList
attr_reader :dependencies
def self.from_bundler
- new(Bundle.new.gems.map(&:to_dependency))
+ dep_list = new(Bundle.new.gems.map(&:to_dependency))
+ dep_list.dependencies.each do |dep|
+ dep.children.each do |child_dep|
+ dep_list.dependencies.select { |d| d.name == child_dep.name }.each do |found_child|
+ found_child.parents << dep
+ end
+ end
+ end
+ dep_list
end
def self.from_yaml(yaml)
View
24 spec/lib/license_finder/dependency_list_spec.rb
@@ -1,12 +1,16 @@
require 'spec_helper'
describe LicenseFinder::DependencyList do
- def build_gemspec(name, version)
+ def build_gemspec(name, version, dependency=nil)
Gem::Specification.new do |s|
s.name = name
s.version = version
s.summary = 'summary'
s.description = 'description'
+
+ if dependency
+ s.add_dependency dependency
+ end
end
end
@@ -37,6 +41,24 @@ def build_gemspec(name, version)
subject.dependencies[1].name.should == 'gem2'
subject.dependencies[1].version.should == '0.4.2'
end
+
+ context "when initialized with a parent and child gem" do
+ subject do
+ bundle = stub(Bundler::Definition).build.stub!
+ bundle.dependencies { [] }
+ bundle.groups { [] }
+ bundle.specs_for { [build_gemspec('gem1', '1.2.3', 'gem2'), build_gemspec('gem2', '0.4.2')] }
+
+ LicenseFinder::DependencyList.from_bundler
+ end
+
+ it "should update the child dependency with its parent data" do
+ gem1 = subject.dependencies.first
+ gem2 = subject.dependencies.last
+
+ gem2.parents.should == [gem1]
+ end
+ end
end
describe '#from_yaml' do
View
27 spec/lib/license_finder/dependency_spec.rb
@@ -146,6 +146,33 @@
end
end
+
+ context "when the gem has at least one parent" do
+ before { dependency.parents = [ OpenStruct.new(:name => "foo parent") ]}
+ it "should include a parents section" do
+ should include "Parents"
+ end
+ end
+
+ context "when the gem has no parents" do
+ it "should not include any parents section in the output" do
+ should_not include "Parents"
+ end
+ end
+
+ context "when the gem has at least one child" do
+ before { dependency.children = [ OpenStruct.new(:name => "foo child") ]}
+
+ it "should include a Children section" do
+ should include "Children"
+ end
+ end
+
+ context "when the gem has no children" do
+ it "should not include any Children section in the output" do
+ should_not include "Children"
+ end
+ end
end
describe '#source' do
Please sign in to comment.
Something went wrong with that request. Please try again.