Skip to content

Commit 979e719

Browse files
author
Matthew Kane Parker
committed
Feature: rake license:action_items
1 parent df64a7a commit 979e719

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pkg/*
33
.bundle
44
Gemfile.lock
55
.rvmrc
6-
.idea/*
6+
.idea/*
7+
tmp/

MIT-LICENSE LICENSE

File renamed without changes.

Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ require 'bundler'
22
Bundler::GemHelper.install_tasks
33

44
require 'rspec/core/rake_task'
5+
require 'cucumber'
6+
require 'cucumber/rake/task'
57

68
desc "Run all specs in spec/"
79
RSpec::Core::RakeTask.new(:spec) do |t|
@@ -10,3 +12,10 @@ RSpec::Core::RakeTask.new(:spec) do |t|
1012
t.rspec_opts = %w[--color]
1113
end
1214

15+
16+
desc "Run all cukes in features/"
17+
Cucumber::Rake::Task.new(:features) do |t|
18+
t.cucumber_opts = "features --format pretty"
19+
end
20+
21+
task default: [:spec, :features]
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: rake license:action_items
2+
As a user
3+
I want a rake task "license:action_items" that lists any dependencies with licenses that fall outside of my whitelist
4+
So that I know the limitations of distributing my application
5+
6+
Background:
7+
Given I have a rails application with license finder
8+
9+
Scenario: Application with non-free dependency
10+
Given my rails app depends on a gem "gpl_licensed_gem" licensed with "GPL"
11+
And my rails app depends on a gem "mit_licensed_gem" licensed with "MIT"
12+
And I whitelist the "MIT" license
13+
When I run "bundle exec rake license:action_items"
14+
Then I should see "gpl_licensed_gem" in its output
15+
And I should not see "mit_licensed_gem" in its output

features/step_definitions/steps.rb

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Given /^I have a rails application with license finder$/ do
2+
@user = DSL::User.new
3+
@user.create_rails_app
4+
end
5+
6+
Given /^my rails app depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
7+
@user.add_dependency_to_app gem_name, license
8+
end
9+
10+
Given /^I whitelist the "(.*?)" license$/ do |license|
11+
@user.configure_license_finder_whitelist [license]
12+
end
13+
14+
When /^I run "(.*?)"$/ do |command|
15+
@output = @user.execute_command command
16+
end
17+
18+
Then /^I should see "(.*?)" in its output$/ do |gem_name|
19+
@output.should include gem_name
20+
end
21+
22+
Then /^I should not see "(.*?)" in its output$/ do |gem_name|
23+
@output.should_not include gem_name
24+
end
25+
26+
module DSL
27+
class User
28+
def create_rails_app
29+
reset_sandbox!
30+
31+
`bundle exec rails new #{app_location} --skip-bundle`
32+
33+
Bundler.with_clean_env do
34+
`pushd #{app_location} && echo \"gem 'license_finder', path: '../../'\" >> Gemfile`
35+
end
36+
end
37+
38+
39+
def add_dependency_to_app(gem_name, license)
40+
`mkdir #{sandbox_location}/#{gem_name}`
41+
42+
File.open("#{sandbox_location}/#{gem_name}/#{gem_name}.gemspec", 'w') do |file|
43+
file.write <<-GEMSPEC
44+
Gem::Specification.new do |s|
45+
s.name = "#{gem_name}"
46+
s.version = "0.0.0"
47+
s.author = "Cucumber"
48+
s.summary = "Gem for testing License Finder"
49+
s.license = "#{license}"
50+
end
51+
GEMSPEC
52+
end
53+
54+
Bundler.with_clean_env do
55+
`pushd #{app_location} && echo \"gem '#{gem_name}', path: '../#{gem_name}'\" >> Gemfile && bundle`
56+
end
57+
end
58+
59+
def configure_license_finder_whitelist(whitelisted_licenses=[])
60+
File.open("tmp/my_app/config/license_finder.yml", "w") do |f|
61+
f.write <<-YML
62+
---
63+
whitelist:
64+
#{whitelisted_licenses.map {|l| "- #{l}"}.join("\n")}
65+
YML
66+
end
67+
end
68+
69+
def execute_command(command)
70+
Bundler.with_clean_env do
71+
@output = `cd #{app_location} && bundle exec #{command}`
72+
end
73+
74+
@output
75+
end
76+
77+
private
78+
def app_name
79+
"my_app"
80+
end
81+
82+
def app_location
83+
File.join(sandbox_location, app_name)
84+
end
85+
86+
def sandbox_location
87+
"tmp"
88+
end
89+
90+
def reset_sandbox!
91+
`rm -rf #{sandbox_location}`
92+
`mkdir #{sandbox_location}`
93+
end
94+
end
95+
end

license_finder.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Gem::Specification.new do |s|
22
s.name = "license_finder"
3-
s.version = File.read "VERSION"
4-
s.platform = Gem::Platform::RUBY
3+
s.version = "0.4.0"
54
s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards"]
65
s.email = ["[email protected]"]
76
s.homepage = "https://github.com/pivotal/LicenseFinder"
87
s.summary = "Know your dependencies - and the licenses they are binding your application to."
98
s.description = "Find and display licenses of a project's gem dependencies, so that you know what your limitations are when distributing your application."
109
s.license = "MIT"
1110

12-
%w(rspec rr rake cucumber).each do |gem|
11+
s.add_development_dependency "rails", ">=3"
12+
%w(rspec rr rake cucumber rails).each do |gem|
1313
s.add_development_dependency gem
1414
end
1515

0 commit comments

Comments
 (0)