Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Feature: rake license:action_items

  • Loading branch information...
commit 979e719c3d8520a9d85fa0fc46d7b9ecba426718 1 parent df64a7a
Matthew Kane Parker authored
View
3  .gitignore
@@ -3,4 +3,5 @@ pkg/*
.bundle
Gemfile.lock
.rvmrc
-.idea/*
+.idea/*
+tmp/
View
0  MIT-LICENSE → LICENSE
File renamed without changes
View
9 Rakefile
@@ -2,6 +2,8 @@ require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
+require 'cucumber'
+require 'cucumber/rake/task'
desc "Run all specs in spec/"
RSpec::Core::RakeTask.new(:spec) do |t|
@@ -10,3 +12,10 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w[--color]
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]
View
15 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
View
95 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
View
6 license_finder.gemspec
@@ -1,7 +1,6 @@
Gem::Specification.new do |s|
s.name = "license_finder"
- s.version = File.read "VERSION"
- s.platform = Gem::Platform::RUBY
+ s.version = "0.4.0"
s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards"]
s.email = ["brent@pivotalabs.com"]
s.homepage = "https://github.com/pivotal/LicenseFinder"
@@ -9,7 +8,8 @@ Gem::Specification.new do |s|
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"
- %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
end
Please sign in to comment.
Something went wrong with that request. Please try again.