Skip to content

Commit

Permalink
Feature: rake license:action_items
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Kane Parker committed Sep 7, 2012
1 parent df64a7a commit 979e719
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,5 @@ pkg/*
.bundle .bundle
Gemfile.lock Gemfile.lock
.rvmrc .rvmrc
.idea/* .idea/*
tmp/
File renamed without changes.
9 changes: 9 additions & 0 deletions Rakefile
Expand Up @@ -2,6 +2,8 @@ require 'bundler'
Bundler::GemHelper.install_tasks Bundler::GemHelper.install_tasks


require 'rspec/core/rake_task' require 'rspec/core/rake_task'
require 'cucumber'
require 'cucumber/rake/task'


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



desc "Run all cukes in features/"
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end

task default: [:spec, :features]
15 changes: 15 additions & 0 deletions features/rake_tasks/action_items.feature
@@ -0,0 +1,15 @@
Feature: rake license:action_items
As a user
I want a rake task "license:action_items" that lists any dependencies with licenses that fall outside of my whitelist
So that I know the limitations of distributing my application

Background:
Given I have a rails application with license finder

Scenario: Application with non-free dependency
Given my rails app depends on a gem "gpl_licensed_gem" licensed with "GPL"
And my rails app depends on a gem "mit_licensed_gem" licensed with "MIT"
And I whitelist the "MIT" license
When I run "bundle exec rake license:action_items"
Then I should see "gpl_licensed_gem" in its output
And I should not see "mit_licensed_gem" in its output
95 changes: 95 additions & 0 deletions features/step_definitions/steps.rb
@@ -0,0 +1,95 @@
Given /^I have a rails application with license finder$/ do
@user = DSL::User.new
@user.create_rails_app
end

Given /^my rails app depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
@user.add_dependency_to_app gem_name, license
end

Given /^I whitelist the "(.*?)" license$/ do |license|
@user.configure_license_finder_whitelist [license]
end

When /^I run "(.*?)"$/ do |command|
@output = @user.execute_command command
end

Then /^I should see "(.*?)" in its output$/ do |gem_name|
@output.should include gem_name
end

Then /^I should not see "(.*?)" in its output$/ do |gem_name|
@output.should_not include gem_name
end

module DSL
class User
def create_rails_app
reset_sandbox!

`bundle exec rails new #{app_location} --skip-bundle`

Bundler.with_clean_env do
`pushd #{app_location} && echo \"gem 'license_finder', path: '../../'\" >> Gemfile`
end
end


def add_dependency_to_app(gem_name, license)
`mkdir #{sandbox_location}/#{gem_name}`

File.open("#{sandbox_location}/#{gem_name}/#{gem_name}.gemspec", 'w') do |file|
file.write <<-GEMSPEC
Gem::Specification.new do |s|
s.name = "#{gem_name}"
s.version = "0.0.0"
s.author = "Cucumber"
s.summary = "Gem for testing License Finder"
s.license = "#{license}"
end
GEMSPEC
end

Bundler.with_clean_env do
`pushd #{app_location} && echo \"gem '#{gem_name}', path: '../#{gem_name}'\" >> Gemfile && bundle`
end
end

def configure_license_finder_whitelist(whitelisted_licenses=[])
File.open("tmp/my_app/config/license_finder.yml", "w") do |f|
f.write <<-YML
---
whitelist:
#{whitelisted_licenses.map {|l| "- #{l}"}.join("\n")}
YML
end
end

def execute_command(command)
Bundler.with_clean_env do
@output = `cd #{app_location} && bundle exec #{command}`
end

@output
end

private
def app_name
"my_app"
end

def app_location
File.join(sandbox_location, app_name)
end

def sandbox_location
"tmp"
end

def reset_sandbox!
`rm -rf #{sandbox_location}`
`mkdir #{sandbox_location}`
end
end
end
6 changes: 3 additions & 3 deletions license_finder.gemspec
@@ -1,15 +1,15 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "license_finder" s.name = "license_finder"
s.version = File.read "VERSION" s.version = "0.4.0"
s.platform = Gem::Platform::RUBY
s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards"] s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards"]
s.email = ["brent@pivotalabs.com"] s.email = ["brent@pivotalabs.com"]
s.homepage = "https://github.com/pivotal/LicenseFinder" s.homepage = "https://github.com/pivotal/LicenseFinder"
s.summary = "Know your dependencies - and the licenses they are binding your application to." s.summary = "Know your dependencies - and the licenses they are binding your application to."
s.description = "Find and display licenses of a project's gem dependencies, so that you know what your limitations are when distributing your application." s.description = "Find and display licenses of a project's gem dependencies, so that you know what your limitations are when distributing your application."
s.license = "MIT" s.license = "MIT"


%w(rspec rr rake cucumber).each do |gem| s.add_development_dependency "rails", ">=3"
%w(rspec rr rake cucumber rails).each do |gem|
s.add_development_dependency gem s.add_development_dependency gem
end end


Expand Down

0 comments on commit 979e719

Please sign in to comment.