berkshelf 1.1.0.rc1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.description = %q{Manages a Cookbook's, or an Application's, Cookbook dependencies}
19
19
  s.summary = s.description
20
20
  s.homepage = "http://berkshelf.com"
21
+ s.license = "Apache 2.0"
21
22
  s.files = `git ls-files`.split($\)
22
23
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
24
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -341,13 +341,13 @@ Feature: install cookbooks from a Berksfile
341
341
  Scenario: with a git error during download
342
342
  Given I write to "Berksfile" with:
343
343
  """
344
- cookbook "ohai"
344
+ cookbook "ohai", "1.1.4"
345
345
  cookbook "doesntexist", git: "git://github.com/asdjhfkljashflkjashfakljsf"
346
346
  """
347
347
  When I run `berks install`
348
348
  Then the output should contain:
349
349
  """
350
- Installing ohai (1.1.2) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
350
+ Installing ohai (1.1.4) from site: 'http://cookbooks.opscode.com/api/v1/cookbooks'
351
351
  Failed to download doesntexist from git: 'git://github.com/asdjhfkljashflkjashfakljsf'
352
352
  An error occured during Git execution:
353
353
  """
@@ -0,0 +1,32 @@
1
+ Feature: open command
2
+ As a user
3
+ I want to be able to view the source of a cached cookbook
4
+ So that I can troubleshoot bugs in my dependencies
5
+
6
+ Scenario: Running berks open with no $EDITOR
7
+ Given the environment variable EDITOR is nil
8
+ And the cookbook store has the cookbooks:
9
+ | mysql | 1.2.4 |
10
+ When I run `berks open mysql`
11
+ Then the output should contain "To open a cookbook, set $EDITOR or $BERKSHELF_EDITOR"
12
+
13
+ Scenario: Running berks open with an $EDITOR
14
+ Given the environment variable EDITOR is "ls"
15
+ And the cookbook store has the cookbooks:
16
+ | mysql | 1.2.4 |
17
+ When I run `berks open mysql`
18
+ Then the output should contain "metadata.rb"
19
+
20
+ Scenario: Running berks open with a missing EDITOR
21
+ Given the environment variable EDITOR is "wat"
22
+ And the cookbook store has the cookbooks:
23
+ | mysql | 1.2.4 |
24
+ When I run `berks open mysql`
25
+ Then the output should contain "Could not run `wat "
26
+ And the CLI should exit with the status code for error "CommandUnsuccessful"
27
+
28
+ Scenario: Running berks open when the cookbook does not exist
29
+ Given the environment variable EDITOR is "ls"
30
+ When I run `berks open mysql`
31
+ Then the output should contain "Cookbook 'mysql' not found in any of the sources!"
32
+ And the CLI should exit with the status code for error "CookbookNotFound"
@@ -1,3 +1,11 @@
1
1
  Given /^pending\s+"([^\"]+)"$/ do |msg|
2
2
  pending
3
3
  end
4
+
5
+ Given /^the environment variable (.+) is nil$/ do |variable|
6
+ set_env variable, nil
7
+ end
8
+
9
+ Given /^the environment variable (.+) is "(.+)"$/ do |variable, value|
10
+ set_env variable, value
11
+ end
@@ -1,3 +1,5 @@
1
+ require 'chef/cookbook/chefignore'
2
+
1
3
  module Berkshelf
2
4
  # @author Jamie Winsor <jamie@vialstudios.com>
3
5
  class Berksfile
@@ -27,7 +29,13 @@ module Berkshelf
27
29
  # @return [String]
28
30
  # expanded filepath to the vendor directory
29
31
  def vendor(cookbooks, path)
30
- path = File.expand_path(path)
32
+ chefignore_file = [
33
+ File.join(Dir.pwd, 'chefignore'),
34
+ File.join(Dir.pwd, 'cookbooks', 'chefignore')
35
+ ].find { |f| File.exists?(f) }
36
+
37
+ chefignore = chefignore_file && ::Chef::Cookbook::Chefignore.new(chefignore_file)
38
+ path = File.expand_path(path)
31
39
  FileUtils.mkdir_p(path)
32
40
 
33
41
  scratch = Berkshelf.mktmpdir
@@ -37,7 +45,12 @@ module Berkshelf
37
45
 
38
46
  # Dir.glob does not support backslash as a File separator
39
47
  src = cb.path.to_s.gsub('\\', '/')
40
- FileUtils.cp_r(Dir.glob(File.join(src, "*")), dest)
48
+ files = Dir.glob(File.join(src, "*"))
49
+
50
+ # Filter out files using chefignore
51
+ files = chefignore.remove_ignores_from(files) if chefignore
52
+
53
+ FileUtils.cp_r(files, dest)
41
54
  end
42
55
 
43
56
  FileUtils.remove_dir(path, force: true)
@@ -410,10 +423,10 @@ module Berkshelf
410
423
  # @return [Hash]
411
424
  # a hash of cached cookbooks and their latest version. An empty hash is returned
412
425
  # if there are no newer cookbooks for any of your sources
413
- #
426
+ #
414
427
  # @example
415
428
  # berksfile.outdated => {
416
- # <#CachedCookbook name="artifact"> => "0.11.2"
429
+ # <#CachedCookbook name="artifact"> => "0.11.2"
417
430
  # }
418
431
  def outdated(options = {})
419
432
  outdated = Hash.new
@@ -92,6 +92,21 @@ module Berkshelf
92
92
  Berkshelf.formatter.msg "Config written to: '#{path}'"
93
93
  end
94
94
 
95
+ desc "open NAME", "Opens the source directory of an installed cookbook", hide: true
96
+ def open(name)
97
+ editor = [ENV['BERKSHELF_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
98
+ raise ArgumentError, "To open a cookbook, set $EDITOR or $BERKSHELF_EDITOR" unless editor
99
+
100
+ cookbook = Berkshelf.cookbook_store.cookbooks(name).last
101
+ raise CookbookNotFound, "Cookbook '#{name}' not found in any of the sources!" unless cookbook
102
+
103
+ Dir.chdir(cookbook.path) do
104
+ command = "#{editor} #{cookbook.path}"
105
+ success = system(command)
106
+ raise CommandUnsuccessful, "Could not run `#{command}`" unless success
107
+ end
108
+ end
109
+
95
110
  method_option :except,
96
111
  type: :array,
97
112
  desc: "Exclude cookbooks that are in these groups.",
@@ -148,4 +148,5 @@ module Berkshelf
148
148
 
149
149
  class ConfigExists < BerkshelfError; status_code(116); end
150
150
  class ConfigurationError < BerkshelfError; status_code(117); end
151
+ class CommandUnsuccessful < BerkshelfError; status_code(118); end
151
152
  end
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "1.1.0.rc1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -33,12 +33,31 @@ EOF
33
33
  end
34
34
 
35
35
  describe "::vendor" do
36
- it "returns the expanded filepath of the vendor directory" do
37
- cached_cookbooks = Array.new
38
- tmpdir = Dir.mktmpdir(nil, tmp_path)
36
+ let(:cached_cookbooks) { [] }
37
+ let(:tmpdir) { Dir.mktmpdir(nil, tmp_path) }
39
38
 
39
+ it "returns the expanded filepath of the vendor directory" do
40
40
  subject.vendor(cached_cookbooks, tmpdir).should eql(tmpdir)
41
41
  end
42
+
43
+ context "with a chefignore" do
44
+ before(:each) do
45
+ File.stub(:exists?).and_return(true)
46
+ ::Chef::Cookbook::Chefignore.any_instance.stub(:remove_ignores_from).and_return(['metadata.rb'])
47
+ end
48
+
49
+ it "finds a chefignore file" do
50
+ ::Chef::Cookbook::Chefignore.should_receive(:new).with(File.expand_path('chefignore'))
51
+ subject.vendor(cached_cookbooks, tmpdir)
52
+ end
53
+
54
+ it "removes files in chefignore" do
55
+ cached_cookbooks = [ CachedCookbook.from_path(fixtures_path.join('cookbooks/example_cookbook')) ]
56
+ FileUtils.should_receive(:cp_r).with(['metadata.rb'], anything()).exactly(1).times
57
+ FileUtils.should_receive(:cp_r).with(anything(), anything(), anything()).once
58
+ subject.vendor(cached_cookbooks, tmpdir)
59
+ end
60
+ end
42
61
  end
43
62
  end
44
63
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.rc1
5
- prerelease: 6
4
+ version: 1.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie Winsor
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-11-30 00:00:00.000000000 Z
15
+ date: 2012-12-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: yajl-ruby
@@ -222,6 +222,7 @@ files:
222
222
  - features/json_formatter.feature
223
223
  - features/list_command.feature
224
224
  - features/lockfile.feature
225
+ - features/open_command.feature
225
226
  - features/outdated_command.feature
226
227
  - features/show_command.feature
227
228
  - features/step_definitions/berksfile_steps.rb
@@ -347,7 +348,8 @@ files:
347
348
  - spec/unit/berkshelf/uploader_spec.rb
348
349
  - spec/unit/berkshelf_spec.rb
349
350
  homepage: http://berkshelf.com
350
- licenses: []
351
+ licenses:
352
+ - Apache 2.0
351
353
  post_install_message:
352
354
  rdoc_options: []
353
355
  require_paths:
@@ -361,9 +363,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
361
363
  required_rubygems_version: !ruby/object:Gem::Requirement
362
364
  none: false
363
365
  requirements:
364
- - - ! '>'
366
+ - - ! '>='
365
367
  - !ruby/object:Gem::Version
366
- version: 1.3.1
368
+ version: '0'
369
+ segments:
370
+ - 0
371
+ hash: 810514310070508080
367
372
  requirements: []
368
373
  rubyforge_project:
369
374
  rubygems_version: 1.8.23
@@ -381,6 +386,7 @@ test_files:
381
386
  - features/json_formatter.feature
382
387
  - features/list_command.feature
383
388
  - features/lockfile.feature
389
+ - features/open_command.feature
384
390
  - features/outdated_command.feature
385
391
  - features/show_command.feature
386
392
  - features/step_definitions/berksfile_steps.rb