boxci 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +146 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +118 -0
  8. data/Rakefile +13 -0
  9. data/bin/boxci +6 -0
  10. data/boxci.gemspec +28 -0
  11. data/lib/boxci/builder.rb +29 -0
  12. data/lib/boxci/cli.rb +70 -0
  13. data/lib/boxci/config_permutation.rb +15 -0
  14. data/lib/boxci/config_permutation_component.rb +11 -0
  15. data/lib/boxci/config_permutation_component_factory.rb +7 -0
  16. data/lib/boxci/config_permutation_components/rbenv.rb +13 -0
  17. data/lib/boxci/dependency_checker.rb +55 -0
  18. data/lib/boxci/global_config.rb +26 -0
  19. data/lib/boxci/initializer.rb +41 -0
  20. data/lib/boxci/language.rb +35 -0
  21. data/lib/boxci/language_factory.rb +7 -0
  22. data/lib/boxci/languages/ruby.rb +31 -0
  23. data/lib/boxci/project_config.rb +96 -0
  24. data/lib/boxci/provider.rb +35 -0
  25. data/lib/boxci/provider_config.rb +23 -0
  26. data/lib/boxci/provider_factory.rb +7 -0
  27. data/lib/boxci/providers/aws.rb +27 -0
  28. data/lib/boxci/providers/openstack.rb +27 -0
  29. data/lib/boxci/providers/virtualbox.rb +24 -0
  30. data/lib/boxci/templates/Vagrantfile +41 -0
  31. data/lib/boxci/templates/boxci/global_config.yml.tt +1 -0
  32. data/lib/boxci/templates/dot_boxci.yml.tt +11 -0
  33. data/lib/boxci/templates/languages/ruby/main.pp +27 -0
  34. data/lib/boxci/templates/providers/aws/Vagrantfile.erb +45 -0
  35. data/lib/boxci/templates/providers/aws.yml.tt +5 -0
  36. data/lib/boxci/templates/providers/openstack/Vagrantfile.erb +37 -0
  37. data/lib/boxci/templates/providers/openstack.yml.tt +16 -0
  38. data/lib/boxci/templates/providers/virtualbox/Vagrantfile.erb +47 -0
  39. data/lib/boxci/templates/providers/virtualbox.yml.tt +2 -0
  40. data/lib/boxci/templates/puppet/manifests/.empty_directory +0 -0
  41. data/lib/boxci/templates/puppet/modules/.empty_directory +0 -0
  42. data/lib/boxci/test_runner.rb +134 -0
  43. data/lib/boxci/tester.rb +287 -0
  44. data/lib/boxci/version.rb +3 -0
  45. data/lib/boxci.rb +71 -0
  46. data/spec/lib/boxci/builder_spec.rb +86 -0
  47. data/spec/lib/boxci/config_permutation_component_factory_spec.rb +17 -0
  48. data/spec/lib/boxci/config_permutation_component_spec.rb +19 -0
  49. data/spec/lib/boxci/config_permutation_components/rbenv_spec.rb +12 -0
  50. data/spec/lib/boxci/config_permutation_spec.rb +27 -0
  51. data/spec/lib/boxci/dependency_checker_spec.rb +215 -0
  52. data/spec/lib/boxci/global_config_spec.rb +34 -0
  53. data/spec/lib/boxci/initializer_spec.rb +117 -0
  54. data/spec/lib/boxci/language_factory_spec.rb +17 -0
  55. data/spec/lib/boxci/language_spec.rb +31 -0
  56. data/spec/lib/boxci/project_config_spec.rb +218 -0
  57. data/spec/lib/boxci/provider_config_spec.rb +39 -0
  58. data/spec/lib/boxci/provider_factory_spec.rb +17 -0
  59. data/spec/lib/boxci/provider_spec.rb +30 -0
  60. data/spec/lib/boxci/tester_spec.rb +15 -0
  61. data/spec/lib/boxci_spec.rb +176 -0
  62. data/spec/spec_helper.rb +11 -0
  63. metadata +213 -0
@@ -0,0 +1,215 @@
1
+ require "spec_helper"
2
+
3
+ describe Boxci::DependencyChecker do
4
+ describe "#verify_all" do
5
+ before do
6
+ allow(subject).to receive(:verify_vagrant)
7
+ allow(subject).to receive(:verify_cloud_provider_config)
8
+ allow(subject).to receive(:verify_repo_puppet_directory)
9
+ allow(subject).to receive(:verify_vagrantfile)
10
+ end
11
+
12
+ it "checks if vagrant is installed" do
13
+ expect(subject).to receive(:verify_vagrant)
14
+ subject.verify_all
15
+ end
16
+
17
+ it "checks if the cloud_provider_config exists" do
18
+ expect(subject).to receive(:verify_cloud_provider_config)
19
+ subject.verify_all
20
+ end
21
+
22
+ it "verifies the repository has the required puppet directory structure" do
23
+ expect(subject).to receive(:verify_repo_puppet_directory)
24
+ subject.verify_all
25
+ end
26
+
27
+ it "verifies the vagrantfile exists" do
28
+ expect(subject).to receive(:verify_vagrantfile)
29
+ subject.verify_all
30
+ end
31
+
32
+ context "when a dependency fails" do
33
+ before do
34
+ allow(subject).to receive(:verify_vagrant).and_raise(Boxci::MissingDependency, "Error message 123")
35
+ allow(subject).to receive(:exit)
36
+ allow(subject).to receive(:puts)
37
+ end
38
+
39
+ it "rescues the exception" do
40
+ expect { subject.verify_all }.to_not raise_error
41
+ end
42
+
43
+ it "outputs the error message" do
44
+ expect(subject).to receive(:puts).with("Error message 123")
45
+ subject.verify_all
46
+ end
47
+
48
+ it "exits" do
49
+ expect(subject).to receive(:exit)
50
+ subject.verify_all
51
+ end
52
+ end
53
+
54
+ context "when no dependencies fail" do
55
+ before do
56
+ allow(Boxci::DependencyChecker).to receive(:verify_all).and_return(true)
57
+ end
58
+
59
+ it "does not output anything" do
60
+ expect(subject).to_not receive(:puts)
61
+ subject.verify_all
62
+ end
63
+
64
+ it "does not exit" do
65
+ expect(subject).to_not receive(:exit)
66
+ subject.verify_all
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#verify_vagrant" do
72
+ it "checks if the system path includes 'vagrant'" do
73
+ expect(subject).to receive(:system).with("which vagrant > /dev/null").and_return(true)
74
+ subject.verify_vagrant
75
+ end
76
+
77
+ context "when vagrant is verified" do
78
+ before do
79
+ allow(subject).to receive(:system).and_return(true)
80
+ end
81
+
82
+ it "does not raise an error" do
83
+ expect { subject.verify_vagrant }.to_not raise_error
84
+ end
85
+ end
86
+
87
+ context "when vagrant is not verified" do
88
+ before do
89
+ allow(subject).to receive(:system).and_return(false)
90
+ end
91
+
92
+ it "raises an error" do
93
+ expect { subject.verify_vagrant }.to raise_error(Boxci::MissingDependency)
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#verify_cloud_provider_config" do
99
+ it "checks if the the '.cloud_provider_config' exists in the user's home dir" do
100
+ cloud_provider_file = File.join(File.expand_path(ENV["HOME"]), ".boxci", "cloud_provider_config.yml")
101
+ expect(File).to receive(:exists?).with(cloud_provider_file).and_return(true)
102
+ subject.verify_cloud_provider_config
103
+ end
104
+
105
+ context "when the config is verified" do
106
+ before do
107
+ expect(File).to receive(:exists?).and_return(true)
108
+ end
109
+
110
+ it "does not raise an error" do
111
+ expect { subject.verify_cloud_provider_config }.to_not raise_error
112
+ end
113
+ end
114
+
115
+ context "when the config is not verified" do
116
+ before do
117
+ expect(File).to receive(:exists?).and_return(false)
118
+ end
119
+
120
+ it "raises an error" do
121
+ expect { subject.verify_cloud_provider_config }.to raise_error(Boxci::MissingDependency)
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "#verify_repo_puppet_directory" do
127
+ let(:project_path) { "/some/path" }
128
+
129
+ before do
130
+ allow(Boxci).to receive(:project_path).and_return(project_path)
131
+ allow(File).to receive(:directory?).and_return(true)
132
+ end
133
+
134
+ it "checks for the puppet directory in the repo root" do
135
+ expect(File).to receive(:directory?).with(File.join(project_path, "puppet")).and_return(true)
136
+ subject.verify_repo_puppet_directory
137
+ end
138
+
139
+ context "when the directory is present" do
140
+ it "does not raise an error" do
141
+ expect { subject.verify_repo_puppet_directory }.to_not raise_error
142
+ end
143
+ end
144
+
145
+ context "when the directory is not present" do
146
+ before do
147
+ allow(File).to receive(:directory?).and_return(false)
148
+ end
149
+
150
+ it "raises an error" do
151
+ expect { subject.verify_repo_puppet_directory }.to raise_error(Boxci::MissingDependency)
152
+ end
153
+ end
154
+ end
155
+
156
+ describe "#verify_vagrantfile" do
157
+ let(:project_path) { "/some/path" }
158
+
159
+ before do
160
+ allow(Boxci).to receive(:project_path).and_return(project_path)
161
+ allow(File).to receive(:exists?).and_return(true)
162
+ end
163
+
164
+ it "checks for the Vagrantfile in the repo root" do
165
+ expect(File).to receive(:exists?).with(File.join(project_path, "Vagrantfile")).and_return(true)
166
+ subject.verify_vagrantfile
167
+ end
168
+
169
+ context "when the vagrantfile is verified" do
170
+ it "does not raise an error" do
171
+ expect { subject.verify_vagrantfile }.to_not raise_error
172
+ end
173
+ end
174
+
175
+ context "when the vagrantfile is not verified" do
176
+ before do
177
+ allow(File).to receive(:exists?).and_return(false)
178
+ end
179
+
180
+ it "raises an error" do
181
+ expect { subject.verify_vagrantfile }.to raise_error(Boxci::MissingDependency)
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "#verify_boxci_config" do
187
+ let(:project_path) { "/some/path" }
188
+
189
+ before do
190
+ allow(Boxci).to receive(:project_path).and_return(project_path)
191
+ allow(File).to receive(:exists?).and_return(true)
192
+ end
193
+
194
+ it "checks for the Boxci config file in the repo root" do
195
+ expect(File).to receive(:exists?).with(File.join(project_path, ".boxci.yml")).and_return(true)
196
+ subject.verify_boxci_config
197
+ end
198
+
199
+ context "when the config file is verified" do
200
+ it "does not raise an error" do
201
+ expect { subject.verify_boxci_config }.to_not raise_error
202
+ end
203
+ end
204
+
205
+ context "when the config file is not verified" do
206
+ before do
207
+ allow(File).to receive(:exists?).and_return(false)
208
+ end
209
+
210
+ it "raises an error" do
211
+ expect { subject.verify_boxci_config }.to raise_error(Boxci::MissingDependency)
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::GlobalConfig do
4
+ describe "#initialize" do
5
+ it "sets the config to sane values" do
6
+ subject
7
+ expect(subject.instance_variable_get(:@global_config)).not_to be_nil
8
+ end
9
+ end
10
+
11
+ describe "#load" do
12
+ it "reads the global config hash" do
13
+ expect(subject).to receive(:read_global_config_hash).and_return({})
14
+ subject.load
15
+ end
16
+
17
+ it "merges the read project config hash with the defaults" do
18
+ default_hash = double
19
+ subject.instance_variable_set(:@global_config, default_hash)
20
+ read_hash = double
21
+ allow(subject).to receive(:read_global_config_hash).and_return(read_hash)
22
+ expect(default_hash).to receive(:merge!).with(read_hash)
23
+ subject.load
24
+ end
25
+ end
26
+
27
+ describe "#default_provider" do
28
+ it "returns the default_provider from the config hash" do
29
+ allow(subject).to receive(:read_global_config_hash).and_return({'default_provider' => 'hoopty'})
30
+ subject.load
31
+ expect(subject.default_provider).to eq('hoopty')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,117 @@
1
+ require "spec_helper"
2
+
3
+ describe Boxci::Initializer do
4
+ describe "#init" do
5
+ before do
6
+ allow(subject).to receive(:create_provider_config)
7
+ allow(subject).to receive(:set_default_provider)
8
+ allow(subject).to receive(:create_project_config)
9
+ end
10
+
11
+ it "creates provider specific config" do
12
+ provider_double = double
13
+ expect(subject).to receive(:create_provider_config).with(provider_double)
14
+ subject.init(double, provider_double)
15
+ end
16
+
17
+ it "sets the default provider" do
18
+ provider_double = double
19
+ expect(subject).to receive(:set_default_provider).with(provider_double)
20
+ subject.init(double, provider_double)
21
+ end
22
+
23
+ it "creates the project config" do
24
+ language_double = double
25
+ expect(subject).to receive(:create_project_config).with(language_double)
26
+ subject.init(language_double, double)
27
+ end
28
+ end
29
+
30
+ describe "#create_provider_config" do
31
+ it "renders the provider specific config" do
32
+ expect(subject).to receive(:template).with("templates/providers/foo.yml.tt", "~/.boxci/providers/foo.yml")
33
+ subject.create_provider_config('foo')
34
+ end
35
+ end
36
+
37
+ describe "#set_default_provider" do
38
+ it "assigns the provider to an instance variable" do
39
+ allow(subject).to receive(:template)
40
+ subject.set_default_provider('aws')
41
+ expect(subject.instance_variable_get(:@provider)).to eq('aws')
42
+ end
43
+
44
+ it "creates the global_config.yml setting the default provider" do
45
+ expect(subject).to receive(:template).with("templates/boxci/global_config.yml.tt", "~/.boxci/global_config.yml")
46
+ subject.set_default_provider('aws')
47
+ end
48
+ end
49
+
50
+ describe "#create_project_config" do
51
+ let(:local_repository_path) { "/somewhere" }
52
+
53
+ before do
54
+ allow(subject).to receive(:local_repository_path).and_return(local_repository_path)
55
+ end
56
+
57
+ it "assigns the given language to @language" do
58
+ allow(subject).to receive(:template)
59
+ language = double
60
+ subject.create_project_config(language)
61
+ expect(subject.instance_variable_get(:@language)).to eq(language)
62
+ end
63
+
64
+ it "assigns the current ruby version found in .ruby-version to @current_ruby_version" do
65
+ allow(subject).to receive(:template)
66
+ ruby_version = double
67
+ allow(subject).to receive(:dot_ruby_version).and_return(ruby_version)
68
+ subject.create_project_config('ruby')
69
+ expect(subject.instance_variable_get(:@current_ruby_version)).to eq(ruby_version)
70
+ end
71
+
72
+ it "renders the dot_boxci.yml.tt from the templates to the project root .boxci.yml" do
73
+ expect(subject).to receive(:template).with("templates/dot_boxci.yml.tt", File.join(Boxci.project_path, ".boxci.yml"))
74
+ subject.create_project_config('ruby')
75
+ end
76
+ end
77
+
78
+ describe "#dot_ruby_version" do
79
+ context "when the .ruby-version file exists" do
80
+ before do
81
+ allow(File).to receive(:exist?).and_return(true)
82
+ end
83
+
84
+ context "when format is ruby-1.9.3-p327@fooo" do
85
+ it "returns '1.9.3-p327'" do
86
+ allow(File).to receive(:read).and_return('ruby-1.9.3-p327@fooo')
87
+ expect(subject.dot_ruby_version).to eq('1.9.3-p327')
88
+ end
89
+ end
90
+
91
+ context "when format is ruby-2.1.0" do
92
+ it "returns '2.1.0'" do
93
+ allow(File).to receive(:read).and_return('ruby-2.1.0')
94
+ expect(subject.dot_ruby_version).to eq('2.1.0')
95
+ end
96
+ end
97
+
98
+ context "when format is 2.1.0" do
99
+ it "returns '2.1.0'" do
100
+ allow(File).to receive(:read).and_return('2.1.0')
101
+ expect(subject.dot_ruby_version).to eq('2.1.0')
102
+ end
103
+ end
104
+ end
105
+
106
+ context "when the .ruby-version does NOT exist" do
107
+ before do
108
+ allow(File).to receive(:exist?).and_return(false)
109
+ end
110
+
111
+ it "returns nil" do
112
+ allow(File).to receive(:exist?).and_return(false)
113
+ expect(subject.dot_ruby_version).to be_nil
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::LanguageFactory do
4
+ describe ".build" do
5
+ it "gets the constant for the language class" do
6
+ expect(Boxci::Languages).to receive(:const_get).with('Ruby').and_return(double.as_null_object)
7
+ subject.build('ruby')
8
+ end
9
+
10
+ it "constructs a new instance of the language const it previously grabbed" do
11
+ lang = double
12
+ allow(Boxci::Languages).to receive(:const_get).with('Ruby').and_return(lang)
13
+ expect(lang).to receive(:new)
14
+ subject.build('ruby')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::Language do
4
+ describe "#before_permutation_switch" do
5
+ it "returns empty string" do
6
+ expect(subject.before_permutation_switch).to eq("")
7
+ end
8
+ end
9
+
10
+ describe "#after_permutation_switch" do
11
+ it "returns empty string" do
12
+ expect(subject.after_permutation_switch).to eq("")
13
+ end
14
+ end
15
+
16
+ describe "#default_script" do
17
+ it "raises an exception when not implemented by subclass" do
18
+ class Boxci::Provider::TestPureVirtualLanguagePuppetManifestOne < ::Boxci::Language
19
+ end
20
+ expect { Boxci::Provider::TestPureVirtualLanguagePuppetManifestOne.new.default_script }.to raise_error(Boxci::PureVirtualMethod)
21
+ end
22
+ end
23
+
24
+ describe "#generate_starter_puppet_manifest" do
25
+ it "raises an exception when not implemented by subclass" do
26
+ class Boxci::Provider::TestPureVirtualLanguagePuppetManifestTwo < ::Boxci::Language
27
+ end
28
+ expect { Boxci::Provider::TestPureVirtualLanguagePuppetManifestTwo.new.generate_starter_puppet_manifest }.to raise_error(Boxci::PureVirtualMethod)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,218 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::ProjectConfig do
4
+ describe "#initialize" do
5
+ it "sets the config has to sane values" do
6
+ subject
7
+ expect(subject.instance_variable_get(:@project_config)).not_to be_nil
8
+ end
9
+ end
10
+
11
+ describe "#load" do
12
+ it "reads the project config hash" do
13
+ expect(subject).to receive(:read_project_config_hash).and_return({})
14
+ subject.load
15
+ end
16
+
17
+ it "merges the read project config hash with the defaults" do
18
+ default_hash = double
19
+ subject.instance_variable_set(:@project_config, default_hash)
20
+ read_hash = double
21
+ allow(subject).to receive(:read_project_config_hash).and_return(read_hash)
22
+ expect(default_hash).to receive(:merge!).with(read_hash)
23
+ subject.load
24
+ end
25
+ end
26
+
27
+ describe "#language" do
28
+ it "returns the language from the config hash" do
29
+ allow(subject).to receive(:read_project_config_hash).and_return({'language' => 'java'})
30
+ subject.load
31
+ expect(subject.language).to eq('java')
32
+ end
33
+ end
34
+
35
+ describe "#puppet_facts" do
36
+ context "when puppet facts are provided in the project config" do
37
+ it "returns the puppet facts from the config hash" do
38
+ facters = {"test_key" => "test_value"}
39
+ subject.instance_variable_set(:@project_config, {"puppet_facts" => facters})
40
+ expect(subject.puppet_facts).to eq(facters)
41
+ end
42
+ end
43
+
44
+ context "when puppet facts are NOT provided in the project config" do
45
+ it "returns an empty array" do
46
+ subject.instance_variable_set(:@project_config, {})
47
+ expect(subject.puppet_facts).to eq([])
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "#box_size" do
53
+ context "when the config has a box size specified" do
54
+ it "returns the users specified box size" do
55
+ box_size_double = double('box size double')
56
+ subject.instance_variable_set(:@project_config, {"box_size" => box_size_double })
57
+ expect(subject.box_size).to eq(box_size_double)
58
+ end
59
+ end
60
+
61
+ context "when the config does NOT have a box size specified" do
62
+ it "returns the default box size" do
63
+ expect(subject.box_size).to eq('small')
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#artifact_path" do
69
+ context "when the config has an artifact path specified" do
70
+ it "returns the artifact path specified in the config" do
71
+ artifact_path_double = double('artifact path double')
72
+ subject.instance_variable_set(:@project_config, { "artifact_path" => artifact_path_double })
73
+ expect(subject.artifact_path).to eq(artifact_path_double)
74
+ end
75
+ end
76
+
77
+ context "when the config does NOT have an artifact path specified" do
78
+ it "returns the default artifact path" do
79
+ expect(subject.artifact_path).to eq('/tmp/boxci/artifacts')
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#before_install" do
85
+ context "when before_install is provided in the project config" do
86
+ it "grabs the named hook as an array" do
87
+ subject.instance_variable_set(:@project_config, { 'before_install' => double })
88
+ expect(subject).to receive(:option_as_array).with('before_install')
89
+ subject.before_install
90
+ end
91
+ end
92
+
93
+ context "when before_install is NOT provided in the project config" do
94
+ it "returns an empty array" do
95
+ subject.instance_variable_set(:@project_config, {})
96
+ expect(subject.before_install).to eq([])
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#install" do
102
+ context "when install is provided in the project config" do
103
+ it "grabs the named hook as an array" do
104
+ subject.instance_variable_set(:@project_config, { 'install' => double })
105
+ expect(subject).to receive(:option_as_array).with('install')
106
+ subject.install
107
+ end
108
+ end
109
+
110
+ context "when install is NOT provided in the project config" do
111
+ it "returns an empty array" do
112
+ subject.instance_variable_set(:@project_config, {})
113
+ expect(subject.install).to eq([])
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#before_script" do
119
+ context "when before_script is provided in the project config" do
120
+ it "grabs the named hook as an array" do
121
+ subject.instance_variable_set(:@project_config, { 'before_script' => double })
122
+ expect(subject).to receive(:option_as_array).with('before_script')
123
+ subject.before_script
124
+ end
125
+ end
126
+
127
+ context "when before_script is NOT provided in the project config" do
128
+ it "returns an empty array" do
129
+ subject.instance_variable_set(:@project_config, {})
130
+ expect(subject.before_script).to eq([])
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "#script" do
136
+ context "when script is provided in the project config" do
137
+ it "grabs the named hook as an array" do
138
+ subject.instance_variable_set(:@project_config, { 'script' => double })
139
+ expect(subject).to receive(:option_as_array).with('script')
140
+ subject.script
141
+ end
142
+ end
143
+
144
+ context "when script is NOT provided in the project config" do
145
+ it "returns an empty array" do
146
+ subject.instance_variable_set(:@project_config, {})
147
+ expect(subject.script).to eq([])
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#after_failure" do
153
+ context "when after_failure is provided in the project config" do
154
+ it "grabs the named hook as an array" do
155
+ subject.instance_variable_set(:@project_config, { 'after_failure' => double })
156
+ expect(subject).to receive(:option_as_array).with('after_failure')
157
+ subject.after_failure
158
+ end
159
+ end
160
+
161
+ context "when after_failure is NOT provided in the project config" do
162
+ it "returns an empty array" do
163
+ subject.instance_variable_set(:@project_config, {})
164
+ expect(subject.after_failure).to eq([])
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "#after_success" do
170
+ context "when after_success is provided in the project config" do
171
+ it "grabs the named hook as an array" do
172
+ subject.instance_variable_set(:@project_config, { 'after_success' => double })
173
+ expect(subject).to receive(:option_as_array).with('after_success')
174
+ subject.after_success
175
+ end
176
+ end
177
+
178
+ context "when after_success is NOT provided in the project config" do
179
+ it "returns an empty array" do
180
+ subject.instance_variable_set(:@project_config, {})
181
+ expect(subject.after_success).to eq([])
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "#after_script" do
187
+ context "when after_script is provided in the project config" do
188
+ it "grabs the named hook as an array" do
189
+ subject.instance_variable_set(:@project_config, { 'after_script' => double })
190
+ expect(subject).to receive(:option_as_array).with('after_script')
191
+ subject.after_script
192
+ end
193
+ end
194
+
195
+ context "when after_script is NOT provided in the project config" do
196
+ it "returns an empty array" do
197
+ subject.instance_variable_set(:@project_config, {})
198
+ expect(subject.after_script).to eq([])
199
+ end
200
+ end
201
+ end
202
+
203
+ describe "#option_as_array" do
204
+ context "when the value is an array" do
205
+ it "returns the value" do
206
+ subject.instance_variable_set(:@project_config, { 'foo' => [1, 2, 3] })
207
+ expect(subject.send(:option_as_array, 'foo')).to eq([1, 2, 3])
208
+ end
209
+ end
210
+
211
+ context "when not the value is not an array" do
212
+ it "returns the value as the only item in an array" do
213
+ subject.instance_variable_set(:@project_config, { 'foo' => 1 })
214
+ expect(subject.send(:option_as_array, 'foo')).to eq([1])
215
+ end
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::ProviderConfig do
4
+ subject { Boxci::ProviderConfig.new("aws") }
5
+
6
+ describe "#initialize" do
7
+ it "sets the config to sane values" do
8
+ expect(subject.instance_variable_get(:@provider_config)).not_to be_nil
9
+ end
10
+
11
+ it "sets the provider instance variable to the given provider" do
12
+ expect(subject.instance_variable_get(:@provider)).to eq('aws')
13
+ end
14
+ end
15
+
16
+ describe "#load" do
17
+ it "reads the provider config hash" do
18
+ expect(subject).to receive(:read_provider_config_hash).and_return({})
19
+ subject.load
20
+ end
21
+
22
+ it "merges the read project config hash with the defaults" do
23
+ default_hash = double
24
+ subject.instance_variable_set(:@provider_config, default_hash)
25
+ read_hash = double
26
+ allow(subject).to receive(:read_provider_config_hash).and_return(read_hash)
27
+ expect(default_hash).to receive(:merge!).with(read_hash)
28
+ subject.load
29
+ end
30
+ end
31
+
32
+ describe "#fetch" do
33
+ it "returns the value from the config hash matching the passed key" do
34
+ configs = {"key1" => "value1", "key2" => "value2"}
35
+ subject.instance_variable_set(:@provider_config, configs)
36
+ expect(subject.fetch("key1")).to eq("value1")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxci::ProviderFactory do
4
+ describe ".build" do
5
+ it "gets the constant for the provider class" do
6
+ expect(Boxci::Providers).to receive(:const_get).with('Aws').and_return(double.as_null_object)
7
+ subject.build('aws')
8
+ end
9
+
10
+ it "constructs a new instance of the provider const it previously grabbed" do
11
+ lang = double
12
+ allow(Boxci::Providers).to receive(:const_get).with('Aws').and_return(lang)
13
+ expect(lang).to receive(:new)
14
+ subject.build('aws')
15
+ end
16
+ end
17
+ end