flombe 0.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -0
  4. data/Flombefile +9 -0
  5. data/Gemfile +10 -0
  6. data/Gemfile.lock +57 -0
  7. data/LICENSE +20 -0
  8. data/Rakefile +33 -0
  9. data/bin/flombe +17 -0
  10. data/config/rake.rb +38 -0
  11. data/cookbooks/homebrew/README.rdoc +8 -0
  12. data/cookbooks/homebrew/metadata.rb +8 -0
  13. data/cookbooks/homebrew/providers/homebrew.rb +39 -0
  14. data/cookbooks/homebrew/recipes/default.rb +42 -0
  15. data/cookbooks/homebrew/resources/homebrew.rb +14 -0
  16. data/cookbooks/mysql/README.rdoc +8 -0
  17. data/cookbooks/mysql/metadata.rb +6 -0
  18. data/cookbooks/mysql/recipes/default.rb +43 -0
  19. data/cookbooks/mysql/recipes/timezone.rb +10 -0
  20. data/cookbooks/redis/README.rdoc +8 -0
  21. data/cookbooks/redis/metadata.rb +6 -0
  22. data/cookbooks/redis/recipes/2.0.4.rb +24 -0
  23. data/cookbooks/redis/recipes/default.rb +7 -0
  24. data/cookbooks/rvm/CHANGELOG.md +19 -0
  25. data/cookbooks/rvm/README.md +564 -0
  26. data/cookbooks/rvm/Rakefile +35 -0
  27. data/cookbooks/rvm/attributes/default.rb +54 -0
  28. data/cookbooks/rvm/attributes/gem_package.rb +23 -0
  29. data/cookbooks/rvm/attributes/vagrant.rb +22 -0
  30. data/cookbooks/rvm/libraries/gem_package_monkeypatch.rb +34 -0
  31. data/cookbooks/rvm/libraries/helpers.rb +334 -0
  32. data/cookbooks/rvm/libraries/rvm_rubygems_package.rb +108 -0
  33. data/cookbooks/rvm/metadata.json +271 -0
  34. data/cookbooks/rvm/metadata.rb +95 -0
  35. data/cookbooks/rvm/providers/default_ruby.rb +46 -0
  36. data/cookbooks/rvm/providers/environment.rb +50 -0
  37. data/cookbooks/rvm/providers/gemset.rb +135 -0
  38. data/cookbooks/rvm/providers/global_gem.rb +99 -0
  39. data/cookbooks/rvm/providers/ruby.rb +100 -0
  40. data/cookbooks/rvm/providers/shell.rb +68 -0
  41. data/cookbooks/rvm/providers/wrapper.rb +58 -0
  42. data/cookbooks/rvm/recipes/default.rb +73 -0
  43. data/cookbooks/rvm/recipes/gem_package.rb +23 -0
  44. data/cookbooks/rvm/recipes/system.rb +69 -0
  45. data/cookbooks/rvm/recipes/user.rb +47 -0
  46. data/cookbooks/rvm/recipes/vagrant.rb +30 -0
  47. data/cookbooks/rvm/resources/default_ruby.rb +29 -0
  48. data/cookbooks/rvm/resources/environment.rb +29 -0
  49. data/cookbooks/rvm/resources/gem.rb +36 -0
  50. data/cookbooks/rvm/resources/gemset.rb +30 -0
  51. data/cookbooks/rvm/resources/global_gem.rb +33 -0
  52. data/cookbooks/rvm/resources/ruby.rb +29 -0
  53. data/cookbooks/rvm/resources/shell.rb +40 -0
  54. data/cookbooks/rvm/resources/wrapper.rb +32 -0
  55. data/cookbooks/rvm/templates/default/rvmrc.erb +14 -0
  56. data/cookbooks/rvm/templates/default/vagrant-chef-solo-wrapper.erb +23 -0
  57. data/cookbooks/utils/README.rdoc +8 -0
  58. data/cookbooks/utils/metadata.rb +6 -0
  59. data/cookbooks/utils/recipes/default.rb +10 -0
  60. data/cookbooks/utils/recipes/dotfiles.rb +21 -0
  61. data/cookbooks/utils/templates/default/dot.profile.erb +36 -0
  62. data/flombe.gemspec +28 -0
  63. data/lib/flombe/dsl.rb +66 -0
  64. data/lib/flombe.rb +107 -0
  65. data/spec/dsl_spec.rb +111 -0
  66. data/spec/flombe_spec.rb +30 -0
  67. data/spec/quality_spec.rb +11 -0
  68. data/spec/spec_helper.rb +21 -0
  69. data/spec/support/helpers.rb +18 -0
  70. data/spec/support/matchers.rb +9 -0
  71. data/spec/support/path.rb +21 -0
  72. data/templates/chef_solo.erb +11 -0
  73. metadata +154 -0
@@ -0,0 +1,30 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Resource:: gemset
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ actions :create, :delete, :empty, :update
23
+
24
+ attribute :gemset, :kind_of => String, :name_attribute => true
25
+ attribute :ruby_string, :kind_of => String, :regex => /^[^@]+$/
26
+
27
+ def initialize(*args)
28
+ super
29
+ @action = :create
30
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Resource:: global_gem
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ actions :install, :upgrade, :remove, :purge
23
+
24
+ attribute :package_name, :kind_of => String, :name_attribute => true
25
+ attribute :version, :kind_of => String
26
+ attribute :source, :kind_of => String
27
+ attribute :options, :kind_of => Hash
28
+ attribute :gem_binary, :kind_of => String
29
+
30
+ def initialize(*args)
31
+ super
32
+ @action = :install
33
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Resource:: ruby
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ actions :install, :uninstall, :remove
23
+
24
+ attribute :ruby_string, :kind_of => String, :name_attribute => true
25
+
26
+ def initialize(*args)
27
+ super
28
+ @action = :install
29
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Resource:: shell
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ actions :run
23
+
24
+ attribute :name, :kind_of => String, :name_attribute => true
25
+ attribute :ruby_string, :kind_of => String, :default => "default"
26
+ attribute :code, :kind_of => String
27
+ attribute :creates, :kind_of => String
28
+ attribute :cwd, :kind_of => String
29
+ attribute :environment, :kind_of => Hash
30
+ attribute :group, :kind_of => String
31
+ attribute :path, :kind_of => Array
32
+ attribute :returns, :kind_of => Array, :default => [ 0 ]
33
+ attribute :timeout, :kind_of => Integer
34
+ attribute :user, :kind_of => String
35
+ attribute :umask, :kind_of => String
36
+
37
+ def initialize(*args)
38
+ super
39
+ @action = :run
40
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Resource:: wrapper
4
+ #
5
+ # Author:: Fletcher Nichol <fnichol@nichol.ca>
6
+ #
7
+ # Copyright 2011, Fletcher Nichol
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ actions :create
23
+
24
+ attribute :prefix, :kind_of => String, :name_attribute => true
25
+ attribute :ruby_string, :kind_of => String
26
+ attribute :binary, :kind_of => String
27
+ attribute :binaries, :kind_of => Array
28
+
29
+ def initialize(*args)
30
+ super
31
+ @action = :create
32
+ end
@@ -0,0 +1,14 @@
1
+ # rvm configuration
2
+ #
3
+ # Generated by Chef for <%= node[:fqdn] %>
4
+ # Local modifications will be overwritten.
5
+ #
6
+ umask g+w
7
+ export rvm_path="<%= node['rvm']['root_path'] %>"
8
+
9
+ <% unless node['rvm']['rvm_gem_options'].empty? -%>
10
+ export rvm_gem_options="<%= node['rvm']['rvm_gem_options'] %>"
11
+ <% end -%>
12
+ <% node['rvm']['rvmrc'].each_pair do |k,v| -%>
13
+ export <%= k %>=<%= v %>
14
+ <% end -%>
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # RVM-aware chef-solo wrapper
4
+ #
5
+ # Generated by Chef for <%= node[:fqdn] %>
6
+ # Local modifications will be overridden
7
+
8
+ if [[ -d "<%= node['rvm']['root_path'] %>" ]] ; then
9
+ export PATH="/bin:<%= node['rvm']['root_path'] %>:$PATH"
10
+ rvm_path='<%= node['rvm']['root_path'] %>'
11
+ export rvm_path
12
+ unset RUBY_VERSION
13
+ unset GEM_HOME
14
+ unset GEM_PATH
15
+ unset MY_RUBY_HOME
16
+ unset IRBRC
17
+ rvm_ruby_string='system'
18
+ export rvm_ruby_string
19
+ unset rvm_gemset_name
20
+ unset MAGLEV_HOME
21
+ fi
22
+
23
+ exec <%= node['rvm']['vagrant']['system_chef_solo'] %> "$@"
@@ -0,0 +1,8 @@
1
+ = DESCRIPTION:
2
+
3
+ = REQUIREMENTS:
4
+
5
+ = ATTRIBUTES:
6
+
7
+ = USAGE:
8
+
@@ -0,0 +1,6 @@
1
+ maintainer ""
2
+ maintainer_email ""
3
+ license "All rights reserved"
4
+ description "Installs/Configures utils"
5
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
6
+ version "0.1"
@@ -0,0 +1,10 @@
1
+ #
2
+ # Cookbook Name:: utils
3
+ # Recipe:: default
4
+ #
5
+
6
+ require_recipe 'homebrew'
7
+
8
+ %w(tig ack coreutils gist wget).each do |pkg|
9
+ homebrew pkg
10
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Cookbook Name:: utils::profile
3
+ # Recipe:: default
4
+ #
5
+
6
+ template "#{ENV['HOME']}/.flombe.profile" do
7
+ mode 0700
8
+ owner ENV['USER']
9
+ group Etc.getgrgid(Process.gid).name
10
+ source "dot.profile.erb"
11
+ variables({ :home => ENV['HOME'] })
12
+ end
13
+
14
+ execute "setup flombe profile sourcing in ~/.bash_profile" do
15
+ command "echo 'source ~/.flombe.profile' >> ~/.bash_profile"
16
+ not_if "grep -q 'flombe.profile' ~/.bash_profile"
17
+ end
18
+
19
+ execute "sourcing flombe profile for immediate usage" do
20
+ command "source ~/.flombe.profile"
21
+ end
@@ -0,0 +1,36 @@
1
+ export CLICOLOR=1
2
+ export LSCOLORS=ExFxCxDxBxegedabagacad
3
+
4
+ source /usr/local/etc/bash_completion.d/git-completion.bash
5
+
6
+ function parse_git_branch {
7
+ git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1] /'
8
+ }
9
+
10
+ function proml {
11
+ local BLUE="\[\033[0;34m\]"
12
+ local RED="\[\033[0;31m\]"
13
+ local LIGHT_RED="\[\033[1;31m\]"
14
+ local GREEN="\[\033[0;32m\]"
15
+ local LIGHT_GREEN="\[\033[1;32m\]"
16
+ local WHITE="\[\033[1;37m\]"
17
+ local LIGHT_GRAY="\[\033[0;37m\]"
18
+ local CYAN="\[\033[0;36m\]"
19
+ local NO_COLOUR="\[\033[0m\]"
20
+ case $TERM in
21
+ xterm*)
22
+ TITLEBAR='\[\033]0;\u@\h:\w\007\]'
23
+ ;;
24
+ *)
25
+ TITLEBAR=""
26
+ ;;
27
+ esac
28
+
29
+ PS1="${TITLEBAR}\
30
+ $BLUE\$(parse_git_branch)\
31
+ $NO_COLOUR\h:$CYAN\w\
32
+ $NO_COLOUR\u\$ "
33
+ PS2='> '
34
+ PS4='+ '
35
+ }
36
+ proml
data/flombe.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'flombe'
5
+
6
+ Gem::Specification.new do | s |
7
+ s.name = "flombe"
8
+ s.version = Flombe::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.extra_rdoc_files = ["LICENSE"]
11
+ s.summary = "Mac OS X development configurator for multi project shops."
12
+ s.description = "A mix between the ease of use of Bundler and the super powers of Chef. Configuration management made easy on a per-project basis."
13
+ s.author = "Stephen Craton"
14
+ s.email = "stephen@babypips.com"
15
+ s.homepage = "http://github.com/devpips/flombe"
16
+
17
+ bundle = Bundler::Definition.build('Gemfile', 'Gemfile.lock', { })
18
+ bundle.dependencies.each do | dep |
19
+ next unless dep.groups.include?(:runtime)
20
+ s.add_dependency(dep.name)
21
+ end
22
+
23
+ s.bindir = "bin"
24
+ s.executables = %w( flombe )
25
+ s.require_path = 'lib'
26
+ s.files = `git ls-files`.split("\n") + Dir.glob("{cookbooks/rvm}/**/*")
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ end
data/lib/flombe/dsl.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'erubis'
2
+
3
+ module Flombe
4
+ class Dsl
5
+ CHEF_METHODS = %w(cookbook_path sandbox_path file_cache_path file_backup_path json_attribs log_level log_location verbose_logging node_name node_path solo ssl_verify_mode umask recipe_url cache_type cache_options)
6
+ BASE_COOKBOOKS = [File.expand_path('../../../cookbooks', __FILE__)]
7
+ FLOMBE_BASE = "#{ENV['HOME']}/.flombe"
8
+
9
+ def self.evaluate(flombefile)
10
+ builder = new
11
+ builder.instance_eval(File.open(flombefile, "rb") { |f| f.read }, flombefile.to_s, 1)
12
+ builder
13
+ end
14
+
15
+ def initialize
16
+ @config = {}
17
+ @recipes = {}
18
+ end
19
+
20
+ def config
21
+ cookbooks = @config.delete(:cookbook_path)
22
+ cookbooks = [cookbooks] if cookbooks.kind_of? String
23
+ {
24
+ :file_cache_path => "#{FLOMBE_BASE}/cache",
25
+ :file_backup_path => "#{FLOMBE_BASE}/backup",
26
+ :sandbox_path => "#{FLOMBE_BASE}/sandbox",
27
+ :log_level => :info,
28
+ :log_location => STDOUT,
29
+ :cookbook_path => BASE_COOKBOOKS + (cookbooks || []),
30
+ :cache_options => {:path => "#{FLOMBE_BASE}/cache/checksums", :skip_expires => true}
31
+ }.merge!(@config)
32
+ end
33
+
34
+ def to_dna
35
+ {
36
+ :recipes => @recipes.keys
37
+ }.merge!(@recipes).to_json
38
+ end
39
+
40
+ def to_solo_config
41
+ template = File.open(File.expand_path('../../../templates/chef_solo.erb', __FILE__), "r") { |f| f.read }
42
+ Erubis::Eruby.new(template).result(:config => config)
43
+ end
44
+
45
+ CHEF_METHODS.each do |method|
46
+ define_method method do |*args|
47
+ @config[method.to_sym] = args.pop
48
+ end
49
+ end
50
+
51
+ def recipe(name, *args)
52
+ options = Hash === args.last ? args.pop : {}
53
+ @recipes[name.to_sym] = options
54
+ end
55
+
56
+ def rubies(rubies, *args)
57
+ @recipes[:rvm] = {} unless @recipes.has_key?(:rvm)
58
+
59
+ rubies = [rubies] if rubies.is_a? String
60
+ @recipes[:rvm][:rubies] = rubies
61
+
62
+ options = Hash === args.last ? args.pop : {}
63
+ @recipes[:rvm][:default_ruby] = options[:default] unless options[:default].nil?
64
+ end
65
+ end
66
+ end
data/lib/flombe.rb ADDED
@@ -0,0 +1,107 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+
3
+ require "etc"
4
+ require "tmpdir"
5
+ require "json"
6
+
7
+ module Flombe
8
+ VERSION = "0.1.0.2"
9
+
10
+ autoload :Dsl, 'flombe/dsl'
11
+
12
+ class FlombeError < Exception ; end
13
+ class MissingXCodeError < FlombeError ; end
14
+ class BadMacOSXVersionError < FlombeError ; end
15
+ class NoFlombefileError < FlombeError ; end
16
+ class RunningAsRootError < FlombeError ; end
17
+
18
+ class Runner
19
+ RECOMMENDED_LLVM = 2206
20
+
21
+ def self.run
22
+ new.run
23
+ end
24
+
25
+ def self.warn(msg)
26
+ $stderr.puts "\033[0;31m\033[1m==> \033[0m\033[1m" + msg + "\033[0m"
27
+ end
28
+
29
+ def run
30
+ raise BadMacOSXVersionError, "You must have Snow Leopard for Flombe. Sorry bro." unless macosx?
31
+ raise MissingXCodeError, "You must have xcode installed to run Flombe." unless xcode?
32
+ raise NoFlombefileError, "There is no Flombefile here: #{Dir.pwd}" unless flombefile?
33
+ raise RunningAsRootError, "Please do not run this command as root." if root?
34
+
35
+ if `/usr/bin/xcode-select -print-path` + `/usr/bin/llvm-gcc-4.2 -v 2>&1` =~ /LLVM build (\d{4,})/
36
+ if $1.to_i < RECOMMENDED_LLVM
37
+ warn "You should really upgrade your xcode install for best performance."
38
+ end
39
+ end
40
+
41
+ run_chef
42
+ end
43
+
44
+ private
45
+
46
+ def xcode?
47
+ !`/usr/bin/xcode-select -print-path`.chomp.empty?
48
+ end
49
+
50
+ def macosx?
51
+ macosx_version >= 10.6
52
+ end
53
+
54
+ def flombefile?
55
+ File.exist?(flombefile)
56
+ end
57
+
58
+ def macosx_version
59
+ /(10\.\d+)(\.\d+)?/.match(`/usr/bin/sw_vers -productVersion`.chomp).captures.first.to_f
60
+ end
61
+
62
+ def root?
63
+ Etc.getpwuid.uid == 0
64
+ end
65
+
66
+ def run_chef
67
+ system("chef-solo -j #{dna} -c #{config}")
68
+ exit($?.to_i)
69
+ end
70
+
71
+ def sane_xcode_version?
72
+ xcode_path = `/usr/bin/xcode-select -print-path`.chomp
73
+ if xcode_path.empty?
74
+ false
75
+ elsif `#{xcode_path}/usr/bin/llvm-gcc-4.2 -v 2>&1` =~ /LLVM build (\d{4,})/
76
+ if $1.to_i < RECOMMENDED_LLVM
77
+ warn "You should really upgrade your xcode install"
78
+ end
79
+ true
80
+ end
81
+ end
82
+
83
+ def flombefile
84
+ @flombefile ||= File.expand_path(File.join(Dir.pwd, "Flombefile"))
85
+ end
86
+
87
+ def flombe_definition
88
+ @flombe ||= Flombe::Dsl.evaluate(flombefile)
89
+ end
90
+
91
+ def config
92
+ config_file = File.expand_path(File.join(Dir.tmpdir, "solo.rb"))
93
+ File.open(config_file, "w") do |fp|
94
+ fp.write( flombe_definition.to_solo_config )
95
+ end
96
+ config_file
97
+ end
98
+
99
+ def dna
100
+ dna_file = File.expand_path(File.join(Dir.tmpdir, "dna.json"))
101
+ File.open(dna_file, "w") do |fp|
102
+ fp.write( flombe_definition.to_dna )
103
+ end
104
+ dna_file
105
+ end
106
+ end
107
+ end
data/spec/dsl_spec.rb ADDED
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Flombe::Dsl do
4
+ let(:file) do
5
+ flombefile <<-G
6
+ recipe "homebrew"
7
+ G
8
+ end
9
+ let(:flombe) { Flombe::Dsl.evaluate(@file || file) }
10
+ let(:dna) { JSON.parse(flombe.to_dna) }
11
+ let(:config) { flombe.config }
12
+
13
+ describe "recipes" do
14
+ it "should add to the list of recipes" do
15
+ dna['recipes'].should == ['homebrew']
16
+ end
17
+ end
18
+
19
+ describe "solo.rb configuration" do
20
+ context "it should let me call chef-solo methods" do
21
+ Flombe::Dsl::CHEF_METHODS.each do |method|
22
+ it "can set #{method}" do
23
+ flombe.send(method, "test")
24
+ flombe.config[method.to_sym].should == "test"
25
+ end unless method == "cookbook_path" # we'll test cookbook_path specifically later on
26
+ end
27
+ end
28
+
29
+ it "should provide a set of defaults for the solo config" do
30
+ config[:file_cache_path].should be
31
+ config[:cookbook_path].should be
32
+ config[:log_level].should be
33
+ config[:log_location].should be
34
+ config[:cache_options].should be
35
+ end
36
+
37
+ it "should allow overriding of config defaults" do
38
+ @file = flombefile <<-G
39
+ log_level :info
40
+ G
41
+ config[:log_level].should == :info
42
+ end
43
+ end
44
+
45
+ describe "cookbook paths" do
46
+ let(:default_cookbook) { File.expand_path('../../cookbooks', __FILE__) }
47
+
48
+ it "should include the flombe cookbooks by default" do
49
+ config[:cookbook_path].should == [default_cookbook]
50
+ end
51
+
52
+ it "should include the flobme cookbooks even if custom ones are set" do
53
+ flombe.send(:cookbook_path, "~/my/cookbooks")
54
+ flombe.config[:cookbook_path].should == [default_cookbook, "~/my/cookbooks"]
55
+ end
56
+
57
+ it "should allow me to specify multiple cookbook paths" do
58
+ @file = flombefile <<-G
59
+ cookbook_path ["~/my/cookbooks", "./local/cookbooks"]
60
+ G
61
+ config[:cookbook_path].should == [default_cookbook, "~/my/cookbooks", "./local/cookbooks"]
62
+ end
63
+ end
64
+
65
+ describe "recipe config" do
66
+ it "should store extra params as config options" do
67
+ @file = flombefile <<-G
68
+ recipe "mysql", :root_password => 'qit13R', :tmp_path => '/tmp'
69
+ G
70
+ dna['mysql'].should == { "root_password" => "qit13R", "tmp_path" => "/tmp" }
71
+ end
72
+ end
73
+
74
+ describe "rvm rubies" do
75
+ let(:file) do
76
+ flombefile <<-G
77
+ rubies 'ruby-1.9.2-p180'
78
+ G
79
+ end
80
+
81
+ it "should add a ruby intepreter to a list" do
82
+ dna['rvm']['rubies'].should == ['ruby-1.9.2-p180']
83
+ end
84
+
85
+ it "should add the rvm recipe" do
86
+ dna['recipes'].should include('rvm')
87
+ end
88
+
89
+ it "should not add the RVM recipe twice" do
90
+ @file = flombefile <<-G
91
+ recipe "rvm"
92
+ rubies 'ruby-1.9.2-p180'
93
+ G
94
+ dna['recipes'].should == ['rvm']
95
+ end
96
+
97
+ it "should add multiple rubies to a list" do
98
+ @file = flombefile <<-G
99
+ rubies ['ruby-1.9.2-p180', 'ruby-1.8.7']
100
+ G
101
+ dna['rvm']['rubies'].should == ['ruby-1.9.2-p180', 'ruby-1.8.7']
102
+ end
103
+
104
+ it "should let me define a default ruby" do
105
+ @file = flombefile <<-G
106
+ rubies ['ruby-1.9.2-p180', 'ruby-1.8.7'], :default => 'ruby-1.9.2-p180'
107
+ G
108
+ dna['rvm']['default_ruby'].should == 'ruby-1.9.2-p180'
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Flombe do
4
+ let(:runner) { Flombe::Runner.new }
5
+
6
+ it "should detect if xcode is missing" do
7
+ runner.stub!(:xcode?).and_return(false)
8
+ lambda { runner.run }.should raise_error(Flombe::MissingXCodeError)
9
+ end
10
+
11
+ it "should detect Mac OS X verson" do
12
+ runner.stub!(:macosx_version).and_return(10.5)
13
+ lambda { runner.run }.should raise_error(Flombe::BadMacOSXVersionError)
14
+ end
15
+
16
+ it "should detect that a Flombefile does not exist" do
17
+ runner.stub!(:flombefile?).and_return(false)
18
+ lambda { runner.run }.should raise_error(Flombe::NoFlombefileError)
19
+ end
20
+
21
+ it "should detect if it's trying to be run as root" do
22
+ runner.stub!(:root?).and_return(true)
23
+ lambda { runner.run }.should raise_error(Flombe::RunningAsRootError)
24
+ end
25
+
26
+ it "should run chef-solo" do
27
+ runner.should_receive(:run_chef)
28
+ runner.run
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe "The Gem" do
4
+ it "can still be built" do
5
+ `gem build flombe.gemspec`
6
+ $?.should == 0
7
+
8
+ # clean up the .gem generated
9
+ system("rm -rf flombe-0.1.gem")
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'rspec'
8
+
9
+ require 'flombe'
10
+
11
+ Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
12
+ require file
13
+ end
14
+
15
+ # RSpec::Rubygems.setup
16
+
17
+ RSpec.configure do |config|
18
+ config.include RSpec::Matchers
19
+ config.include RSpec::Helpers
20
+ config.include RSpec::Paths
21
+ end