berkshelf 1.4.6 → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +1 -5
  3. data/CONTRIBUTING.md +3 -1
  4. data/Gemfile +11 -1
  5. data/README.md +16 -0
  6. data/Thorfile +3 -1
  7. data/berkshelf.gemspec +26 -38
  8. data/features/apply_command.feature +32 -0
  9. data/features/configure_command.feature +31 -0
  10. data/features/contingent_command.feature +5 -5
  11. data/features/default_locations.feature +2 -2
  12. data/features/groups_install.feature +19 -20
  13. data/features/info_command.feature +13 -13
  14. data/features/install_command.feature +86 -83
  15. data/features/json_formatter.feature +60 -23
  16. data/features/list_command.feature +5 -11
  17. data/features/lockfile.feature +286 -6
  18. data/features/open_command.feature +8 -4
  19. data/features/outdated_command.feature +8 -15
  20. data/features/package_command.feature +39 -0
  21. data/features/show_command.feature +8 -9
  22. data/features/step_definitions/chef_server_steps.rb +20 -2
  23. data/features/step_definitions/cli_steps.rb +10 -2
  24. data/features/step_definitions/configure_cli_steps.rb +7 -0
  25. data/features/step_definitions/filesystem_steps.rb +19 -14
  26. data/features/step_definitions/json_steps.rb +22 -5
  27. data/features/step_definitions/utility_steps.rb +13 -1
  28. data/features/support/env.rb +10 -23
  29. data/features/update_command.feature +105 -24
  30. data/features/upload_command.feature +0 -14
  31. data/features/vendor_install.feature +3 -3
  32. data/generator_files/Vagrantfile.erb +11 -11
  33. data/lib/berkshelf.rb +6 -5
  34. data/lib/berkshelf/berksfile.rb +267 -99
  35. data/lib/berkshelf/cli.rb +70 -34
  36. data/lib/berkshelf/cli_commands/test_command.rb +11 -0
  37. data/lib/berkshelf/community_rest.rb +1 -1
  38. data/lib/berkshelf/config.rb +19 -2
  39. data/lib/berkshelf/cookbook_source.rb +41 -12
  40. data/lib/berkshelf/cookbook_store.rb +8 -4
  41. data/lib/berkshelf/errors.rb +61 -29
  42. data/lib/berkshelf/formatters.rb +13 -19
  43. data/lib/berkshelf/formatters/human_readable.rb +8 -0
  44. data/lib/berkshelf/formatters/json.rb +12 -1
  45. data/lib/berkshelf/formatters/null.rb +23 -0
  46. data/lib/berkshelf/init_generator.rb +22 -11
  47. data/lib/berkshelf/location.rb +8 -10
  48. data/lib/berkshelf/locations/chef_api_location.rb +4 -5
  49. data/lib/berkshelf/locations/git_location.rb +14 -12
  50. data/lib/berkshelf/locations/path_location.rb +16 -1
  51. data/lib/berkshelf/locations/site_location.rb +1 -3
  52. data/lib/berkshelf/lockfile.rb +230 -33
  53. data/lib/berkshelf/resolver.rb +2 -1
  54. data/lib/berkshelf/ui.rb +4 -8
  55. data/lib/berkshelf/version.rb +1 -1
  56. data/lib/thor/monkies/shell.rb +2 -5
  57. data/spec/fixtures/cassettes/Berkshelf_Resolver/{ClassMethods/_initialize → _initialize}/adds_the_dependencies_of_the_source_as_sources.yml +0 -0
  58. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +2 -0
  59. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +26 -0
  60. data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +5 -0
  61. data/spec/fixtures/lockfiles/default.lock +11 -0
  62. data/spec/{config/knife.rb → knife.rb.sample} +2 -2
  63. data/spec/spec_helper.rb +15 -3
  64. data/spec/support/chef_api.rb +19 -5
  65. data/spec/support/chef_server.rb +4 -3
  66. data/spec/support/knife.rb +18 -0
  67. data/spec/unit/berkshelf/berksfile_spec.rb +332 -235
  68. data/spec/unit/berkshelf/cached_cookbook_spec.rb +40 -42
  69. data/spec/unit/berkshelf/chef/cookbook/chefignore_spec.rb +11 -15
  70. data/spec/unit/berkshelf/community_rest_spec.rb +16 -14
  71. data/spec/unit/berkshelf/config_spec.rb +36 -20
  72. data/spec/unit/berkshelf/cookbook_generator_spec.rb +6 -10
  73. data/spec/unit/berkshelf/cookbook_source_spec.rb +244 -183
  74. data/spec/unit/berkshelf/cookbook_store_spec.rb +72 -76
  75. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
  76. data/spec/unit/berkshelf/downloader_spec.rb +137 -157
  77. data/spec/unit/berkshelf/errors_spec.rb +1 -1
  78. data/spec/unit/berkshelf/formatters/null_spec.rb +17 -0
  79. data/spec/unit/berkshelf/formatters_spec.rb +83 -90
  80. data/spec/unit/berkshelf/git_spec.rb +219 -207
  81. data/spec/unit/berkshelf/init_generator_spec.rb +73 -73
  82. data/spec/unit/berkshelf/location_spec.rb +143 -162
  83. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +94 -89
  84. data/spec/unit/berkshelf/locations/git_location_spec.rb +75 -59
  85. data/spec/unit/berkshelf/locations/path_location_spec.rb +46 -30
  86. data/spec/unit/berkshelf/locations/site_location_spec.rb +4 -4
  87. data/spec/unit/berkshelf/lockfile_spec.rb +185 -1
  88. data/spec/unit/berkshelf/logger_spec.rb +6 -24
  89. data/spec/unit/berkshelf/mixin/logging_spec.rb +6 -8
  90. data/spec/unit/berkshelf/resolver_spec.rb +36 -38
  91. data/spec/unit/berkshelf/ui_spec.rb +9 -10
  92. data/spec/unit/berkshelf_spec.rb +41 -40
  93. data/spec/unit/chef/config_spec.rb +9 -11
  94. metadata +55 -203
  95. data/spec/config/berkshelf.pem +0 -27
  96. data/spec/config/validator.pem +0 -27
@@ -1,138 +1,143 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::ChefAPILocation, :chef_server do
4
- let(:test_chef_api) { "https://chefserver:8081" }
5
- let(:node_name) { "reset" }
6
- let(:client_key) { fixtures_path.join("reset.pem").to_s }
7
-
8
- describe "ClassMethods" do
9
- subject { described_class }
10
-
11
- let(:valid_uri) { test_chef_api }
12
- let(:invalid_uri) { "notauri" }
13
- let(:constraint) { double('constraint') }
14
-
15
- describe "::initialize" do
16
- before(:each) do
17
- @location = subject.new("nginx",
18
- constraint,
19
- chef_api: test_chef_api,
20
- node_name: node_name,
21
- client_key: client_key
22
- )
23
- end
4
+ let(:test_chef_api) { 'https://chefserver:8081' }
5
+ let(:node_name) { 'reset' }
6
+ let(:client_key) { fixtures_path.join('reset.pem').to_s }
7
+
8
+ let(:valid_uri) { test_chef_api }
9
+ let(:invalid_uri) { 'notauri' }
10
+ let(:constraint) { double('constraint') }
11
+
12
+ describe '.initialize' do
13
+ subject do
14
+ Berkshelf::ChefAPILocation.new('nginx',
15
+ constraint,
16
+ chef_api: test_chef_api,
17
+ node_name: node_name,
18
+ client_key: client_key
19
+ )
20
+ end
24
21
 
25
- it "sets the uri attribute to the value of the chef_api option" do
26
- @location.uri.should eql(test_chef_api)
27
- end
22
+ it 'sets the uri attribute to the value of the chef_api option' do
23
+ expect(subject.uri).to eq(test_chef_api)
24
+ end
28
25
 
29
- it "sets the node_name attribute to the value of the node_name option" do
30
- @location.node_name.should eql(node_name)
31
- end
26
+ it 'sets the node_name attribute to the value of the node_name option' do
27
+ expect(subject.node_name).to eq(node_name)
28
+ end
32
29
 
33
- it "sets the client_key attribute to the value of the client_key option" do
34
- @location.client_key.should eql(client_key)
35
- end
30
+ it 'sets the client_key attribute to the value of the client_key option' do
31
+ expect(subject.client_key).to eq(client_key)
32
+ end
36
33
 
37
- it "sets the downloaded status to false" do
38
- @location.should_not be_downloaded
39
- end
34
+ it 'sets the downloaded status to false' do
35
+ expect(subject).to_not be_downloaded
36
+ end
40
37
 
41
- context "when an invalid Chef API URI is given" do
42
- it "raises Berkshelf::InvalidChefAPILocation" do
43
- lambda {
44
- subject.new("nginx", constraint, chef_api: invalid_uri, node_name: node_name, client_key: client_key)
45
- }.should raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
46
- end
38
+ context 'when an invalid Chef API URI is given' do
39
+ it 'raises Berkshelf::InvalidChefAPILocation' do
40
+ expect {
41
+ Berkshelf::ChefAPILocation.new("nginx", constraint, chef_api: invalid_uri, node_name: node_name, client_key: client_key)
42
+ }.to raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
47
43
  end
44
+ end
48
45
 
49
- context "when no option for node_name is supplied" do
50
- it "raises Berkshelf::InvalidChefAPILocation" do
51
- lambda {
52
- subject.new("nginx", constraint, chef_api: invalid_uri, client_key: client_key)
53
- }.should raise_error(Berkshelf::InvalidChefAPILocation)
54
- end
46
+ context 'when no option for node_name is supplied' do
47
+ it 'raises Berkshelf::InvalidChefAPILocation' do
48
+ expect {
49
+ Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: invalid_uri, client_key: client_key)
50
+ }.to raise_error(Berkshelf::InvalidChefAPILocation)
55
51
  end
52
+ end
56
53
 
57
- context "when no option for client_key is supplied" do
58
- it "raises Berkshelf::InvalidChefAPILocation" do
59
- lambda {
60
- subject.new("nginx", constraint, chef_api: invalid_uri, node_name: node_name)
61
- }.should raise_error(Berkshelf::InvalidChefAPILocation)
62
- end
54
+ context 'when no option for client_key is supplied' do
55
+ it 'raises Berkshelf::InvalidChefAPILocation' do
56
+ expect {
57
+ Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: invalid_uri, node_name: node_name)
58
+ }.to raise_error(Berkshelf::InvalidChefAPILocation)
63
59
  end
60
+ end
64
61
 
65
- context "given the symbol :config for the value of chef_api:" do
66
- before(:each) { @loc = subject.new("nginx", constraint, chef_api: :config) }
62
+ context 'given the symbol :config for the value of chef_api:' do
63
+ subject do
64
+ Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: :config)
65
+ end
67
66
 
68
- it "uses the value of Berkshelf::Chef.instance.chef.chef_server_url for the uri attribute" do
69
- @loc.uri.should eql(Berkshelf::Config.instance.chef.chef_server_url)
70
- end
67
+ it 'uses the value of Berkshelf::Chef.instance.chef.chef_server_url for the uri attribute' do
68
+ expect(subject.uri).to eq(Berkshelf::Config.instance.chef.chef_server_url)
69
+ end
71
70
 
72
- it "uses the value of Berkshelf::Chef.instance.chef.node_name for the node_name attribute" do
73
- @loc.node_name.should eql(Berkshelf::Config.instance.chef.node_name)
74
- end
71
+ it 'uses the value of Berkshelf::Chef.instance.chef.node_name for the node_name attribute' do
72
+ expect(subject.node_name).to eq(Berkshelf::Config.instance.chef.node_name)
73
+ end
75
74
 
76
- it "uses the value of Berkshelf::Chef.instance.chef.client_key for the client_key attribute" do
77
- @loc.client_key.should eql(Berkshelf::Config.instance.chef.client_key)
78
- end
75
+ it 'uses the value of Berkshelf::Chef.instance.chef.client_key for the client_key attribute' do
76
+ expect(subject.client_key).to eq(Berkshelf::Config.instance.chef.client_key)
79
77
  end
80
78
  end
79
+ end
81
80
 
82
- describe "::validate_uri" do
83
- it "returns false if the given URI is invalid" do
84
- subject.validate_uri(invalid_uri).should be_false
85
- end
81
+ describe '.validate_uri' do
82
+ it 'returns false if the given URI is invalid' do
83
+ expect(Berkshelf::ChefAPILocation.validate_uri(invalid_uri)).to be_false
84
+ end
86
85
 
87
- it "returns true if the given URI is valid" do
88
- subject.validate_uri(valid_uri).should be_true
89
- end
86
+ it 'returns true if the given URI is valid' do
87
+ expect(Berkshelf::ChefAPILocation.validate_uri(valid_uri)).to be_true
90
88
  end
89
+ end
91
90
 
92
- describe "::validate_uri!" do
93
- it "raises Berkshelf::InvalidChefAPILocation if the given URI is invalid" do
94
- lambda {
95
- subject.validate_uri!(invalid_uri)
96
- }.should raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
97
- end
91
+ describe '.validate_uri!' do
92
+ it 'raises Berkshelf::InvalidChefAPILocation if the given URI is invalid' do
93
+ expect {
94
+ Berkshelf::ChefAPILocation.validate_uri!(invalid_uri)
95
+ }.to raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
96
+ end
98
97
 
99
- it "returns true if the given URI is valid" do
100
- subject.validate_uri!(valid_uri).should be_true
101
- end
98
+ it 'returns true if the given URI is valid' do
99
+ expect(Berkshelf::ChefAPILocation.validate_uri!(valid_uri)).to be_true
102
100
  end
103
101
  end
104
102
 
103
+
104
+
105
105
  subject do
106
- described_class.new('nginx', nil, chef_api: test_chef_api, node_name: node_name, client_key: client_key)
106
+ Berkshelf::ChefAPILocation.new('nginx',
107
+ nil,
108
+ chef_api: test_chef_api,
109
+ node_name: node_name,
110
+ client_key: client_key
111
+ )
107
112
  end
108
113
 
109
- describe "#target_cookbook" do
114
+ describe '#target_cookbook' do
110
115
  let(:cookbook_version) { double('cookbook_version') }
111
116
 
112
- context "when a version constraint is present" do
117
+ context 'when a version constraint is present' do
113
118
  let(:constraint) { double('constraint') }
114
119
 
115
- it "returns the best solution for the constraint" do
120
+ it 'returns the best solution for the constraint' do
116
121
  subject.stub(:version_constraint).and_return(constraint)
117
122
  subject.stub_chain(:conn, :cookbook, :satisfy).with(subject.name, constraint).and_return(cookbook_version)
118
-
119
- subject.target_cookbook.should eql(cookbook_version)
123
+
124
+ expect(subject.target_cookbook).to eq(cookbook_version)
120
125
  end
121
126
  end
122
127
 
123
- context "when a version constraint is not present" do
124
- it "returns the latest version of the cookbook" do
128
+ context 'when a version constraint is not present' do
129
+ it 'returns the latest version of the cookbook' do
125
130
  subject.stub(:version_constraint).and_return(nil)
126
131
  subject.stub_chain(:conn, :cookbook, :latest_version).with(subject.name).and_return(cookbook_version)
127
132
 
128
- subject.target_cookbook.should eql(cookbook_version)
133
+ expect(subject.target_cookbook).to eq(cookbook_version)
129
134
  end
130
135
  end
131
136
  end
132
137
 
133
- describe "#to_s" do
134
- it "returns a string containing the location key and the Chef API URI" do
135
- subject.to_s.should eql("chef_api: '#{test_chef_api}'")
138
+ describe '#to_s' do
139
+ it 'returns a string containing the location key and the Chef API URI' do
140
+ expect(subject.to_s).to eq("chef_api: '#{test_chef_api}'")
136
141
  end
137
142
  end
138
143
  end
@@ -3,130 +3,146 @@ require 'spec_helper'
3
3
  describe Berkshelf::GitLocation do
4
4
  let(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
5
5
 
6
- describe "ClassMethods" do
7
- subject { described_class }
8
-
9
- describe "::initialize" do
10
- it "raises InvalidGitURI if given an invalid Git URI for options[:git]" do
11
- lambda {
12
- subject.new("nginx", complacent_constraint, git: "/something/on/disk")
13
- }.should raise_error(Berkshelf::InvalidGitURI)
14
- end
6
+ describe '.initialize' do
7
+ it 'raises InvalidGitURI if given an invalid Git URI for options[:git]' do
8
+ expect {
9
+ Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: '/something/on/disk')
10
+ }.to raise_error(Berkshelf::InvalidGitURI)
15
11
  end
12
+ end
16
13
 
17
- describe "::tmpdir" do
18
- it "creates a temporary directory within the Berkshelf temporary directory" do
19
- subject.tmpdir.should include(Berkshelf.tmp_dir)
20
- end
14
+ describe '.tmpdir' do
15
+ it 'creates a temporary directory within the Berkshelf temporary directory' do
16
+ expect(Berkshelf::GitLocation.tmpdir).to include(Berkshelf.tmp_dir)
21
17
  end
22
18
  end
23
19
 
24
- subject { described_class.new("nginx", complacent_constraint, git: "git://github.com/opscode-cookbooks/nginx.git") }
25
20
 
26
- describe "#download" do
27
- context "when a local revision is present" do
21
+
22
+ subject { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
23
+
24
+ describe '#download' do
25
+ context 'when a local revision is present' do
28
26
  let(:cached) { double('cached') }
29
27
 
30
28
  before do
29
+ Berkshelf::Git.stub(:rev_parse).and_return('abcd1234')
31
30
  Berkshelf::GitLocation.any_instance.stub(:cached?).and_return(true)
32
31
  Berkshelf::GitLocation.any_instance.stub(:validate_cached).with(cached).and_return(cached)
33
32
  Berkshelf::CachedCookbook.stub(:from_store_path).with(any_args()).and_return(cached)
34
33
  end
35
34
 
36
- it "returns the cached cookbook" do
35
+ it 'returns the cached cookbook' do
37
36
  expect(subject.download(tmp_path)).to eq(cached)
38
37
  end
39
38
  end
40
39
 
41
- it "returns an instance of Berkshelf::CachedCookbook" do
42
- subject.download(tmp_path).should be_a(Berkshelf::CachedCookbook)
40
+ it 'returns an instance of Berkshelf::CachedCookbook' do
41
+ expect(subject.download(tmp_path)).to be_a(Berkshelf::CachedCookbook)
43
42
  end
44
43
 
45
- it "downloads the cookbook to the given destination" do
44
+ it 'downloads the cookbook to the given destination' do
46
45
  cached_cookbook = subject.download(tmp_path)
47
- branch_name = subject.branch_name
46
+ ref = subject.ref
48
47
 
49
- tmp_path.should have_structure {
50
- directory "#{cached_cookbook.cookbook_name}-#{branch_name}" do
51
- file "metadata.rb"
48
+ expect(tmp_path).to have_structure {
49
+ directory "#{cached_cookbook.cookbook_name}-#{ref}" do
50
+ file 'metadata.rb'
52
51
  end
53
52
  }
54
53
  end
55
54
 
56
- it "sets the downloaded status to true" do
55
+ it 'sets the downloaded status to true' do
57
56
  subject.download(tmp_path)
58
-
59
- subject.should be_downloaded
57
+ expect(subject).to be_downloaded
60
58
  end
61
59
 
62
- context "given no ref/branch/tag options is given" do
63
- subject { described_class.new("nginx", complacent_constraint, git: "git://github.com/opscode-cookbooks/nginx.git") }
60
+ context 'given no ref/branch/tag options is given' do
61
+ subject { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
64
62
 
65
- it "sets the branch attribute to the HEAD revision of the cloned repo" do
63
+ it 'sets the branch attribute to the HEAD revision of the cloned repo' do
66
64
  subject.download(tmp_path)
67
-
68
- subject.branch.should_not be_nil
65
+ expect(subject.branch).to_not be_nil
69
66
  end
70
67
  end
71
68
 
72
- context "given a git repo that does not exist" do
73
- subject { described_class.new("doesnot_exist", complacent_constraint, git: "git://github.com/RiotGames/thisrepo_does_not_exist.git") }
69
+ context 'given a git repo that does not exist' do
70
+ subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: 'git://github.com/RiotGames/thisrepo_does_not_exist.git') }
74
71
 
75
- it "raises a GitError" do
72
+ it 'raises a GitError' do
76
73
  Berkshelf::Git.stub(:git).and_raise(Berkshelf::GitError.new(''))
77
- lambda {
74
+ expect {
78
75
  subject.download(tmp_path)
79
- }.should raise_error(Berkshelf::GitError)
76
+ }.to raise_error(Berkshelf::GitError)
80
77
  end
81
78
  end
82
79
 
83
- context "given a git repo that does not contain a cookbook" do
80
+ context 'given a git repo that does not contain a cookbook' do
84
81
  let(:fake_remote) { local_git_origin_path_for('not_a_cookbook') }
85
- subject { described_class.new("doesnot_exist", complacent_constraint, git: "file://#{fake_remote}.git") }
82
+ subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: "file://#{fake_remote}.git") }
86
83
 
87
- it "raises a CookbookNotFound error" do
84
+ it 'raises a CookbookNotFound error' do
88
85
  subject.stub(:clone).and_return {
89
86
  FileUtils.mkdir_p(fake_remote)
90
- Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m "README"`; dir }
87
+ Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m 'README'`; dir }
91
88
  }
92
89
 
93
- lambda {
90
+ expect {
94
91
  subject.download(tmp_path)
95
- }.should raise_error(Berkshelf::CookbookNotFound)
92
+ }.to raise_error(Berkshelf::CookbookNotFound)
96
93
  end
97
94
  end
98
95
 
99
- context "given the content at the Git repo does not satisfy the version constraint" do
96
+ context 'given the content at the Git repo does not satisfy the version constraint' do
100
97
  subject do
101
- described_class.new("nginx",
98
+ Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
102
99
  double('constraint', satisfies?: false),
103
- git: "git://github.com/opscode-cookbooks/nginx.git"
100
+ git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git'
104
101
  )
105
102
  end
106
103
 
107
- it "raises a CookbookValidationFailure error" do
108
- lambda {
104
+ it 'raises a CookbookValidationFailure error' do
105
+ expect {
109
106
  subject.download(tmp_path)
110
- }.should raise_error(Berkshelf::CookbookValidationFailure)
107
+ }.to raise_error(Berkshelf::CookbookValidationFailure)
108
+ end
109
+ end
110
+
111
+ context 'given a value for tag' do
112
+ let(:tag) { '1.0.0' }
113
+
114
+ subject do
115
+ Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
116
+ complacent_constraint,
117
+ git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
118
+ tag: tag
119
+ )
120
+ end
121
+ let(:cached) { subject.download(tmp_path) }
122
+ let(:sha) { subject.ref }
123
+ let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
124
+
125
+ it 'returns a cached cookbook with a path that contains the ref' do
126
+ expect(cached.path).to eq(expected_path)
111
127
  end
112
128
  end
113
129
 
114
- context "given a value for ref that is a tag or branch and not a commit hash" do
115
- let(:ref) { "0.9.8" }
130
+ context 'give a value for branch' do
131
+ let(:branch) { 'master' }
116
132
 
117
133
  subject do
118
- described_class.new("nginx",
134
+ Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
119
135
  complacent_constraint,
120
- git: "git://github.com/opscode-cookbooks/nginx.git",
121
- ref: ref
136
+ git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
137
+ branch: branch
122
138
  )
123
139
  end
124
- let(:cached_cookbook) { subject.download(tmp_path) }
125
- let(:commit_hash) { "d7be334b094f497f5cce4169a8b3012bf7b27bc3" }
126
- let(:expected_path) { tmp_path.join("#{cached_cookbook.cookbook_name}-#{ref}") }
140
+ let(:cached) { subject.download(tmp_path) }
141
+ let(:sha) { subject.ref }
142
+ let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
127
143
 
128
- it "returns a cached cookbook with a path that contains the ref and not the commit hash it is pointing to" do
129
- cached_cookbook.path.should eql(expected_path)
144
+ it 'returns a cached cookbook with a path that contains the ref' do
145
+ expect(cached.path).to eq(expected_path)
130
146
  end
131
147
  end
132
148
  end
@@ -2,58 +2,74 @@ require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::PathLocation do
4
4
  let(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
5
- let(:path) { fixtures_path.join("cookbooks", "example_cookbook").to_s }
5
+ let(:path) { fixtures_path.join('cookbooks', 'example_cookbook').to_s }
6
6
 
7
- describe "ClassMethods" do
8
- describe "::new" do
9
- it "assigns the value of :path to @path" do
10
- obj = described_class.new("nginx", complacent_constraint, path: path)
11
-
12
- obj.path.should eql(path)
13
- end
7
+ describe '.new' do
8
+ it 'assigns the value of :path to @path' do
9
+ location = Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path)
10
+ expect(location.path).to eq(path)
14
11
  end
15
12
  end
16
13
 
17
- subject { described_class.new("nginx", complacent_constraint, path: path) }
18
14
 
19
- describe "#download" do
20
- it "returns an instance of CachedCookbook" do
21
- subject.download(tmp_path).should be_a(Berkshelf::CachedCookbook)
15
+
16
+ subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
17
+
18
+ describe '#download' do
19
+ it 'returns an instance of CachedCookbook' do
20
+ expect(subject.download(tmp_path)).to be_a(Berkshelf::CachedCookbook)
22
21
  end
23
22
 
24
- it "sets the downloaded status to true" do
23
+ it 'sets the downloaded status to true' do
25
24
  subject.download(tmp_path)
26
-
27
- subject.should be_downloaded
25
+ expect(subject).to be_downloaded
28
26
  end
29
27
 
30
- context "given a path that does not exist" do
31
- subject { described_class.new("doesnot_exist", complacent_constraint, path: tmp_path.join("doesntexist_noway")) }
28
+ context 'given a path that does not exist' do
29
+ subject { Berkshelf::PathLocation.new('doesnot_exist', complacent_constraint, path: tmp_path.join('doesntexist_noway')) }
32
30
 
33
- it "raises a CookbookNotFound error" do
34
- lambda {
31
+ it 'raises a CookbookNotFound error' do
32
+ expect {
35
33
  subject.download(tmp_path)
36
- }.should raise_error(Berkshelf::CookbookNotFound)
34
+ }.to raise_error(Berkshelf::CookbookNotFound)
37
35
  end
38
36
  end
39
37
 
40
- context "given a path that does not contain a cookbook" do
41
- subject { described_class.new("doesnot_exist", complacent_constraint, path: fixtures_path) }
38
+ context 'given a path that does not contain a cookbook' do
39
+ subject { Berkshelf::PathLocation.new('doesnot_exist', complacent_constraint, path: fixtures_path) }
42
40
 
43
- it "raises a CookbookNotFound error" do
44
- lambda {
41
+ it 'raises a CookbookNotFound error' do
42
+ expect {
45
43
  subject.download(tmp_path)
46
- }.should raise_error(Berkshelf::CookbookNotFound)
44
+ }.to raise_error(Berkshelf::CookbookNotFound)
47
45
  end
48
46
  end
49
47
 
50
- context "given the content at path does not satisfy the version constraint" do
51
- subject { described_class.new("nginx", double('constraint', satisfies?: false), path: path) }
48
+ context 'given the content at path does not satisfy the version constraint' do
49
+ subject { Berkshelf::PathLocation.new('nginx', double('constraint', satisfies?: false), path: path) }
52
50
 
53
- it "raises a CookbookValidationFailure error" do
54
- lambda {
51
+ it 'raises a CookbookValidationFailure error' do
52
+ expect {
55
53
  subject.download(double('path'))
56
- }.should raise_error(Berkshelf::CookbookValidationFailure)
54
+ }.to raise_error(Berkshelf::CookbookValidationFailure)
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#to_s' do
60
+ context 'for a remote path' do
61
+ subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
62
+
63
+ it 'includes the path information' do
64
+ expect(subject.to_s).to match(/path\:.+example_cookbook/)
65
+ end
66
+ end
67
+
68
+ context 'for a store path' do
69
+ subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: File.join(Berkshelf.berkshelf_path, 'cookbooks/example_cookbook')) }
70
+
71
+ it 'does not include the path information' do
72
+ expect(subject.to_s).to_not match(/path\:.+/)
57
73
  end
58
74
  end
59
75
  end