license_finder 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.travis.yml +22 -0
  2. data/README.markdown +56 -92
  3. data/Rakefile +1 -1
  4. data/bin/license_finder +1 -1
  5. data/features/approve_dependencies.feature +49 -0
  6. data/features/html_report.feature +48 -0
  7. data/features/license_finder.feature +36 -0
  8. data/features/license_finder_rake_task.feature +36 -0
  9. data/features/rails_rake.feature +9 -0
  10. data/features/step_definitions/steps.rb +78 -31
  11. data/features/text_report.feature +27 -0
  12. data/lib/{templates/Apache.txt → data/licenses/Apache2.txt} +0 -0
  13. data/lib/{templates → data/licenses}/BSD.txt +0 -0
  14. data/lib/{templates → data/licenses}/GPLv2.txt +0 -0
  15. data/lib/{templates → data/licenses}/ISC.txt +0 -0
  16. data/lib/{templates → data/licenses}/LGPL.txt +0 -0
  17. data/lib/{templates → data/licenses}/MIT.txt +0 -0
  18. data/lib/{templates → data/licenses}/NewBSD.txt +0 -0
  19. data/lib/{templates → data/licenses}/Ruby.txt +0 -0
  20. data/lib/{templates → data/licenses}/SimplifiedBSD.txt +0 -0
  21. data/lib/license_finder.rb +11 -32
  22. data/lib/license_finder/bundle.rb +33 -0
  23. data/lib/license_finder/bundled_gem.rb +20 -14
  24. data/lib/license_finder/cli.rb +4 -3
  25. data/lib/license_finder/configuration.rb +34 -0
  26. data/lib/license_finder/dependency.rb +27 -22
  27. data/lib/license_finder/dependency_list.rb +35 -13
  28. data/lib/license_finder/license.rb +11 -1
  29. data/lib/license_finder/license/apache2.rb +8 -0
  30. data/lib/license_finder/license/bsd.rb +2 -0
  31. data/lib/license_finder/license/gplv2.rb +2 -0
  32. data/lib/license_finder/license/isc.rb +1 -0
  33. data/lib/license_finder/license/lgpl.rb +1 -0
  34. data/lib/license_finder/license/mit.rb +4 -1
  35. data/lib/license_finder/license/new_bsd.rb +3 -0
  36. data/lib/license_finder/license/ruby.rb +2 -2
  37. data/lib/license_finder/license/simplified_bsd.rb +3 -0
  38. data/lib/license_finder/license_url.rb +10 -0
  39. data/lib/license_finder/possible_license_file.rb +2 -2
  40. data/lib/license_finder/railtie.rb +1 -3
  41. data/lib/license_finder/reporter.rb +51 -0
  42. data/lib/license_finder/viewable.rb +31 -0
  43. data/lib/tasks/license_finder.rake +3 -28
  44. data/lib/templates/dependency.html.erb +54 -0
  45. data/lib/templates/dependency_list.html.erb +38 -0
  46. data/license_finder.gemspec +12 -4
  47. data/spec/lib/license_finder/bundled_gem_spec.rb +5 -3
  48. data/spec/lib/license_finder/dependency_list_spec.rb +54 -9
  49. data/spec/lib/license_finder/dependency_spec.rb +93 -57
  50. data/spec/lib/license_finder/license/apache_spec.rb +2 -2
  51. data/spec/lib/license_finder/license/mit_spec.rb +1 -1
  52. data/spec/lib/license_finder/license_spec.rb +14 -0
  53. data/spec/lib/license_finder/license_url_spec.rb +20 -0
  54. data/spec/lib/license_finder/reporter_spec.rb +5 -0
  55. data/spec/lib/license_finder_spec.rb +2 -0
  56. data/spec/spec_helper.rb +0 -1
  57. data/spec/support/license_examples.rb +6 -0
  58. metadata +68 -33
  59. data/features/executables/license_finder.feature +0 -19
  60. data/features/rake_tasks/action_items.feature +0 -27
  61. data/features/rake_tasks/action_items_ok.feature +0 -23
  62. data/features/rake_tasks/generate_dependencies.feature +0 -62
  63. data/features/rake_tasks/init.feature +0 -26
  64. data/features/rake_tasks/regressions.feature +0 -18
  65. data/lib/license_finder/bundler_dependency_query.rb +0 -51
  66. data/lib/license_finder/finder.rb +0 -39
  67. data/lib/license_finder/license/apache.rb +0 -5
  68. data/spec/lib/license_finder/finder_spec.rb +0 -36
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 1.9.2
4
+ - jruby-18mode
5
+ - jruby-19mode
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+ - 1.8.7
11
+ - ree
12
+
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-18mode
16
+ - rvm: jruby-19mode
17
+ - rvm: rbx-18mode
18
+ - rvm: rbx-19mode
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - rvm: 1.8.7
22
+ - rvm: ree
data/README.markdown CHANGED
@@ -1,38 +1,61 @@
1
1
  # License Finder
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/pivotal/LicenseFinder.png)](http://travis-ci.org/pivotal/LicenseFinder)
4
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/pivotal/LicenseFinder)
4
5
 
5
6
  With bundler it's easy for your project to depend on many gems. This decomposition is nice, but managing licenses becomes difficult. This tool gathers info about the licenses of the gems in your project.
6
7
 
7
8
  ## Installation
8
- =====
9
9
 
10
10
  Add license_finder to your Rails project's Gemfile and `bundle`:
11
11
 
12
12
  ```ruby
13
- gem 'license_finder', :git => "https://github.com/pivotal/LicenseFinder.git"
13
+ gem 'license_finder'
14
14
  ```
15
15
 
16
- Now, initialize license finder:
16
+ ## Usage
17
+
18
+ License finder will generate reports of action items - i.e., dependencies that do not fall within your license "whitelist".
17
19
 
18
20
  ```sh
19
- $ bundle exec rake license:init
21
+ $ bundle exec license_finder
20
22
  ```
21
23
 
22
- This will create a `config/license_finder.yml` file that lets you configure license finder.
23
- This is where you should add licenses which are allowed on the project, so they will be automatically approved.
24
+ The first time you run this, `license_finder` will create a default configuration file `./config/license_finder.yml`:
24
25
 
25
- ## Usage
26
26
 
27
- Once you've whitelisted licenses, you can then tell license finder to analyze your Gemfile and generate a list of
28
- dependencies that have non-whitelisted licenses:
27
+ ```yaml
28
+ ---
29
+ whitelist:
30
+ #- MIT
31
+ #- Apache 2.0
32
+ ignore_groups:
33
+ #- test
34
+ #- development
35
+ ```
36
+
37
+ This allows you to configure bundler groups and add licenses to the whitelist.
29
38
 
30
- ```sh
31
- $ bundle exec rake license:action_items
39
+ On a brand new Rails project, you could expect `license_finder` to output something like the following
40
+ (assuming you whitelisted the MIT license in your `config/license_finder.yml`):
41
+
42
+ ```
43
+ Dependencies that need approval:
44
+
45
+ highline, 1.6.14, ruby
46
+ json, 1.7.5, ruby
47
+ mime-types, 1.19, ruby
48
+ rails, 3.2.8, other
49
+ rdoc, 3.12, other
50
+ rubyzip, 0.9.9, ruby
51
+ xml-simple, 1.1.1, other
32
52
  ```
33
53
 
34
- This will write out a dependencies.yml and dependencies.txt file in the root of your project, as well as
35
- output a list of unapproved dependencies to the console. It will also return a non-zero exit status if there
54
+ The executable task will also write out a dependencies.yml, dependencies.txt, and dependencies.html file in the root of your project.
55
+
56
+ The latter two files are human readable reports that you could send to your non-technical business partners, lawyers, etc.
57
+
58
+ `license_finder` will also return a non-zero exit status if there are
36
59
  unapproved dependencies. You could use this in a CI build, for example, to alert you whenever someone adds an
37
60
  unapproved dependency to the project.
38
61
 
@@ -41,15 +64,15 @@ and then edited the resulting file).
41
64
 
42
65
  ### Manually approving dependencies
43
66
 
44
- Whenever you have a dependency that falls outside of your whitelist, `rake license:action_items` will tell you.
67
+ Whenever you have a dependency that falls outside of your whitelist, `license_finder` will tell you.
45
68
  If your business decides that this is an acceptable risk, you can manually approve the dependency by finding its
46
69
  section in the `dependencies.yml` file and setting its `approved` attribute to true. For example, lets assume you've only
47
70
  whitelisted the "MIT" license in your `config/license_finder.yml`. You then add the 'awesome_gpl_gem' to your Gemfile,
48
- which we'll assume is licensed with the `GPL` license. You then run `rake license_finder:action_items` and see
71
+ which we'll assume is licensed with the `GPL` license. You then run `license_finder` and see
49
72
  the gem listed in the output:
50
73
 
51
74
  ```txt
52
- awesome_gpl_gem 1.0.0, GPL
75
+ awesome_gpl_gem, 1.0.0, GPL
53
76
  ```
54
77
 
55
78
  Your business tells you that in this case, it's acceptable to use this gem. You should now update your `dependencies.yml`
@@ -62,7 +85,7 @@ file, setting the `approved` attribute to `true` for the `awesome_gpl_gem` secti
62
85
  approved: true
63
86
  ```
64
87
 
65
- If you rerun `rake license:action_items`, you should no longer see `awesome_gpl_gem` in the output.
88
+ If you rerun `license_finder`, you should no longer see `awesome_gpl_gem` in the output.
66
89
 
67
90
 
68
91
  ## Manually managing Javascript Dependencies
@@ -82,89 +105,26 @@ You could then update the "approved" attribute to true once you have signoff fro
82
105
  remember any manually added licenses between successive runs.
83
106
 
84
107
 
85
- ## Usage outside Rails
86
-
87
- As a standalone script:
88
-
89
- ```sh
90
- $ git clone http://github.com/pivotal/LicenseFinder.git license_finder
91
- $ cd /path/to/your/project
92
- $ /path/to/license_finder/bin/license_finder
93
- ```
94
-
95
- Optionally add `--with-licenses` to include the full text of the licenses in the output.
96
-
108
+ ## Usage with Rake
97
109
 
98
- ## Sample Output
110
+ First, add license finder to your project's Gemfile:
99
111
 
100
- File: `config/license_finder.yml`:
101
-
102
- ```yaml
103
- ---
104
- whitelist:
105
- - MIT
106
- - Apache 2.0
107
- ignore_groups:
108
- - test
109
- - development
112
+ ```ruby
113
+ gem "license_finder"
110
114
  ```
111
115
 
112
- File: `dependencies.yml`:
113
-
114
- ```yaml
115
- ---
116
- - name: "json_pure"
117
- version: "1.5.1"
118
- license: "other"
119
- approved: false
116
+ Next, update your project's Rakefile with the license finder rake task:
120
117
 
121
- - name: "rake"
122
- version: "0.8.7"
123
- license: "MIT"
124
- approved: true
118
+ ```ruby
119
+ require 'bundler/setup'
120
+ require 'license_finder'
121
+ LicenseFinder.load_rake_tasks
125
122
  ```
126
123
 
127
- File: `dependencies.txt`:
128
-
129
- json_pure 1.5.1, other
130
- rake 0.8.7, MIT
124
+ You can now run `bundle exec rake license_finder`. This is the equivalent of running `bundle exec license_finder`.
131
125
 
132
- File: `bin/license_finder`:
133
-
134
- ```yaml
135
- ---
136
- json_pure 1.5.1:
137
- dependency_name: json_pure
138
- dependency_version: 1.5.1
139
- install_path: /some/path/.rvm/gems/ruby-1.9.2-p180/gems/json_pure-1.5.1
140
- license_files:
141
- - file_name: COPYING
142
- header_type: other
143
- body_type: other
144
- disclaimer_of_liability: other
145
- - file_name: COPYING-json-jruby
146
- header_type: other
147
- body_type: other
148
- disclaimer_of_liability: other
149
- readme_files:
150
- - file_name: README
151
- mentions_license: true
152
- - file_name: README-json-jruby.markdown
153
- mentions_license: false
154
- ---
155
- rake 0.8.7:
156
- dependency_name: rake
157
- dependency_version: 0.8.7
158
- install_path: /some/path/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7
159
- license_files:
160
- - file_name: MIT-LICENSE
161
- header_type: other
162
- body_type: mit
163
- disclaimer_of_liability: "mit: THE AUTHORS OR COPYRIGHT HOLDERS"
164
- readme_files:
165
- - file_name: README
166
- mentions_license: true
167
- ```
126
+ This could be handy if you have a build for CI that you want to break when you have unapproved dependencies. The
127
+ rake task will `exit 1` immediately if there are unapproved dependencies, stopping your build dead in its tracks!
168
128
 
169
129
  ## A note to gem authors / maintainers
170
130
 
@@ -178,3 +138,7 @@ end
178
138
  ```
179
139
 
180
140
  And add a `LICENSE` file to your gem that contains your license text.
141
+
142
+ ## License
143
+
144
+ LicenseFinder is released under the terms of the MIT License. http://www.opensource.org/licenses/mit-license
data/Rakefile CHANGED
@@ -18,4 +18,4 @@ Cucumber::Rake::Task.new(:features) do |t|
18
18
  t.cucumber_opts = "features --format pretty"
19
19
  end
20
20
 
21
- task default: [:spec, :features]
21
+ task :default => [:spec, :features]
data/bin/license_finder CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'license_finder'
4
- LicenseFinder::CLI.new.check_for_action_items
4
+ LicenseFinder::CLI.check_for_action_items
@@ -0,0 +1,49 @@
1
+ Feature: Approving non-whitelisted Dependencies
2
+ So that I can track the dependencies of my application which my business has approved
3
+ As an application developer using license finder
4
+ I want to be able to manually approve dependencies that have licenses which fall outside of my whitelist
5
+
6
+ Scenario: Manually approving a non-whitelisted dependency
7
+ Given I have an app with license finder
8
+ And my app depends on a gem "gpl_gem" licensed with "GPL"
9
+ And I whitelist the "MIT" license
10
+
11
+ When I run "license_finder"
12
+ Then I should see the following settings for "gpl_gem":
13
+ """
14
+ version: "0.0.0"
15
+ license: "GPL"
16
+ approved: false
17
+ """
18
+
19
+ When I update the settings for "gpl_gem" with the following content:
20
+ """
21
+ approved: true
22
+ """
23
+ When I run "license_finder"
24
+ Then I should not see "gpl_gem" in its output
25
+
26
+ Scenario: Manually adding a non-bundled dependency
27
+ Given I have an app with license finder
28
+ When I run "license_finder"
29
+ And I add the following content to "dependencies.yml":
30
+ """
31
+ - name: "my_javascript_library"
32
+ version: "0.0.0"
33
+ license: "GPL"
34
+ approved: false
35
+ """
36
+ Then I should see the following settings for "my_javascript_library":
37
+ """
38
+ version: "0.0.0"
39
+ license: "GPL"
40
+ approved: false
41
+ """
42
+ When I run "license_finder"
43
+ Then I should see "my_javascript_library" in its output
44
+ When I update the settings for "my_javascript_library" with the following content:
45
+ """
46
+ approved: true
47
+ """
48
+ When I run "license_finder"
49
+ Then I should not see "my_javascript_library" in its output
@@ -0,0 +1,48 @@
1
+ Feature: HTML Report
2
+ So that I can easily view a report outlining my application dependencies and licenses
3
+ As a non-technical application product owner
4
+ I want license finder to generate an easy-to-understand HTML report
5
+
6
+ Background:
7
+ Given I have an app with license finder
8
+
9
+ Scenario: Dependency details listed in HTML report
10
+ Given my application depends on a gem "mit_licensed_gem" with:
11
+ | license | summary | description | version | homepage | bundler_groups |
12
+ | MIT | mit is cool | seriously | 0.0.1 | http://mit_licensed_gem.github.com | test |
13
+ When I run "license_finder"
14
+ And I should see the "mit_licensed_gem" in the html with the following details:
15
+ | license | summary | description | name | bundler_groups |
16
+ | MIT | mit is cool | seriously | mit_licensed_gem v0.0.1 | test |
17
+ And the text "MIT" should link to "http://opensource.org/licenses/mit-license"
18
+ And the text "mit_licensed_gem" should link to "http://mit_licensed_gem.github.com"
19
+
20
+ Scenario: Approval status of dependencies indicated in HTML report
21
+ Given my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
22
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
23
+ And I whitelist the "MIT" license
24
+ When I run "license_finder"
25
+ Then I should see the "gpl_licensed_gem" in the html flagged as "unapproved"
26
+ And I should see the "mit_licensed_gem" in the html flagged as "approved"
27
+
28
+ Scenario: Dependency summary
29
+ Given my app depends on a gem "gpl_licensed_gem" licensed with "GPL"
30
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
31
+ And I whitelist the following licenses: "MIT, other"
32
+ When I run "license_finder"
33
+ # rake, bundler, license_finder, my_app, gpl_licensed_gem, mit_licensed_gem
34
+ Then I should see "6 total" in the html
35
+ # gpl_licensed_gem
36
+ And I should see "1 unapproved" in the html
37
+ # gpl_licensed_gem
38
+ And I should see "1 GPL" in the html
39
+
40
+ Scenario: Implicit dependencies list their parent dependencies
41
+ Given I have a rails app with license finder
42
+ When I run "license_finder"
43
+ Then I should see the "activerecord" in the html with the following details:
44
+ | parent |
45
+ | rails |
46
+ And I should see "rails" in the html with the following details:
47
+ | children |
48
+ | activerecord |
@@ -0,0 +1,36 @@
1
+ Feature: License Finder command line executable
2
+ So that I can report and manage my application's dependencies and licenses to my business
3
+ As an application developer
4
+ I want a command-line interface
5
+
6
+ Scenario: Running without a configuration file
7
+ Given I have an app with license finder
8
+ And my app does not have a "config" directory
9
+ When I run "license_finder"
10
+ Then I should see a "config" directory
11
+ And I should see the file "config/license_finder.yml" with the following content:
12
+ """
13
+ ---
14
+ whitelist:
15
+ #- MIT
16
+ #- Apache 2.0
17
+ ignore_groups:
18
+ #- test
19
+ #- development
20
+ dependencies_file_dir: './'
21
+ """
22
+
23
+ Scenario: Auditing an application with non-whitelisted licenses
24
+ Given I have an app with license finder
25
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
26
+ When I run "license_finder"
27
+ Then it should exit with status code 1
28
+ And I should see "mit_licensed_gem" in its output
29
+
30
+ Scenario: Auditing an application with whitelisted licenses
31
+ Given I have an app with license finder
32
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
33
+ And I whitelist the following licenses: "MIT, other"
34
+ When I run "license_finder"
35
+ Then it should exit with status code 0
36
+ And I should see "All gems are approved for use" in its output
@@ -0,0 +1,36 @@
1
+ Feature: License Finder command line executable
2
+ So that I can report and manage my application's dependencies and licenses to my business
3
+ As an application developer
4
+ I want a command-line interface
5
+
6
+ Scenario: Running without a configuration file
7
+ Given I have an app with rake and license finder
8
+ And my app does not have a "config" directory
9
+ When I run "rake license_finder"
10
+ Then I should see a "config" directory
11
+ And I should see the file "config/license_finder.yml" with the following content:
12
+ """
13
+ ---
14
+ whitelist:
15
+ #- MIT
16
+ #- Apache 2.0
17
+ ignore_groups:
18
+ #- test
19
+ #- development
20
+ dependencies_file_dir: './'
21
+ """
22
+
23
+ Scenario: Auditing an application with non-whitelisted licenses
24
+ Given I have an app with rake and license finder
25
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
26
+ When I run "rake license_finder"
27
+ Then it should exit with status code 1
28
+ And I should see "mit_licensed_gem" in its output
29
+
30
+ Scenario: Auditing an application with whitelisted licenses
31
+ Given I have an app with rake and license finder
32
+ And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
33
+ And I whitelist the following licenses: "MIT, other"
34
+ When I run "rake license_finder"
35
+ Then it should exit with status code 0
36
+ And I should see "All gems are approved for use" in its output
@@ -0,0 +1,9 @@
1
+ Feature: The rake task is automatically made available in Rails project
2
+ So that I do not have to modify the Rails rakefile
3
+ As an application developer
4
+ I want the license_finder rake task automatically loaded for me in a rails project
5
+
6
+ Scenario: The application is a Rails app
7
+ Given I have a rails app with license finder
8
+ When I run "rake license_finder"
9
+ Then I should see "Dependencies that need approval:" in its output
@@ -1,41 +1,39 @@
1
1
  require 'fileutils'
2
+ require 'capybara'
2
3
 
3
- Given /^I have a rails application with license finder$/ do
4
- @user = DSL::User.new
4
+ Given /^I have a rails app(?:lication)? with license finder$/ do
5
+ @user = ::DSL::User.new
5
6
  @user.create_rails_app
6
7
  end
7
8
 
8
- Given /^I have an application with license finder$/ do
9
- @user = DSL::User.new
9
+ Given /^I have an app(?:lication)? with license finder$/ do
10
+ @user = ::DSL::User.new
10
11
  @user.create_nonrails_app
11
12
  end
12
13
 
13
14
 
14
- Given /^I have an application setup with rake and license finder$/ do
15
- @user = DSL::User.new
15
+ Given /^I have an app(?:lication)? with rake and license finder$/ do
16
+ @user = ::DSL::User.new
16
17
  @user.create_nonrails_app
17
18
  @user.add_license_finder_to_rakefile
18
- @user.execute_command "rake license:init"
19
19
  end
20
20
 
21
- Given /^my application does not have a config directory$/ do
22
- FileUtils.rm_rf(@user.config_path)
23
- File.exists?(@user.config_path).should be_false
24
- end
21
+ Given /^my app(?:lication)? does not have a "([^"]+)" directory$/ do |name|
22
+ path = @user.app_path(name)
25
23
 
26
- Then /^the config directory should exist$/ do
27
- File.exists?(@user.config_path).should be_true
24
+ FileUtils.rm_rf(path)
25
+ File.should_not be_exists(path)
28
26
  end
29
27
 
30
- Given /^my application's rake file requires license finder$/ do
31
- @user.add_license_finder_to_rakefile
28
+ Then /^I should see a "([^"]+)" directory$/ do |name|
29
+ File.should be_exists(@user.app_path(name))
32
30
  end
33
31
 
34
- Given /^my (?:rails )?app depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
32
+ Given /^my (?:rails )?app(?:lication)? depends on a gem "(.*?)" licensed with "(.*?)"$/ do |gem_name, license|
35
33
  @user.add_dependency_to_app gem_name, :license => license
36
34
  end
37
35
 
38
- Given /^my (?:rails )?app depends on a gem "(.*?)" licensed with "(.*?)" in the "(.*?)" bundler groups$/ do |gem_name, license, bundler_groups|
36
+ Given /^my (?:rails )?app(?:lication)? depends on a gem "(.*?)" licensed with "(.*?)" in the "(.*?)" bundler groups$/ do |gem_name, license, bundler_groups|
39
37
  @user.add_dependency_to_app gem_name, :license => license, :bundler_groups => bundler_groups
40
38
  end
41
39
 
@@ -59,12 +57,15 @@ When /^I add the following content to "([^"]*)":$/ do |filename, text|
59
57
  @user.append_to_file(filename, @content = text)
60
58
  end
61
59
 
62
- When /^my application depends on a gem "([^"]*)" with:$/ do |gem_name, gem_info|
60
+ When /^my app(?:lication)? depends on a gem "([^"]*)" with:$/ do |gem_name, gem_info|
63
61
  info = gem_info.hashes.first
64
62
  @user.add_dependency_to_app(gem_name,
65
- :license => info["license"],
66
- :summary => info["summary"],
67
- :description => info["description"]
63
+ :license => info["license"],
64
+ :summary => info["summary"],
65
+ :description => info["description"],
66
+ :version => info["version"],
67
+ :homepage => info["homepage"],
68
+ :bundler_groups => info["bundler_groups"]
68
69
  )
69
70
  end
70
71
 
@@ -76,19 +77,18 @@ Then /^I should not see "(.*?)" in its output$/ do |gem_name|
76
77
  @output.should_not include gem_name
77
78
  end
78
79
 
79
- Then /^license finder should generate a file "([^"]*)" with the following content:$/ do |filename, text|
80
- File.read(File.join(@user.app_path, filename)).should == text.gsub(/^\s+/, "")
80
+ Then /^I should see the file "([^"]*)" with the following content:$/ do |filename, text|
81
+ File.read(@user.app_path(filename)).should == text.gsub(/^\s+/, "")
81
82
  end
82
83
 
83
- Then /^license finder should generate a file "([^"]*)" containing:$/ do |filename, text|
84
- File.read(File.join(@user.app_path, filename)).should include(text.gsub(/^\s+/, ""))
84
+ Then /^I should see the file "([^"]*)" containing:$/ do |filename, text|
85
+ File.read(@user.app_path(filename)).should include(text.gsub(/^\s+/, ""))
85
86
  end
86
87
 
87
88
  Then /^I should see the following settings for "([^"]*)":$/ do |name, yaml|
88
89
  expected_settings = YAML.load(yaml)
89
90
  all_settings = YAML.load(File.read(@user.dependencies_file_path))
90
91
  actual_settings = all_settings.detect { |gem| gem['name'] == name }
91
-
92
92
  actual_settings.should include expected_settings
93
93
  end
94
94
 
@@ -96,6 +96,29 @@ Then /^it should exit with status code (\d)$/ do |status|
96
96
  $?.exitstatus.should == status.to_i
97
97
  end
98
98
 
99
+ Then /^I should see the "([^"]*)" in the html flagged as "([^"]*)"$/ do |gem_name, css_class|
100
+ html = File.read(@user.dependencies_html_path)
101
+ page = Capybara.string(html)
102
+ gpl_gem = page.find("##{gem_name}")
103
+ gpl_gem[:class].should == css_class
104
+ end
105
+
106
+ Then /^I should see (?:the )?"([^"]*)" in the html with the following details:$/ do |gem_name, table|
107
+ html = File.read(@user.dependencies_html_path)
108
+ page = Capybara.string(html)
109
+ section = page.find("##{gem_name}")
110
+
111
+ table.hashes.first.each do |property_name, property_value|
112
+ section.should have_content property_value
113
+ end
114
+ end
115
+
116
+ Then /^I should see "([^"]*)" in the html$/ do |text|
117
+ html = File.read(@user.dependencies_html_path)
118
+ page = Capybara.string(html)
119
+
120
+ page.should have_content text
121
+ end
99
122
 
100
123
  module DSL
101
124
  class User
@@ -106,6 +129,8 @@ module DSL
106
129
 
107
130
  add_gem_dependency('rake')
108
131
  add_gem_dependency('license_finder', :path => root_path)
132
+
133
+ bundle_app
109
134
  end
110
135
 
111
136
  def create_rails_app
@@ -147,7 +172,9 @@ module DSL
147
172
  license = options.fetch(:license)
148
173
  summary = options.fetch(:summary, "")
149
174
  description = options.fetch(:description, "")
150
- bundler_groups = options.fetch(:bundler_groups, "").split(',').map(&:strip)
175
+ bundler_groups = options.fetch(:bundler_groups, "").to_s.split(',').map(&:strip)
176
+ version = options[:version] || "0.0.0"
177
+ homepage = options[:homepage]
151
178
 
152
179
  gem_dir = File.join(projects_path, gem_name)
153
180
 
@@ -156,11 +183,12 @@ module DSL
156
183
  file.write <<-GEMSPEC
157
184
  Gem::Specification.new do |s|
158
185
  s.name = "#{gem_name}"
159
- s.version = "0.0.0"
186
+ s.version = "#{version}"
160
187
  s.author = "Cucumber"
161
188
  s.summary = "#{summary}"
162
189
  s.license = "#{license}"
163
190
  s.description = "#{description}"
191
+ s.homepage = "#{homepage}"
164
192
  end
165
193
  GEMSPEC
166
194
  end
@@ -175,6 +203,7 @@ module DSL
175
203
  end
176
204
 
177
205
  def configure_license_finder_whitelist(whitelisted_licenses=[])
206
+ FileUtils.mkdir_p(config_path)
178
207
  File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
179
208
  f.write({'whitelist' => whitelisted_licenses}.to_yaml)
180
209
  end
@@ -188,8 +217,16 @@ module DSL
188
217
  @output
189
218
  end
190
219
 
191
- def app_path
192
- File.join(projects_path, app_name)
220
+ def app_path(sub_directory = nil)
221
+ path = app_path = Pathname.new(File.join(projects_path, app_name)).cleanpath.to_s
222
+
223
+ if sub_directory
224
+ path = Pathname.new(File.join(app_path, sub_directory)).cleanpath.to_s
225
+
226
+ raise "#{name} is outside of the app" unless path =~ %r{^#{app_path}/}
227
+ end
228
+
229
+ path
193
230
  end
194
231
 
195
232
  def config_path
@@ -200,6 +237,10 @@ module DSL
200
237
  File.join(app_path, 'dependencies.yml')
201
238
  end
202
239
 
240
+ def dependencies_html_path
241
+ File.join(app_path, 'dependencies.html')
242
+ end
243
+
203
244
  private
204
245
 
205
246
  def bundle_app
@@ -245,7 +286,13 @@ module DSL
245
286
  end
246
287
 
247
288
  def root_path
248
- File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
289
+ Pathname.new(File.join(File.dirname(__FILE__), "..", "..")).realpath.to_s
249
290
  end
250
291
  end
251
292
  end
293
+
294
+
295
+ When /^the text "([^"]*)" should link to "([^"]*)"$/ do |text, link|
296
+ html = Capybara.string File.read(@user.dependencies_html_path)
297
+ html.find(:xpath, "//a[@href='#{link}']").text.should == text
298
+ end