Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Kane Parker
committed
Sep 7, 2012
1 parent
df64a7a
commit 979e719
Showing
6 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -3,4 +3,5 @@ pkg/* | ||
.bundle | .bundle | ||
Gemfile.lock | Gemfile.lock | ||
.rvmrc | .rvmrc | ||
.idea/* | .idea/* | ||
tmp/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters