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,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "berkshelf errors" do
3
+ describe Berkshelf::BerkshelfError do
4
4
  pending
5
5
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Berkshelf::Formatters::Null do
4
+ before { Berkshelf.set_format(:null) }
5
+
6
+ [:install, :package, :foo, :bar, :bacon].each do |meth|
7
+ it "does not raise an error for :#{meth}" do
8
+ expect {
9
+ subject.send(meth)
10
+ }.to_not raise_error(Berkshelf::AbstractFunction)
11
+ end
12
+
13
+ it "returns nil for :#{meth}" do
14
+ expect(subject.send(meth)).to be_nil
15
+ end
16
+ end
17
+ end
@@ -1,119 +1,112 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Berkshelf
4
- describe Formatters do
5
- before(:each) do
6
- @original = Formatters.class_variable_get :@@formatters
7
- Formatters.class_variable_set :@@formatters, Hash.new
8
- end
3
+ describe Berkshelf::Formatters do
4
+ before do
5
+ @original = Berkshelf::Formatters.class_variable_get :@@formatters
6
+ Berkshelf::Formatters.class_variable_set :@@formatters, {}
7
+ end
8
+
9
+ after do
10
+ Berkshelf::Formatters.class_variable_set :@@formatters, @original
11
+ end
12
+
13
+ let(:format_id) { :rspec }
14
+ let(:format_klass) { Class.new { include Berkshelf::Formatters::AbstractFormatter } }
15
+
16
+ describe '.register' do
17
+ it 'adds the class of the includer to the list of registered formatters with the id' do
18
+ Berkshelf::Formatters.register(format_id, format_klass)
9
19
 
10
- after(:each) do
11
- Formatters.class_variable_set :@@formatters, @original
20
+ expect(Berkshelf::Formatters.formatters).to have_key(format_id)
21
+ expect(Berkshelf::Formatters.formatters[format_id]).to eq(format_klass)
12
22
  end
13
23
 
14
- describe "ClassMethods" do
15
- subject { Formatters }
16
- let(:format_id) { :rspec }
17
- let(:format_klass) { Class.new }
18
-
19
- describe "::register" do
20
- it "adds the class of the includer to the list of registered formatters with the id" do
21
- subject.register(format_id, format_klass)
22
-
23
- subject.formatters.should have_key(format_id)
24
- subject.formatters[format_id].should eql(format_klass)
25
- end
26
-
27
- context "when given a string instead of a symbol as the ID" do
28
- it "converts the string to a symbol and registers it" do
29
- subject.register("rspec", format_klass)
30
-
31
- subject.formatters.should have_key(:rspec)
32
- subject.formatters[:rspec].should eql(format_klass)
33
- end
34
- end
35
-
36
- context "when a formatter of the given ID has already been registered" do
37
- it "raises an InternalError" do
38
- subject.register(format_id, format_klass)
39
-
40
- lambda {
41
- subject.register(format_id, format_klass)
42
- }.should raise_error(Berkshelf::InternalError)
43
- end
44
- end
45
- end
24
+ context 'when given a string instead of a symbol as the ID' do
25
+ it 'converts the string to a symbol and registers it' do
26
+ Berkshelf::Formatters.register('rspec', format_klass)
46
27
 
47
- describe "::formatters" do
48
- before(:each) do
49
- subject.register(format_id, format_klass)
50
- end
51
-
52
- it "returns a hash where formatter ID's are keys and values are formatter classes" do
53
- subject.formatters.should be_a(Hash)
54
- subject.formatters.should have(1).item
55
- subject.formatters.keys.first.should eql(format_id)
56
- subject.formatters.values.first.should eql(format_klass)
57
- end
28
+ expect(Berkshelf::Formatters.formatters).to have_key(:rspec)
29
+ expect(Berkshelf::Formatters.formatters[:rspec]).to eq(format_klass)
58
30
  end
31
+ end
59
32
 
60
- describe "::get" do
61
- before(:each) do
62
- subject.register(format_id, format_klass)
63
- end
64
-
65
- it "returns the class constant of the given formatter ID" do
66
- subject[format_id].should eql(format_klass)
67
- end
33
+ context 'when a formatter of the given ID has already been registered' do
34
+ it 'raises an InternalError' do
35
+ Berkshelf::Formatters.register(format_id, format_klass)
68
36
 
69
- context "when the ID has not been registered" do
70
- it "returns nil" do
71
- subject[:not_there].should be_nil
72
- end
73
- end
37
+ expect {
38
+ Berkshelf::Formatters.register(format_id, format_klass)
39
+ }.to raise_error(Berkshelf::InternalError)
74
40
  end
75
41
  end
76
42
  end
77
43
 
78
- describe Formatters::AbstractFormatter do
79
- before(:each) do
80
- @original = Formatters.class_variable_get :@@formatters
81
- Formatters.class_variable_set :@@formatters, Hash.new
44
+ describe '.formatters' do
45
+ before do
46
+ Berkshelf::Formatters.register(format_id, format_klass)
47
+ end
48
+
49
+ it "returns a hash where formatter ID's are keys and values are formatter classes" do
50
+ expect(Berkshelf::Formatters.formatters).to be_a(Hash)
51
+ expect(Berkshelf::Formatters.formatters).to have(1).item
52
+ expect(Berkshelf::Formatters.formatters.keys.first).to eq(format_id)
53
+ expect(Berkshelf::Formatters.formatters.values.first).to eq(format_klass)
82
54
  end
55
+ end
56
+
57
+ describe '.get' do
58
+ before { Berkshelf::Formatters.register(format_id, format_klass) }
83
59
 
84
- after(:each) do
85
- Formatters.class_variable_set :@@formatters, @original
60
+ it 'returns the class constant of the given formatter ID' do
61
+ expect(Berkshelf::Formatters[format_id]).to eq(format_klass)
86
62
  end
87
63
 
88
- describe "ClassMethods" do
89
- subject do
90
- Class.new do
91
- include Formatters::AbstractFormatter
92
- end
64
+ context 'when the ID has not been registered' do
65
+ it 'returns nil' do
66
+ expect(Berkshelf::Formatters[:not_there]).to be_nil
93
67
  end
68
+ end
69
+ end
94
70
 
95
- describe "::register_formatter" do
96
- it "delegates to Formatters" do
97
- Formatters.should_receive(:register).with(:rspec, subject)
71
+ describe Berkshelf::Formatters::AbstractFormatter do
72
+ describe '.register_formatter' do
73
+ it 'delegates to Formatters' do
74
+ Berkshelf::Formatters.should_receive(:register).with(:rspec, format_klass)
98
75
 
99
- subject.register_formatter(:rspec)
100
- end
76
+ format_klass.register_formatter(:rspec)
101
77
  end
102
78
  end
103
79
 
80
+
81
+
104
82
  subject do
105
- Class.new do
106
- include Formatters::AbstractFormatter
107
- end.new
83
+ Class.new { include Berkshelf::Formatters::AbstractFormatter }.new
108
84
  end
109
85
 
110
- it "has abstract methods for all the messaging modes" do
111
- lambda { subject.install("my_coobook","1.2.3","http://community") }.should raise_error(AbstractFunction)
112
- lambda { subject.use("my_coobook","1.2.3") }.should raise_error(AbstractFunction)
113
- lambda { subject.use("my_coobook","1.2.3","http://community") }.should raise_error(AbstractFunction)
114
- lambda { subject.upload("my_coobook","1.2.3","http://chef_server") }.should raise_error(AbstractFunction)
115
- lambda { subject.msg("something you should know") }.should raise_error(AbstractFunction)
116
- lambda { subject.error("whoa this is bad") }.should raise_error(AbstractFunction)
86
+ it 'has abstract methods for all the messaging modes' do
87
+ expect {
88
+ subject.install('my_coobook','1.2.3','http://community')
89
+ }.to raise_error(Berkshelf::AbstractFunction)
90
+
91
+ expect {
92
+ subject.use('my_coobook','1.2.3')
93
+ }.to raise_error(Berkshelf::AbstractFunction)
94
+
95
+ expect {
96
+ subject.use('my_coobook','1.2.3','http://community')
97
+ }.to raise_error(Berkshelf::AbstractFunction)
98
+
99
+ expect {
100
+ subject.upload('my_coobook','1.2.3','http://chef_server')
101
+ }.to raise_error(Berkshelf::AbstractFunction)
102
+
103
+ expect {
104
+ subject.msg('something you to know')
105
+ }.to raise_error(Berkshelf::AbstractFunction)
106
+
107
+ expect {
108
+ subject.error('whoa this is bad')
109
+ }.to raise_error(Berkshelf::AbstractFunction)
117
110
  end
118
111
  end
119
112
  end
@@ -1,299 +1,311 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Git do
4
- describe "ClassMethods" do
5
- subject { Berkshelf::Git }
6
- let(:git) { Berkshelf::Git }
4
+ let(:git) { Berkshelf::Git }
7
5
 
8
- describe "::find_git" do
9
- it "should find git" do
10
- subject.find_git.should_not be_nil
11
- end
6
+ describe '.find_git' do
7
+ it 'finds git' do
8
+ expect(Berkshelf::Git.find_git).to_not be_nil
9
+ end
12
10
 
13
- it "should raise if it can't find git" do
14
- ENV.should_receive(:[]).with("PATH").and_return(String.new)
11
+ it 'raises an error if git cannot be not found' do
12
+ ENV.should_receive(:[]).with('PATH').and_return(String.new)
15
13
 
16
- lambda {
17
- subject.find_git
18
- }.should raise_error(Berkshelf::GitNotFound)
19
- end
14
+ expect {
15
+ Berkshelf::Git.find_git
16
+ }.to raise_error(Berkshelf::GitNotFound)
20
17
  end
18
+ end
21
19
 
22
- describe "::clone" do
23
- let(:target) { clone_target_for('nginx') }
20
+ describe '.clone' do
21
+ let(:target) { clone_target_for('nginx') }
24
22
 
25
- it "clones the repository to the target path" do
26
- origin_uri = git_origin_for("nginx")
27
- subject.clone(origin_uri, target)
23
+ it 'clones the repository to the target path' do
24
+ origin_uri = git_origin_for('nginx')
25
+ Berkshelf::Git.clone(origin_uri, target)
28
26
 
29
- expect(target).to exist
30
- expect(target).to be_directory
31
- end
27
+ expect(target).to exist
28
+ expect(target).to be_directory
32
29
  end
30
+ end
33
31
 
34
- describe "::checkout" do
35
- let(:repo_path) { clone_target_for('nginx') }
36
- let(:repo) {
37
- origin_uri = git_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
38
- git.clone(origin_uri, repo_path)
39
- }
32
+ describe '.checkout' do
33
+ let(:repo_path) { clone_target_for('nginx') }
34
+ let(:repo) {
35
+ origin_uri = git_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
36
+ git.clone(origin_uri, repo_path)
37
+ }
40
38
 
41
- shared_examples "able to checkout git ref" do |test_ref|
42
- it "checks out the specified ref of the given repository" do
43
- git.checkout(repo, ref)
39
+ shared_examples 'able to checkout git ref' do |test_ref|
40
+ it 'checks out the specified ref of the given repository' do
41
+ git.checkout(repo, ref)
44
42
 
45
- Dir.chdir repo_path do
46
- test_ref ||= ref
47
- %x[git rev-parse #{test_ref}].should == %x[git rev-parse HEAD]
48
- end
43
+ Dir.chdir repo_path do
44
+ test_ref ||= ref
45
+ expect(%x[git rev-parse #{test_ref}]).to eq(%x[git rev-parse HEAD])
49
46
  end
50
47
  end
48
+ end
51
49
 
52
- context 'with sha commit id' do
53
- let(:ref) { git_sha_for_ref('nginx', '1.0.1') }
50
+ context 'with sha commit id' do
51
+ let(:ref) { git_sha_for_ref('nginx', '1.0.1') }
54
52
 
55
- it_behaves_like 'able to checkout git ref'
56
- end
53
+ it_behaves_like 'able to checkout git ref'
54
+ end
57
55
 
58
- context 'with tags' do
59
- let(:ref) { "1.0.1" }
56
+ context 'with tags' do
57
+ let(:ref) { '1.0.1' }
60
58
 
61
- it_behaves_like 'able to checkout git ref'
59
+ it_behaves_like 'able to checkout git ref'
62
60
 
63
- context 'after checking out another tag' do
64
- let(:other_tag) { '1.0.2' }
65
- before do
66
- git.checkout(repo, other_tag)
67
- Dir.chdir repo_path do
68
- run! "echo 'uncommitted change' >> content_file"
69
- end
61
+ context 'after checking out another tag' do
62
+ let(:other_tag) { '1.0.2' }
63
+ before do
64
+ git.checkout(repo, other_tag)
65
+ Dir.chdir repo_path do
66
+ run! "echo 'uncommitted change' >> content_file"
70
67
  end
71
-
72
- it_behaves_like 'able to checkout git ref'
73
68
  end
69
+
70
+ it_behaves_like 'able to checkout git ref'
74
71
  end
72
+ end
75
73
 
76
- context 'with branches' do
77
- let(:ref) { 'topic' }
74
+ context 'with branches' do
75
+ let(:ref) { 'topic' }
78
76
 
79
- it_behaves_like 'able to checkout git ref', 'origin/topic'
77
+ it_behaves_like 'able to checkout git ref', 'origin/topic'
80
78
 
81
- context 'after checking out another branch' do
82
- let(:other_branch) { 'next_topic' }
83
- before do
84
- git.checkout(repo, other_branch)
85
- Dir.chdir repo_path do
86
- run! "echo 'uncommitted change' >> content_file"
87
- end
79
+ context 'after checking out another branch' do
80
+ let(:other_branch) { 'next_topic' }
81
+ before do
82
+ git.checkout(repo, other_branch)
83
+ Dir.chdir repo_path do
84
+ run! "echo 'uncommitted change' >> content_file"
88
85
  end
89
-
90
- it_behaves_like 'able to checkout git ref', 'origin/topic'
91
86
  end
87
+
88
+ it_behaves_like 'able to checkout git ref', 'origin/topic'
92
89
  end
93
90
  end
91
+ end
94
92
 
95
- describe "::rev_parse" do
96
- let(:repo_path) { clone_target_for('nginx') }
97
- before(:each) do |example|
98
- origin_uri = git_origin_for('nginx', tags: ['1.1.1'])
99
- subject.clone(origin_uri, repo_path)
100
- subject.checkout(repo_path, git_sha_for_ref('nginx', '1.1.1'))
101
- end
93
+ describe '.rev_parse' do
94
+ let(:repo_path) { clone_target_for('nginx') }
95
+ before(:each) do |example|
96
+ origin_uri = git_origin_for('nginx', tags: ['1.1.1'])
97
+ Berkshelf::Git.clone(origin_uri, repo_path)
98
+ Berkshelf::Git.checkout(repo_path, git_sha_for_ref('nginx', '1.1.1'))
99
+ end
102
100
 
103
- it "returns the ref for HEAD" do
104
- expect(subject.rev_parse(repo_path)).to eql(git_sha_for_ref('nginx', '1.1.1'))
105
- end
101
+ it 'returns the ref for HEAD' do
102
+ rev = Berkshelf::Git.rev_parse(repo_path)
103
+ ref = git_sha_for_ref('nginx', '1.1.1')
104
+
105
+ expect(rev).to eql(ref)
106
106
  end
107
+ end
107
108
 
108
- describe "::show_ref" do
109
- let(:repo_path) { clone_target_for('nginx') }
110
- let(:tags) { ['1.0.1'] }
111
- let(:branches) { ['topic'] }
112
- let!(:repo) {
113
- origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
114
- git.clone(origin_uri, repo_path)
115
- }
109
+ describe '.show_ref' do
110
+ let(:repo_path) { clone_target_for('nginx') }
111
+ let(:tags) { ['1.0.1'] }
112
+ let(:branches) { ['topic'] }
113
+ let!(:repo) {
114
+ origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
115
+ git.clone(origin_uri, repo_path)
116
+ }
116
117
 
117
- it 'returns the commit id for the given tag' do
118
- git.show_ref(repo_path, '1.0.1').should == git_sha_for_ref('nginx', '1.0.1')
119
- end
118
+ it 'returns the commit id for the given tag' do
119
+ show = git.show_ref(repo_path, '1.0.1')
120
+ ref = git_sha_for_ref('nginx', '1.0.1')
120
121
 
121
- it 'returns the commit id for the given branch' do
122
- git.show_ref(repo_path, 'topic').should == git_sha_for_ref('nginx', 'topic')
123
- end
122
+ expect(show).to eq(ref)
123
+ end
124
124
 
125
- context 'with an ambiguous ref' do
126
- let(:tags) { ['topic'] }
127
- let(:branches) { ['topic'] }
125
+ it 'returns the commit id for the given branch' do
126
+ show = git.show_ref(repo_path, 'topic')
127
+ ref = git_sha_for_ref('nginx', 'topic')
128
+ expect(show).to eq(ref)
129
+ end
128
130
 
129
- it 'raises an error' do
130
- expect {git.show_ref(repo_path, 'topic')}.to raise_error(Berkshelf::AmbiguousGitRef)
131
- end
131
+ context 'with an ambiguous ref' do
132
+ let(:tags) { ['topic'] }
133
+ let(:branches) { ['topic'] }
134
+
135
+ it 'raises an error' do
136
+ expect {
137
+ git.show_ref(repo_path, 'topic')
138
+ }.to raise_error(Berkshelf::AmbiguousGitRef)
132
139
  end
133
140
  end
141
+ end
134
142
 
135
- describe '::revision_from_ref' do
136
- let(:repo_path) { clone_target_for('nginx') }
137
- let(:tags) { ['1.0.1'] }
138
- let(:branches) { ['topic'] }
139
- let!(:repo) {
140
- origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
141
- git.clone(origin_uri, repo_path)
142
- }
143
-
144
- context 'with sha commit id' do
145
- let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
146
- it 'returns the passed revision' do
147
- git.revision_from_ref(repo_path, revision).should == revision
148
- end
143
+ describe '.revision_from_ref' do
144
+ let(:repo_path) { clone_target_for('nginx') }
145
+ let(:tags) { ['1.0.1'] }
146
+ let(:branches) { ['topic'] }
147
+ let!(:repo) {
148
+ origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
149
+ git.clone(origin_uri, repo_path)
150
+ }
151
+
152
+ context 'with sha commit id' do
153
+ let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
154
+ it 'returns the passed revision' do
155
+ rev = git.revision_from_ref(repo_path, revision)
156
+ expect(rev).to eq(revision)
149
157
  end
158
+ end
150
159
 
151
- context 'with tag' do
152
- let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
153
- it 'returns the revision' do
154
- git.revision_from_ref(repo_path, '1.0.1').should == revision
155
- end
160
+ context 'with tag' do
161
+ let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
162
+ it 'returns the revision' do
163
+ rev = git.revision_from_ref(repo_path, '1.0.1')
164
+ expect(rev).to eq(revision)
156
165
  end
166
+ end
157
167
 
158
- context 'with branch' do
159
- let(:revision) { git_sha_for_ref('nginx', 'topic') }
160
- it 'returns the revision' do
161
- git.revision_from_ref(repo_path, 'topic').should == revision
162
- end
168
+ context 'with branch' do
169
+ let(:revision) { git_sha_for_ref('nginx', 'topic') }
170
+ it 'returns the revision' do
171
+ rev = git.revision_from_ref(repo_path, 'topic')
172
+ expect(rev).to eq(revision)
163
173
  end
174
+ end
164
175
 
165
- context 'with an invalid ref' do
166
- let(:ref) { 'foobar' }
167
- it 'raises an error' do
168
- expect { git.revision_from_ref(repo_path, ref) }.to raise_error(Berkshelf::InvalidGitRef)
169
- end
176
+ context 'with an invalid ref' do
177
+ let(:ref) { 'foobar' }
178
+ it 'raises an error' do
179
+ expect {
180
+ git.revision_from_ref(repo_path, ref)
181
+ }.to raise_error(Berkshelf::InvalidGitRef)
170
182
  end
171
183
  end
184
+ end
172
185
 
173
- let(:readonly_uri) { "git://github.com/reset/thor-foodcritic.git" }
174
- let(:https_uri) { "https://github.com/reset/solve.git" }
175
- let(:http_uri) { "http://github.com/reset/solve.git" }
176
- let(:invalid_uri) { "/something/on/disk" }
186
+ let(:readonly_uri) { 'git://github.com/reset/thor-foodcritic.git' }
187
+ let(:https_uri) { 'https://github.com/reset/solve.git' }
188
+ let(:http_uri) { 'http://github.com/reset/solve.git' }
189
+ let(:invalid_uri) { '/something/on/disk' }
177
190
 
178
- describe "::validate_uri" do
179
- context "given a valid Git read-only URI" do
180
- it "returns true" do
181
- subject.validate_uri(readonly_uri).should be_true
182
- end
191
+ describe '.validate_uri' do
192
+ context 'given a valid Git read-only URI' do
193
+ it 'returns true' do
194
+ expect(Berkshelf::Git.validate_uri(readonly_uri)).to be_true
183
195
  end
196
+ end
184
197
 
185
- context "given a valid Git HTTPS URI" do
186
- it "returns true" do
187
- subject.validate_uri(https_uri).should be_true
188
- end
198
+ context 'given a valid Git HTTPS URI' do
199
+ it 'returns true' do
200
+ expect(Berkshelf::Git.validate_uri(https_uri)).to be_true
189
201
  end
202
+ end
190
203
 
191
- context "given a valid Github SSH URI" do
192
- it "returns true" do
193
- subject.validate_uri("git@github.com:reset/solve.git").should be_true
194
- end
204
+ context 'given a valid Github SSH URI' do
205
+ it 'returns true' do
206
+ expect(Berkshelf::Git.validate_uri('git@github.com:reset/solve.git')).to be_true
195
207
  end
208
+ end
196
209
 
197
- context "given a valid SSH URI without an 'organization'" do
198
- it "returns true" do
199
- subject.validate_uri("gituser@githost:solve.git").should be_true
200
- end
210
+ context "given a valid SSH URI without an 'organization'" do
211
+ it 'returns true' do
212
+ expect(Berkshelf::Git.validate_uri('gituser@githost:solve.git')).to be_true
201
213
  end
214
+ end
202
215
 
203
- context "given a valid git+ssh URI without an username" do
204
- it "returns true" do
205
- subject.validate_uri("git+ssh://host.com/repo").should be_true
206
- end
216
+ context 'given a valid git+ssh URI without an username' do
217
+ it 'returns true' do
218
+ expect(Berkshelf::Git.validate_uri('git+ssh://host.com/repo')).to be_true
207
219
  end
220
+ end
208
221
 
209
- context "given a valid git+ssh URI with an username" do
210
- it "returns true" do
211
- subject.validate_uri("git+ssh://user@host.com/repo").should be_true
212
- end
222
+ context 'given a valid git+ssh URI with an username' do
223
+ it 'returns true' do
224
+ expect(Berkshelf::Git.validate_uri('git+ssh://user@host.com/repo')).to be_true
213
225
  end
226
+ end
214
227
 
215
- context "given a valid URI with a dash in the hostname" do
216
- it "returns true" do
217
- subject.validate_uri("git://user@git-host.com/repo").should be_true
218
- end
228
+ context 'given a valid URI with a dash in the hostname' do
229
+ it 'returns true' do
230
+ expect(Berkshelf::Git.validate_uri('git://user@git-host.com/repo')).to be_true
219
231
  end
232
+ end
220
233
 
221
- context "given a valid URI with host being a subdomain" do
222
- it "returns true" do
223
- subject.validate_uri("git://user@git.host.com/repo").should be_true
224
- end
234
+ context 'given a valid URI with host being a subdomain' do
235
+ it 'returns true' do
236
+ expect(Berkshelf::Git.validate_uri('git://user@git.host.com/repo')).to be_true
225
237
  end
238
+ end
226
239
 
227
- context "given a valid git+ssh URI with home directory expansion" do
228
- it "returns true" do
229
- subject.validate_uri("git+ssh://user@host.com/~repo").should be_true
230
- end
240
+ context 'given a valid git+ssh URI with home directory expansion' do
241
+ it 'returns true' do
242
+ expect(Berkshelf::Git.validate_uri('git+ssh://user@host.com/~repo')).to be_true
231
243
  end
244
+ end
232
245
 
233
- context "given an invalid URI" do
234
- it "returns false" do
235
- subject.validate_uri(invalid_uri).should be_false
236
- end
246
+ context 'given an invalid URI' do
247
+ it 'returns false' do
248
+ expect(Berkshelf::Git.validate_uri(invalid_uri)).to be_false
237
249
  end
250
+ end
238
251
 
239
- context "given a HTTP URI" do
240
- it "returns true" do
241
- subject.validate_uri(http_uri).should be_true
242
- end
252
+ context 'given a HTTP URI' do
253
+ it 'returns true' do
254
+ expect(Berkshelf::Git.validate_uri(http_uri)).to be_true
243
255
  end
256
+ end
244
257
 
245
- context "given an integer" do
246
- it "returns false" do
247
- subject.validate_uri(123).should be_false
248
- end
258
+ context 'given an integer' do
259
+ it 'returns false' do
260
+ expect(Berkshelf::Git.validate_uri(123)).to be_false
249
261
  end
250
262
  end
263
+ end
251
264
 
252
- describe "::validate_uri!" do
253
- context "given a valid Git read-only URI" do
254
- it "returns true" do
255
- subject.validate_uri!(readonly_uri).should be_true
256
- end
265
+ describe '.validate_uri!' do
266
+ context 'given a valid Git read-only URI' do
267
+ it 'returns true' do
268
+ expect(Berkshelf::Git.validate_uri!(readonly_uri)).to be_true
257
269
  end
270
+ end
258
271
 
259
- context "given a valid Git HTTPS URI" do
260
- it "returns true" do
261
- subject.validate_uri!(https_uri).should be_true
262
- end
272
+ context 'given a valid Git HTTPS URI' do
273
+ it 'returns true' do
274
+ expect(Berkshelf::Git.validate_uri!(https_uri)).to be_true
263
275
  end
276
+ end
264
277
 
265
- context "given a valid Git SSH URI" do
266
- it "returns true" do
267
- subject.validate_uri!("git@github.com:reset/solve.git").should be_true
268
- end
278
+ context 'given a valid Git SSH URI' do
279
+ it 'returns true' do
280
+ expect(Berkshelf::Git.validate_uri!('git@github.com:reset/solve.git')).to be_true
269
281
  end
282
+ end
270
283
 
271
- context "given a valid SSH URI without an 'organization'" do
272
- it "returns true" do
273
- subject.validate_uri("gituser@githost:solve.git").should be_true
274
- end
284
+ context "given a valid SSH URI without an 'organization'" do
285
+ it 'returns true' do
286
+ expect(Berkshelf::Git.validate_uri('gituser@githost:solve.git')).to be_true
275
287
  end
288
+ end
276
289
 
277
- context "given an invalid URI" do
278
- it "raises InvalidGitURI" do
279
- lambda {
280
- subject.validate_uri!(invalid_uri)
281
- }.should raise_error(Berkshelf::InvalidGitURI)
282
- end
290
+ context 'given an invalid URI' do
291
+ it 'raises InvalidGitURI' do
292
+ expect {
293
+ Berkshelf::Git.validate_uri!(invalid_uri)
294
+ }.to raise_error(Berkshelf::InvalidGitURI)
283
295
  end
296
+ end
284
297
 
285
- context "given a HTTP URI" do
286
- it "raises InvalidGitURI" do
287
- subject.validate_uri!(http_uri).should be_true
288
- end
298
+ context 'given a HTTP URI' do
299
+ it 'raises InvalidGitURI' do
300
+ expect(Berkshelf::Git.validate_uri!(http_uri)).to be_true
289
301
  end
302
+ end
290
303
 
291
- context "given an integer" do
292
- it "raises InvalidGitURI" do
293
- lambda {
294
- subject.validate_uri!(123)
295
- }.should raise_error(Berkshelf::InvalidGitURI)
296
- end
304
+ context 'given an integer' do
305
+ it 'raises InvalidGitURI' do
306
+ expect {
307
+ Berkshelf::Git.validate_uri!(123)
308
+ }.to raise_error(Berkshelf::InvalidGitURI)
297
309
  end
298
310
  end
299
311
  end