diff --git a/.gitignore b/.gitignore index 12aa80c00..2fac402c2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ pkg/* .bundle Gemfile.lock .rvmrc -.idea/* \ No newline at end of file +.idea/* +tmp/ diff --git a/MIT-LICENSE b/LICENSE similarity index 100% rename from MIT-LICENSE rename to LICENSE diff --git a/Rakefile b/Rakefile index bc3b6c8b3..8890bcf84 100644 --- a/Rakefile +++ b/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] diff --git a/features/rake_tasks/action_items.feature b/features/rake_tasks/action_items.feature new file mode 100644 index 000000000..3d397d4e5 --- /dev/null +++ b/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 diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb new file mode 100644 index 000000000..cfaeaff5a --- /dev/null +++ b/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 diff --git a/license_finder.gemspec b/license_finder.gemspec index e8d02e08e..c9d136d0f 100644 --- a/license_finder.gemspec +++ b/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