chef-sugar 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Ruby do
4
+ it_behaves_like 'a chef sugar'
5
+
6
+ describe '#ruby_20?' do
7
+ it 'returns true when the ruby version is 2.0' do
8
+ node = { 'languages' => { 'ruby' => { 'version' => '2.0.0' } } }
9
+ expect(described_class.ruby_20?(node)).to be_true
10
+ end
11
+
12
+ it 'returns true when the ruby version is less than 2.0' do
13
+ node = { 'languages' => { 'ruby' => { 'version' => '1.9.3' } } }
14
+ expect(described_class.ruby_20?(node)).to be_false
15
+ end
16
+
17
+ it 'returns false when the ruby version is higher than 2.0' do
18
+ node = { 'languages' => { 'ruby' => { 'version' => '3.0.0' } } }
19
+ expect(described_class.ruby_20?(node)).to be_false
20
+ end
21
+ end
22
+
23
+ describe '#ruby_19?' do
24
+ it 'returns true when the ruby version is 1.9' do
25
+ node = { 'languages' => { 'ruby' => { 'version' => '1.9.1' } } }
26
+ expect(described_class.ruby_19?(node)).to be_true
27
+ end
28
+
29
+ it 'returns true when the ruby version is less than 1.9' do
30
+ node = { 'languages' => { 'ruby' => { 'version' => '1.8.7' } } }
31
+ expect(described_class.ruby_19?(node)).to be_false
32
+ end
33
+
34
+ it 'returns false when the ruby version is higher than 1.9' do
35
+ node = { 'languages' => { 'ruby' => { 'version' => '2.0.0' } } }
36
+ expect(described_class.ruby_19?(node)).to be_false
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Shell do
4
+ describe '#which' do
5
+ it 'returns the first executable matching the command' do
6
+ File.stub(:executable?).and_return(false)
7
+ File.stub(:executable?).with('/usr/bin/mongo').and_return(true)
8
+ expect(described_class.which('mongo')).to eq('/usr/bin/mongo')
9
+ end
10
+
11
+ it 'returns nil when no command is found' do
12
+ File.stub(:executable?).and_return(false)
13
+ expect(described_class.which('node')).to be_nil
14
+ end
15
+ end
16
+
17
+ describe '#dev_null' do
18
+ it 'returns NUL on Windows' do
19
+ node = { 'platform_family' => 'windows' }
20
+ expect(described_class.dev_null(node)).to eq('NUL')
21
+ end
22
+
23
+ it 'returns /dev/null on Linux' do
24
+ node = { 'platform_family' => 'debian' }
25
+ expect(described_class.dev_null(node)).to eq('/dev/null')
26
+ end
27
+ end
28
+
29
+ describe '#installed?' do
30
+ it 'returns true if the given binary exists' do
31
+ File.stub(:which).and_return(false)
32
+ File.stub(:which).with('/usr/bin/mongo').and_return(true)
33
+ expect(described_class.installed?('mongo')).to be_true
34
+ end
35
+
36
+ it 'returns false if the given binary does not exist' do
37
+ File.stub(:executable?).and_return(false)
38
+ expect(described_class.installed?('node')).to be_false
39
+ end
40
+ end
41
+
42
+ describe '#installed_at_version?' do
43
+ it 'returns true if the command is installed at the correct version' do
44
+ described_class.stub(:which).and_return(true)
45
+ described_class.stub(:version_for).and_return('1.2.3')
46
+ expect(described_class.installed_at_version?('mongo', '1.2.3')).to be_true
47
+ end
48
+
49
+ it 'returns true if the command is installed at the correct version and has additional output' do
50
+ described_class.stub(:which).and_return(true)
51
+ described_class.stub(:version_for).and_return('Mongo DB version 1.2.3. Some other text.')
52
+ expect(described_class.installed_at_version?('mongo', '1.2.3')).to be_true
53
+ end
54
+
55
+ it 'returns true if the command is installed at the correct version with a regex' do
56
+ described_class.stub(:which).and_return(true)
57
+ described_class.stub(:version_for).and_return('1.2.3')
58
+ expect(described_class.installed_at_version?('mongo', /1\.2/)).to be_true
59
+ end
60
+
61
+ it 'returns false if the command is installed at the wrong version' do
62
+ described_class.stub(:which).and_return(true)
63
+ described_class.stub(:version_for).and_return('1.2.3')
64
+ expect(described_class.installed_at_version?('mongo', '4.5.6')).to be_false
65
+ end
66
+
67
+ it 'returns false if the command is not installed' do
68
+ described_class.stub(:which).and_return(nil)
69
+ expect(described_class.installed_at_version?('mongo', '1.0.0')).to be_false
70
+ end
71
+ end
72
+
73
+ describe '#version_for' do
74
+ let(:shell_out) { double('shell_out', run_command: nil, error!: nil, stdout: '1.2.3') }
75
+ before { Mixlib::ShellOut.stub(:new).and_return(shell_out) }
76
+
77
+ it 'runs the thing in shellout' do
78
+ expect(Mixlib::ShellOut).to receive(:new).with('mongo --version')
79
+ described_class.version_for('mongo')
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Vagrant do
4
+ it_behaves_like 'a chef sugar'
5
+
6
+ describe '#vagrant?' do
7
+ it 'returns true when the machine is on vagrant' do
8
+ node = { 'vagrant' => {} }
9
+ expect(described_class.vagrant?(node)).to be_true
10
+ end
11
+
12
+ it 'returns false when the machine is not on vagrant' do
13
+ node = {}
14
+ expect(described_class.vagrant?(node)).to be_false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'chef-sugar::default' do
4
+ let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
5
+
6
+ it 'installs the chef gem' do
7
+ expect(chef_run).to install_chef_gem('chef-sugar').with(version: '1.0.0')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-sugar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta.1
5
+ platform: ruby
6
+ authors:
7
+ - Seth Vargo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chef
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '11.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '11.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: chefspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta
83
+ - !ruby/object:Gem::Dependency
84
+ name: foodcritic
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-kitchen
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0.beta
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0.beta
111
+ - !ruby/object:Gem::Dependency
112
+ name: kitchen-vagrant
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.11'
125
+ description: A series of helpful sugar of the Chef core and other resources to make
126
+ a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes
127
+ an awesome experience!
128
+ email:
129
+ - sethvargo@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .kitchen.yml
136
+ - .travis.yml
137
+ - CHANGELOG.md
138
+ - CONTRIBUTING.md
139
+ - Gemfile
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - chef-extensions.gemspec
144
+ - lib/chef/sugar.rb
145
+ - lib/chef/sugar/architecture.rb
146
+ - lib/chef/sugar/cloud.rb
147
+ - lib/chef/sugar/ip.rb
148
+ - lib/chef/sugar/node.rb
149
+ - lib/chef/sugar/platform.rb
150
+ - lib/chef/sugar/platform_family.rb
151
+ - lib/chef/sugar/ruby.rb
152
+ - lib/chef/sugar/shell.rb
153
+ - lib/chef/sugar/vagrant.rb
154
+ - lib/chef/sugar/version.rb
155
+ - metadata.rb
156
+ - recipes/default.rb
157
+ - spec/spec_helper.rb
158
+ - spec/support/shared_examples.rb
159
+ - spec/unit/chef/extensions/architecture_spec.rb
160
+ - spec/unit/chef/extensions/cloud_spec.rb
161
+ - spec/unit/chef/extensions/ip_spec.rb
162
+ - spec/unit/chef/extensions/node_spec.rb
163
+ - spec/unit/chef/extensions/platform_family_spec.rb
164
+ - spec/unit/chef/extensions/platform_spec.rb
165
+ - spec/unit/chef/extensions/ruby_spec.rb
166
+ - spec/unit/chef/extensions/shell_spec.rb
167
+ - spec/unit/chef/extensions/vagrant_spec.rb
168
+ - spec/unit/recipes/default_spec.rb
169
+ homepage: https://github.com/sethvargo/chef-sugar
170
+ licenses:
171
+ - Apache 2.0
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '1.9'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>'
185
+ - !ruby/object:Gem::Version
186
+ version: 1.3.1
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.0.3
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: A collection of helper methods and modules that make working with Chef recipes
193
+ awesome.
194
+ test_files:
195
+ - spec/spec_helper.rb
196
+ - spec/support/shared_examples.rb
197
+ - spec/unit/chef/extensions/architecture_spec.rb
198
+ - spec/unit/chef/extensions/cloud_spec.rb
199
+ - spec/unit/chef/extensions/ip_spec.rb
200
+ - spec/unit/chef/extensions/node_spec.rb
201
+ - spec/unit/chef/extensions/platform_family_spec.rb
202
+ - spec/unit/chef/extensions/platform_spec.rb
203
+ - spec/unit/chef/extensions/ruby_spec.rb
204
+ - spec/unit/chef/extensions/shell_spec.rb
205
+ - spec/unit/chef/extensions/vagrant_spec.rb
206
+ - spec/unit/recipes/default_spec.rb
207
+ has_rdoc: