├── .fixtures.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── lib └── facter │ └── gemhome.rb ├── manifests ├── bundle.pp ├── config.pp ├── dev.pp ├── gemrc.pp ├── init.pp ├── params.pp └── rake.pp ├── metadata.json ├── spec ├── classes │ ├── config_spec.rb │ ├── dev_spec.rb │ ├── gemrc_spec.rb │ └── init_spec.rb ├── defines │ ├── bundle_spec.rb │ └── rake_spec.rb ├── spec.opts ├── spec_helper.rb └── spec_helper_system.rb ├── templates ├── gemrc.yaml.erb └── ruby.sh.erb └── tests ├── dev.pp ├── init.pp ├── params.pp ├── ruby1.8.pp ├── ruby1.9.pp ├── ruby1.9_switch.pp ├── ruby2.0.pp ├── ruby2.1.pp └── ruby2_switch.pp /.fixtures.yml: -------------------------------------------------------------------------------- 1 | fixtures: 2 | repositories: 3 | stdlib: 4 | repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' 5 | symlinks: 6 | ruby: "#{source_dir}" 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Default .gitignore for Ruby 2 | *.gem 3 | *.rbc 4 | .bundle 5 | .config 6 | coverage 7 | InstalledFiles 8 | lib/bundler/man 9 | pkg 10 | rdoc 11 | spec/reports 12 | test/tmp 13 | test/version_tmp 14 | tmp 15 | 16 | # YARD artifacts 17 | .yardoc 18 | _yardoc 19 | doc/ 20 | 21 | # Vim 22 | *.swp 23 | 24 | # Eclipse 25 | .project 26 | 27 | # OS X 28 | .DS_Store 29 | 30 | # Puppet 31 | coverage/ 32 | spec/fixtures/manifests/* 33 | spec/fixtures/modules/* 34 | Gemfile.lock 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: ruby 3 | 4 | rvm: 5 | - 2.4.1 6 | 7 | env: 8 | matrix: 9 | - PUPPET_GEM_VERSION="~> 4" 10 | 11 | sudo: false 12 | 13 | bundler_args: '--without development system_tests' 14 | 15 | before_install: 16 | - 'gem update --system' 17 | - 'gem update bundler' 18 | 19 | script: 'SPEC_OPTS="--format documentation" bundle exec rake validate lint spec' 20 | 21 | matrix: 22 | fast_finish: true 23 | exclude: 24 | - rvm: 2.0.0 25 | env: PUPPET_GEM_VERSION="~> 4" 26 | - rvm: 2.0.0 27 | env: PUPPET_GEM_VERSION="~> 4.9.0" 28 | - rvm: 2.4.1 29 | env: PUPPET_GEM_VERSION="~> 4.7.0" 30 | 31 | notifications: 32 | email: false 33 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Release v1.0.1 2 | ### Summary 3 | Stdlib dependency updated to < 7.0.0. 4 | 5 | ## Release 1.0.0 6 | ### Summary 7 | First major release. Brings it into the modern age with puppet 4, and into the future with archlinux. 8 | 9 | ### Changed 10 | - Dropped puppet 3 compatibility 11 | - Bumped stdlib lower bound to 4.13.1 12 | 13 | ### Added 14 | - archlinux support 15 | 16 | ## Release 0.6.0 17 | ### Summary 18 | This release includes support for Puppet 4 AIO, test fixes and cleanup. 19 | 20 | #### Features 21 | - Support Puppet v4 AIO 22 | 23 | #### Bugfixes 24 | - Fix bundler_package name for ubuntu 25 | - Fix testing 26 | - Update supported platforms 27 | - Remove unused metadata 28 | - Use community style 29 | 30 | ## Release 0.5.0 31 | ### Summary 32 | This release includes several new OS support features/bugfixes and multiple updates to Gemfile, Rakefile and metadata. 33 | 34 | #### Features 35 | - Bundle options: Allow . char in filepath args 36 | - Added FreeBSD 10 support 37 | - Gemfile updated 38 | - Rakefile updated to new syntax 39 | - Pinned rake to v10 when using Ruby 1.8.7 as v11 drops support for it 40 | 41 | #### Bugfixes 42 | - Updated metadata summary 43 | - Now requires ruby2.1-dev when installing on 2.1 Debian 44 | - General typo fixes 45 | - Readme updates and fixes 46 | - Fixed issue were multiple gem sources generated an invalid yaml file 47 | - Now uses ruby bundler on ubuntu < 14.04 48 | 49 | ##2014-11-18 - Release 0.4.0 50 | ###Summary 51 | This release includes the ability to specify the `rake_provider`, improved default parameters for OSes, and updates to tests and docs. 52 | 53 | ####Features 54 | - Add `rake_provider` parameter to `ruby::dev` 55 | - Updated RHEL and Ubuntu parameters 56 | - Test and documentation improvements 57 | 58 | ####Bugfixes 59 | - Clean up lint errors 60 | - Fix typo in README 61 | 62 | ##2014-09-16 - Release 0.3.0 63 | ###Summary 64 | This release includes many new features and improvements, including better 65 | handling for bundler and rake. 66 | 67 | Special thanks to Aaron Hicks for his hard work improving this module! 68 | 69 | ####Features 70 | - Added `$ruby_dev_gems` parameter to `ruby::dev` 71 | - Added the following params to `ruby` 72 | - `$suppress_warnings` 73 | - `$set_system_default` 74 | - `$system_default_bin` 75 | - `$system_default_gem` 76 | - `$gem_integration` 77 | - `$gem_integration_package` 78 | - Manage rake and bundler separately from core ruby packages with the addition 79 | of ruby::bundle and ruby::rake 80 | - Deprecated `$switch` in favor of `$set_system_default` 81 | - Improved testing and documentation 82 | 83 | ####Bugfixes 84 | - Fix package name to be 'bundler' instead of 'ruby-bundler' for Debian/Ubuntu 85 | - Fix package list defaults for RHEL5 and RHEL6 86 | - Fix package logic for trusty 87 | 88 | ##2014-07-15 - Release 0.2.1 89 | ###Summary 90 | This release merely updates metadata.json so the module can be uninstalled and 91 | upgraded via the puppet module command. 92 | 93 | ##2014-06-03 - Version 0.2.0 94 | ###Summary 95 | This work adds the ability to manage the gemrc globally, as well as adds in 96 | Ubuntu 14.04 support. There was a fair amount of under the hood changes to 97 | improve the module and it's testing. 98 | 99 | ####Features 100 | - `ruby::gemrc`: A class to allow you to configure the global gemrc file. 101 | - `ruby::dev`: A class for configurating ruby development specific things. 102 | - Rework the readme, tests, and rake tasks. 103 | - Remove augeas packages. 104 | - Add Ubuntu 14.04 support. 105 | 106 | ####Bugfixes 107 | - Fix for selecting the right package name when using versions. 108 | - Ruby-switch is gone from Ubuntu 14.04 onwards. 109 | - Fixes to ruby-switch in general. 110 | 111 | ##2013-10-09 - Version 0.1.1 112 | ###Summary 113 | Tiny fix to the metadata.json. 114 | 115 | ####Bugfixes 116 | - metadata.json. 117 | 118 | ##2013-10-08 - Version 0.1.0 119 | ###Summary 120 | Release an updated version of this. Highlights include OpenSUSE and general 121 | spring cleaning done by our wonderful community members! 122 | 123 | ####Features 124 | - OpenSUSE support 125 | - Allow `rubygems_package` override. 126 | - Add gemhome fact. 127 | - Add ri package. 128 | 129 | ####Bugfixes 130 | - Lint fixes. 131 | - Remove virtual irb package. 132 | - Update dev packages for Ubuntu/Debian 133 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source ENV['GEM_SOURCE'] || 'https://rubygems.org' 2 | 3 | if puppetversion = ENV['PUPPET_GEM_VERSION'] 4 | gem 'puppet', puppetversion, :require => false 5 | else 6 | gem 'puppet', :require => false 7 | end 8 | 9 | gem 'puppetlabs_spec_helper', '>= 1.2.0', :require => false 10 | gem 'facter', '>= 1.7.0', :require => false 11 | gem 'rspec-puppet', :require => false 12 | gem 'puppet-lint', '~> 2.0', :require => false 13 | gem 'puppet-lint-absolute_classname-check', :require => false 14 | gem 'puppet-lint-alias-check', :require => false 15 | gem 'puppet-lint-empty_string-check', :require => false 16 | gem 'puppet-lint-file_ensure-check', :require => false 17 | gem 'puppet-lint-file_source_rights-check', :require => false 18 | gem 'puppet-lint-leading_zero-check', :require => false 19 | gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false 20 | gem 'puppet-lint-trailing_comma-check', :require => false 21 | gem 'puppet-lint-undef_in_function-check', :require => false 22 | gem 'puppet-lint-unquoted_string-check', :require => false 23 | gem 'puppet-lint-variable_contains_upcase', :require => false 24 | 25 | gem 'rspec','~> 2.0', :require => false if RUBY_VERSION < '1.9' 26 | gem 'rake', '~> 10.0', :require => false if RUBY_VERSION < '1.9' 27 | gem 'json', '<= 1.8', :require => false if RUBY_VERSION < '2.0.0' 28 | gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0' 29 | gem 'json', :require => false if RUBY_VERSION >= '2.0.0' 30 | gem 'metadata-json-lint', '0.0.11', :require => false if RUBY_VERSION < '1.9' 31 | gem 'metadata-json-lint', :require => false if RUBY_VERSION >= '1.9' 32 | 33 | group :system_tests do 34 | if beaker_version = ENV['BEAKER_VERSION'] 35 | gem 'beaker', *location_for(beaker_version) 36 | end 37 | if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] 38 | gem 'beaker-rspec', *location_for(beaker_rspec_version) 39 | else 40 | gem 'beaker-rspec', :require => false 41 | end 42 | gem 'serverspec', :require => false 43 | gem 'beaker-puppet_install_helper', :require => false 44 | end 45 | 46 | # vim:ft=ruby 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012-2016 Puppet Labs Inc 2 | 3 | Puppet Labs can be contacted at: info@puppetlabs.com 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ruby Module 2 | 3 | This module manages Ruby and Rubygems. 4 | 5 | # Compatibility 6 | Puppet >= 4.7.0 with Ruby 2.1.9 and 2.4.1 on the following platforms. 7 | 8 | * Debian 6 9 | * Debian 7 10 | * EL 5 11 | * EL 6 12 | * EL 7 13 | * FreeBSD 10 14 | * SLES 11 SP1 15 | * Arch Linux 16 | 17 | 18 | # Dependencies 19 | 20 | * [PuppetLabs stdlib](https://forge.puppetlabs.com/puppetlabs/stdlib) 21 | 22 | ## Ruby Class 23 | 24 | Installs and manages the core Ruby packages. 25 | 26 | ### Parameters 27 | 28 | * *version*: (default installed) - 29 | Set the version of Ruby to install 30 | 31 | * *latest_release*: (default undefined) - 32 | Set this to true and the Ruby module will install new releases if they are updated in the repositories, or if a new repository is added with a newer release. Note: In Debian and Ubuntu where Ruby version is specified by package name, this parameter will effectively install the latest release of the Ruby version specified with the `version` parameter. 33 | 34 | * *gems_version*: (default installed) - 35 | Set the version of Rubygems to be installed 36 | 37 | * *rubygems_update*: (default true) - 38 | If set to true, the module will ensure that the rubygems package is installed but will use rubygems-update (same as gem update --system but versionable) to update Rubygems to the version defined in $gems_version. If set to false then the rubygems package resource will be versioned from $gems_version 39 | 40 | * *ruby_package*: (default ruby, modified for distribution and Ruby version) - 41 | Set the package name for Ruby 42 | 43 | * *rubygems_package*: (default rubygems) - 44 | Set the package name for rubygems 45 | 46 | * *ruby_dev_packages*: (default undefined) This sets the list of development packages passed to `ruby::dev`. 47 | 48 | * *suppress_warnings*: (default false) This suppresses warnings when a package is not expected to be available for a specific Ruby version for specific Ubuntu\Debian distributions and releases, but when a repository is provided that supplies the unnatural packages. 49 | 50 | * *set_system_default*: (default false) This sets the system default ruby and gem binaries to that specified by the `version` parameter. Only supported in Debian and Ubuntu. 51 | 52 | * *system_default_bin*: (default undefined) This sets a custom ruby binary used by the `set_system_default` parameter. To be used when a custom ruby package is supplied. 53 | 54 | * *system_default_gem*: (default undefined) This sets a custom gem binary used by the `set_system_default` parameter. To be used when a custom ruby or rubygems package is supplied. 55 | 56 | * *gem_integration*: (default false) Install the `rubygems_integration` package for Debian/Ubuntu that provides some integration between gems and distribution packages. Only supported in Debian and Ubuntu. 57 | 58 | * *gem_integration_package*: (default false) Specifies a custom `rubygems-integration` package. 59 | 60 | * *switch*: This parameter is depreciated, but continued for compatibility. Has the same function as `set_system_default`. 61 | 62 | ### Usage 63 | 64 | For a standard install using the latest Rubygems provided by rubygems-update on 65 | CentOS or Redhat use: 66 | ```puppet 67 | class { '::ruby': 68 | gems_version => 'latest', 69 | } 70 | ``` 71 | 72 | On Redhat this is equivilant to 73 | 74 | $ yum install ruby rubygems 75 | $ gem update --system 76 | 77 | #### Specify Version 78 | 79 | To install a specific version of ruby and rubygems but *not* use 80 | rubygems-update use: 81 | ```puppet 82 | class { '::ruby': 83 | version => '1.8.7', 84 | gems_version => '1.8.24', 85 | rubygems_update => false, 86 | } 87 | ``` 88 | 89 | On Redhat this is equivilant to 90 | 91 | $ yum install ruby-1.8.7 rubygems-1.8.24 92 | 93 | #### Alternative Ruby Packages 94 | 95 | If you need to use different packages for either ruby or rubygems you 96 | can. This could be for different versions or custom packages. For 97 | instance the following installs ruby 1.9 on Ubuntu 12.04. 98 | ```puppet 99 | class { '::ruby': 100 | ruby_package => 'ruby1.9.1-full', 101 | rubygems_package => 'rubygems1.9.1', 102 | gems_version => 'latest', 103 | } 104 | ``` 105 | This parameter will be particularly important if an alternative package repository is defined with [`yumrepo`](http://docs.puppetlabs.com/references/latest/type.html#yumrepo) or [`apt::source` or `apt::ppa`](https://forge.puppetlabs.com/puppetlabs/apt). 106 | 107 | ## Ruby Development Class 108 | 109 | The `ruby::dev` class requires the base `ruby` class. 110 | 111 | Installs and manages the installation of the Ruby development packages and tools, including [Rake](http://docs.seattlerb.org/rake/) and [Bundler](http://bundler.io/). Note that the `ruby::dev` class may not install all the dependencies required to install some gems. 112 | 113 | There is some selection logic in the `ruby::dev` class that attempts to install the correct development libraries and tools for the Ruby version installed by the base `ruby` class. Hence the `ruby::dev` class requires the `ruby` class. 114 | 115 | This class often installs a list of packages, so setting a package version is not available as this may behave unpredictably. 116 | 117 | ### Parameters 118 | 119 | * *ensure*: (default is 'installed') - 120 | This parameter sets the `ensure` parameter for all the Ruby development packages. 121 | * *ruby_dev_packages*: (default is depends on OS distribution) - 122 | This parameter replaces the list of default Ruby development packages. 123 | * *rake_ensure*: (default is 'installed') - 124 | This sets the `ensure` parameter of the rake package. 125 | * *rake_package*: (default depends on OS distribution) - 126 | This parameter replaces the default rake package. 127 | * *bundler_ensure*: (default is 'installed') - 128 | This sets the `ensure` parameter of the bundler package. 129 | * *bundler_package*: (default is dependent on OS distribution) - 130 | This parameter replaces the default bundler package. 131 | * *bundler_provider*: (default is dependent on OS distribution) - 132 | This parameter specifies what package provider should be used, only `gem` or `apt` are accepted. 133 | 134 | ## Rake Resource 135 | 136 | The `ruby::rake` resource requires the `ruby::dev` class. 137 | 138 | This resource runs [Rake](http://docs.seattlerb.org/rake/) tasks. This resource was created to be sure that Rake tasks would only be executed once their requirements were met by the `ruby::dev` class. 139 | 140 | As running rake under bundle is a common scenario, the `bundle` parameter will automatically wrap a rake task as a `bundle exec rake` command. This ensures that the rake command passes through the sanity checking in the `ruby::rake` resource, and meets the dependency requirements needed for both rake and bundler tasks. 141 | 142 | ### Parameters 143 | 144 | Most of the parameters for this resource are passed through to the underlying `exec` resource that runs the Rake task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available. 145 | 146 | * *task*: (this parameter is required) - 147 | This parameter is the Ruby task to be performed as a string with command line options. e.g. `db:setup`. 148 | * *rails_env*: (default is `production`) - 149 | This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task. 150 | * *bundle*: (default is false) - 151 | If set to true, the Rake task is automatically run under a `ruby::bundler` resource. 152 | * *creates*: (default is undefined) - 153 | Passed through to the underlying `exec` resource that runs the rake task. 154 | * *cwd*: (default is undefined) - 155 | Passed through to the underlying `exec` resource that runs the rake task. 156 | * *environment*: (default is undefined) - 157 | This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task. 158 | * *user*: (default is undefined) - 159 | Passed through to the underlying `exec` resource that runs the rake task. 160 | * *group*: (default is undefined) - 161 | Passed through to the underlying `exec` resource that runs the rake task. 162 | * *logoutput*: (default is undefined) - 163 | Passed through to the underlying `exec` resource that runs the rake task. 164 | * *onlyif*: (default is undefined) - 165 | Passed through to the underlying `exec` resource that runs the rake task. 166 | * *path*: (default is `['/usr/bin','/bin','/usr/sbin','/sbin']`) - 167 | The rake executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the rake executable. This is then passed to the underlying `exec` resource that runs the rake task. 168 | * *refresh*: (default is undefined) - 169 | Passed through to the underlying `exec` resource that runs the rake task. 170 | * *refreshonly*: (default is undefined) - 171 | Passed through to the underlying `exec` resource that runs the rake task. 172 | * *timeout*: (default is undefined) - 173 | Passed through to the underlying `exec` resource that runs the rake task. 174 | * *tries*: (default is undefined) - 175 | Passed through to the underlying `exec` resource that runs the rake task. 176 | * *try_sleep*: (default is undefined) - 177 | Passed through to the underlying `exec` resource that runs the rake task. 178 | * *unless*: (default is undefined) - 179 | Passed through to the underlying `exec` resource that runs the rake task. 180 | 181 | ## Bundler Resource 182 | 183 | The `ruby::bundle` resource requires the `ruby::dev` class. 184 | 185 | This resource runs [Bundler](http://bundler.io/) tasks. This resource was created to be sure that Bundler tasks would only be executed once their requirements were met by the `ruby::dev` class. 186 | 187 | ### Parameters 188 | 189 | Most of the parameters are passed through to the underlying `exec` resource that runs the bundler task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available. 190 | 191 | * *command*: (default is 'install') - 192 | This sets the command passed to the `bundler` executable. Not all bundler commands are currently supported. Only `exec`, `install` and `update` are currently supported. 193 | * *option*: (default is undefined) - 194 | This sets the options for the bundler command. Not all options are supported. 195 | * *rails_env*: (default is $ruby::params::rails_env) - 196 | This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task. 197 | * *creates*: (default is undefined) - 198 | Passed through to the underlying `exec` resource that runs the bundler task. 199 | * *cwd*: (default is undefined) - 200 | Passed through to the underlying `exec` resource that runs the bundler task. 201 | * *environment*: (default is undefined) - 202 | This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task. 203 | * *user*: (default is undefined) - 204 | Passed through to the underlying `exec` resource that runs the bundler task. 205 | * *group*: (default is undefined) - 206 | Passed through to the underlying `exec` resource that runs the bundler task. 207 | * *logoutput*: (default is undefined) - 208 | Passed through to the underlying `exec` resource that runs the bundler task. 209 | * *onlyif*: (default is undefined) - 210 | Passed through to the underlying `exec` resource that runs the bundler task. 211 | * *path*: (default is undefined) - 212 | The bundle executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the bundle executable. This is then passed to the underlying `exec` resource that runs the bundle task. 213 | * *refresh*: (default is undefined) - 214 | Passed through to the underlying `exec` resource that runs the bundler task. 215 | * *refreshonly*: (default is undefined) - 216 | Passed through to the underlying `exec` resource that runs the bundler task. 217 | * *timeout*: (default is undefined) - 218 | Passed through to the underlying `exec` resource that runs the bundler task. 219 | * *tries*: (default is undefined) - 220 | Passed through to the underlying `exec` resource that runs the bundler task. 221 | * *try_sleep*: (default is undefined) - 222 | Passed through to the underlying `exec` resource that runs the bundler task. 223 | * *unless*: (default is undefined) - 224 | The `unless` parameter is passed through to the underlying `exec` resource that runs the bundler task if the `ruby::bundler` resource `command` parameter is `exec`. For the `install` or `update` commands `unless` will be automatically set to, or overridden with, a command that makes the `ruby::bundle` resource idempotent. 225 | 226 | #### Supported Bundler Commands 227 | 228 | * **exec**: For the `exec` command to work, the command to be executed is passed as the option string. If the command is a rake task, it is recommended that the `ruby::rake` resource is used with the `bundle` parameter set to true. There are currently no constraints on the option string for the `exec` command. 229 | * **install**: The `install` command only currently supports the `--clean`,`--deployment`,`--gemfile`,`--path`, `--without`, and `--no-prune` options. 230 | * **update**: The `update` command only currently supports the `--local` and `--source` options. This command will try and update all the gems in a directory every time puppet runs. 231 | 232 | ## Ruby Configuration Class 233 | 234 | Ruby Enterprise Edition, Ruby versions [later than 1.9.3-preview1](http://www.rubyinside.com/ruby-1-9-3-preview-1-released-5229.html), and some patched Ruby distributions allow some tuning of the Ruby memory heap and garbage collection. These features will not work with the standard Ruby distributions prior to 1.9.3. 235 | 236 | The `ruby::config` class sets global environment variables that tune the Ruby memory heap and it's garbage collection as [per the Ruby Enterprise Edition documentation](http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning). This should allow the configuration of Ruby to better suit a deployed application and reduce the memory overhead of long-running Ruby processes (e.g. the [Puppet daemon](http://www.masterzen.fr/2010/01/28/puppet-memory-usage-not-a-fatality/)). The memory overhead issue can be further reduced by upgrading Ruby to a distribution using a [bitmap marked garbage collection](http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0) patch (e.g. as provided by [BrightBox](http://docs.brightbox.com/ruby/ubuntu/)) or to [Ruby 2.x](https://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/). 237 | 238 | ### More References 239 | 240 | * [Demystifying the Ruby GC](http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc) by Sam Saffron 241 | 242 | ### Parameters 243 | 244 | All the parameters are not set by default, which will revert to the default values for Ruby. 245 | 246 | * *gc_malloc_limit* : Sets `RUBY_GC_MALLOC_LIMIT`, which is the amount of memory that can be allocated without triggering garbage collection. The default is 8000000. 247 | * *heap_free_min* : Sets `RUBY_HEAP_FREE_MIN`, which is the number of heap slots that should be available after garbage collection is run. If fewer slots are available, new heap slots will be allocated. The default is 4096. 248 | * *heap_slots_growth_factor* : Sets `RUBY_HEAP_SLOTS_GROWTH_FACTOR`, which is the multiplier for how many new slots to be created if fewer slots than `RUBY_HEAP_FREE_MIN` remain after garbage collection. The default is 1.8. 249 | * *heap_min_slots* : This sets `RUBY_HEAP_MIN_SLOTS`, which is initial number of heap slots. The default is 10000. 250 | * *heap_slots_increment* : This sets `RUBY_HEAP_SLOTS_INCREMENT`, which is the number of additional slots allocated the first time additional slots are required. The default is 10000. 251 | 252 | ### Usage 253 | 254 | It should be possible to set any number of parameters, but setting no parameters is a special case that removes any modification to the Ruby environment settings. 255 | 256 | #### No Parameters 257 | 258 | If `ruby::config` is given with no parameters it removes the environment settings from the system, which restores the default Ruby settings. 259 | 260 | ```puppet 261 | include ::ruby::config 262 | ``` 263 | 264 | #### With Parameters 265 | 266 | ```puppet 267 | class { '::ruby::config': 268 | heap_min_slots => 500000, 269 | heap_slots_increment => 250000, 270 | heap_slots_growth_factor => 1, 271 | gc_malloc_limit => 50000000, 272 | } 273 | ``` 274 | 275 | Which should result with the following environment variables set: 276 | 277 | ``` 278 | RUBY_HEAP_MIN_SLOTS=500000 279 | RUBY_HEAP_SLOTS_INCREMENT=250000 280 | RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 281 | RUBY_GC_MALLOC_LIMIT=50000000 282 | ``` 283 | 284 | # Package sources 285 | 286 | If the required Ruby version is not available for the distribution being used check the following repositories: 287 | 288 | * For Ubuntu the [Brightbox Ruby PPA](http://www.ubuntuupdates.org/ppa/brightbox_ruby_ng_experimental) provides Ruby packages, use the following puppet code: 289 | 290 | ```puppet 291 | include ::apt 292 | 293 | ::apt::ppa { 'ppa:brightbox/ruby-ng-experimental': } 294 | 295 | class { '::ruby': 296 | version => '1.9.1', 297 | switch => true, 298 | latest_release => true, 299 | require => Apt::Ppa['ppa:brightbox/ruby-ng-experimental'], 300 | } 301 | ``` 302 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/rake_tasks' 2 | require 'puppet-lint/tasks/puppet-lint' 3 | PuppetLint.configuration.send('disable_80chars') 4 | PuppetLint.configuration.send('disable_140chars') 5 | PuppetLint.configuration.relative = true 6 | PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] 7 | 8 | desc 'Validate manifests, templates, and ruby files' 9 | task :validate do 10 | Dir['manifests/**/*.pp'].each do |manifest| 11 | sh "puppet parser validate --noop #{manifest}" 12 | end 13 | Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| 14 | sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ 15 | end 16 | Dir['templates/**/*.erb'].each do |template| 17 | sh "erb -P -x -T '-' #{template} | ruby -c" 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/facter/gemhome.rb: -------------------------------------------------------------------------------- 1 | # Fact: gemhome 2 | # 3 | # Purpose: Returns the gem home for rubygems 4 | # 5 | # Resolution: Returns GEM_HOME. 6 | # 7 | # Caveats: 8 | # 9 | begin 10 | require 'rubygems' 11 | 12 | Facter.add(:gemhome) do 13 | setcode { Gem::dir } 14 | end 15 | rescue LoadError 16 | end 17 | -------------------------------------------------------------------------------- /manifests/bundle.pp: -------------------------------------------------------------------------------- 1 | # == Define: ruby::bundle 2 | # 3 | # This resource runs [Bundler](http://bundler.io/) tasks. This resource was created to be sure that Bundler tasks would only be executed once their requirements were met by the `ruby::dev` class. 4 | # 5 | # === Parameters 6 | # 7 | # * *command*: (default is 'install') - 8 | # This sets the command passed to the `bundler` executable. Not all bundler commands are currently supported. Only `exec`, `install` and `update` are currently supported. 9 | # * *option*: (default is undefined) - 10 | # This sets the options for the bundler command. Not all options are supported. 11 | # * *rails_env*: (default is $ruby::params::rails_env) - 12 | # This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task. 13 | # [*creates*] 14 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 15 | # [*cwd*] 16 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 17 | # [*environment*] 18 | # (default is undefined) This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task. 19 | # [*user*] 20 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 21 | # [*group*] 22 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 23 | # [*logoutput*] 24 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 25 | # [*onlyif*] 26 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 27 | # [*path*] 28 | # (default is undefined) The bundle executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the bundle executable. This is then passed to the underlying `exec` resource that runs the bundle task. 29 | # [*refresh*] 30 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 31 | # [*refreshonly*] 32 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 33 | # [*timeout*] 34 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 35 | # [*tries*] 36 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 37 | # [*try_sleep*] 38 | # (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task. 39 | # [*unless*] 40 | # (default is undefined) The `unless` parameter is only passed through to the underlying `exec` resource that runs the bundler task if the `ruby::bundler` resource `command` parameter is `exec`. For the `install` or `update` commands `unless` will be automatically set to, or overridden with, a command that makes the `ruby::bundle` resource idempotent. 41 | # 42 | # === Examples 43 | # 44 | # Using ruby::bundle to install gems: 45 | # 46 | # ruby::bundle { 'install_app_gems': 47 | # option => '--deployment', 48 | # cwd => '/path/to/app', 49 | # } 50 | # 51 | define ruby::bundle 52 | ( 53 | $command = 'install', 54 | $option = undef, 55 | $rails_env = undef, 56 | $multicore = undef, 57 | $creates = undef, 58 | $cwd = undef, 59 | $environment = undef, 60 | $user = undef, 61 | $group = undef, 62 | $logoutput = undef, 63 | $onlyif = undef, 64 | $path = undef, 65 | $refresh = undef, 66 | $refreshonly = undef, 67 | $timeout = undef, 68 | $tries = undef, 69 | $try_sleep = undef, 70 | $unless = undef, 71 | ) { 72 | 73 | require ::ruby 74 | 75 | if $rails_env == undef { 76 | $rails_env_real = $ruby::params::rails_env 77 | } else { 78 | $rails_env_real = $rails_env 79 | } 80 | 81 | # ensure minimum path requirements for bundler 82 | if $path { 83 | $real_path = unique(flatten([$path, $ruby::params::minimum_path])) 84 | } else { 85 | $real_path = $ruby::params::minimum_path 86 | } 87 | 88 | # merge the environment and rails_env parameters 89 | if $environment { 90 | $real_environment = unique(flatten([$environment, ["RAILS_ENV=${rails_env_real}"]])) 91 | } else { 92 | $real_environment = "RAILS_ENV=${rails_env_real}" 93 | } 94 | 95 | if $multicore { 96 | if "${multicore}" == '0' or versioncmp($multicore,$::processorcount) >= 0 { #lint:ignore:only_variable_string 97 | $multicore_str = " --jobs ${::processorcount}" 98 | } else { 99 | $multicore_str = " --jobs ${multicore}" 100 | } 101 | } else { 102 | $multicore_str = undef 103 | } 104 | 105 | case $command { 106 | 'install': { 107 | if $option { 108 | validate_re( 109 | $option, 110 | [ 111 | '\s*--clean\s*', 112 | '\s*--deployment\s*', 113 | '\s*--gemfile=[a-zA-Z0-9\/\\:\.]+\s*', 114 | '\s*--path=[a-zA-Z0-9\/\\:\.]+\s*', 115 | '\s*--no-prune\s*', 116 | '\s*--without [[a-z0-9]+ ]+\s*', 117 | ], 118 | 'Only bundler options supported for the install command are: clean, deployment, gemfile, path, without, and no-prune' 119 | ) 120 | $real_command = "bundle ${command}${multicore_str} ${option}" 121 | } else { 122 | $real_command = "bundle ${command}${multicore_str}" 123 | } 124 | $real_unless = 'bundle check' 125 | } 126 | 'exec': { 127 | if $option { 128 | $real_command = "bundle ${command}${multicore_str} ${option}" 129 | $real_unless = $unless 130 | } else { 131 | fail ('When given the exec command the ruby::bundle resource requires the command to be executed to be passed to the option parameter') 132 | } 133 | } 134 | 'update':{ 135 | if $option { 136 | validate_re( 137 | $option, 138 | ['--local', '--source='], 139 | 'Only bundler options supported for the update command are: local and source' 140 | ) 141 | $real_command = "bundle ${command}${multicore_str} ${option}" 142 | $real_unless = "bundle outdated${multicore_str} ${option}" 143 | } else { 144 | $real_command = "bundle ${command}${multicore_str}" 145 | $real_unless = 'bundle outdated' 146 | } 147 | } 148 | default: { 149 | fail ('Only the bundler commands install, exec, and update are supported.') 150 | } 151 | } 152 | 153 | exec{"ruby_bundle_${name}": 154 | command => $real_command, 155 | creates => $creates, 156 | cwd => $cwd, 157 | environment => $real_environment, 158 | user => $user, 159 | group => $group, 160 | logoutput => $logoutput, 161 | onlyif => $onlyif, 162 | path => $real_path, 163 | refresh => $refresh, 164 | refreshonly => $refreshonly, 165 | timeout => $timeout, 166 | tries => $tries, 167 | try_sleep => $try_sleep, 168 | unless => $real_unless, 169 | require => Package['bundler'], 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /manifests/config.pp: -------------------------------------------------------------------------------- 1 | # Tunes the Ruby configuration 2 | # Ruby's garbage colleciton is notoriously inefficient and leads to 3 | # overallocation of memory to any long-running process that uses Ruby 4 | # e.g. puppet daemons 5 | # This class allows tuning of the Ruby environment variables 6 | class ruby::config ( 7 | $gc_malloc_limit = undef, 8 | $heap_free_min = undef, 9 | $heap_slots_growth_factor = undef, 10 | $heap_min_slots = undef, 11 | $heap_slots_increment = undef 12 | ) inherits ruby::params { 13 | 14 | if $gc_malloc_limit or 15 | $heap_free_min or 16 | $heap_slots_growth_factor or 17 | $heap_min_slots or 18 | $heap_slots_increment 19 | { 20 | $ensure = 'file' 21 | } else{ 22 | $ensure = 'absent' 23 | } 24 | 25 | file{'ruby_environment': 26 | ensure => $ensure, 27 | path => $ruby::params::ruby_environment_file, 28 | content => template('ruby/ruby.sh.erb'), 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /manifests/dev.pp: -------------------------------------------------------------------------------- 1 | # Class: ruby::dev 2 | # 3 | # This class installs Ruby development libraries. It's not right, and has no tests. 4 | # 5 | # Parameters: 6 | # 7 | # [*ensure*] 8 | # (default is 'installed') This parameter sets the `ensure` parameter for all the Ruby development packages. 9 | # [*ruby_dev_packages*] 10 | # (default is depends on OS distribution) This parameter replaces the list of default Ruby development packages. 11 | # [*rake_ensure*] 12 | # (default is 'installed') This sets the `ensure` parameter of the rake package. 13 | # [*rake_package*] 14 | # (default depends on OS distribution) This parameter replaces the default rake package. 15 | # [*rake_provider*] 16 | # (default depends on OS distribution) This parameter replaces the default rake provider. 17 | # [*bundler_ensure*] 18 | # (default is 'installed') This sets the `ensure` parameter of the bundler package. 19 | # [*bundler_package*] 20 | # (default is depends on OS distribution) This parameter replaces the default bundler package. 21 | # [*bundler_provider*] 22 | # (default depends on OS distribution) This parameter replaces the default bundler provider. 23 | # 24 | # Actions: 25 | # - Install RDoc, IRB, and development libraries 26 | # - Optionally install Rake and Bundler (installed by default) 27 | # 28 | # Requires: 29 | # 30 | # - Ruby 31 | # 32 | # Sample Usage: 33 | # 34 | # include ruby 35 | # include ruby::dev 36 | # 37 | class ruby::dev ( 38 | Enum['installed', 'present', 'absent', 'latest'] $ensure = 'installed', 39 | $ruby_dev_packages = undef, 40 | $rake_ensure = $ruby::params::rake_ensure, 41 | $rake_package = $ruby::params::rake_package, 42 | $rake_provider = $ruby::params::rake_provider, 43 | $bundler_ensure = $ruby::params::bundler_ensure, 44 | $bundler_package = $ruby::params::bundler_package, 45 | Enum['yum', 'gem', 'apt', 'pacman'] $bundler_provider = $ruby::params::bundler_provider, 46 | ) inherits ruby::params { 47 | require ::ruby 48 | 49 | case $::osfamily { 50 | default: { 51 | fail("Detected osfamily is <${::osfamily}> and supported values are 'Debian', 'RedHat', 'Archlinux' and 'Amazon'") 52 | } 53 | 'Debian': { 54 | if $ruby_dev_packages { 55 | $ruby_dev = $ruby_dev_packages 56 | } else { 57 | case $::ruby::version { 58 | /^1\.8.*$/:{ 59 | $ruby_dev = [ 60 | 'ruby1.8-dev', 61 | 'ri1.8', 62 | 'pkg-config', 63 | ] 64 | } 65 | /^1\.9.*$/:{ 66 | $ruby_dev = [ 67 | 'ruby1.9.1-dev', 68 | 'ri1.9.1', 69 | 'pkg-config', 70 | ] 71 | } 72 | /^2\.0.*$/:{ 73 | $ruby_dev = [ 74 | 'ruby2.0-dev', 75 | 'ri', 76 | 'pkg-config', 77 | ] 78 | } 79 | /^2\.1.*$/:{ 80 | $ruby_dev = [ 81 | 'ruby2.1-dev', 82 | 'ri', 83 | 'pkg-config', 84 | ] 85 | } 86 | default: { 87 | $ruby_dev = $::ruby::params::ruby_dev 88 | } 89 | } 90 | } 91 | } 92 | 'RedHat', 'Amazon': { 93 | # This specifically covers the case where there is no distro-provided 94 | # package for bundler. We install it using gem instead. Right now, this is 95 | # only set on RedHat and Amazon (see params.pp). 96 | $ruby_dev_gems = $::ruby::params::ruby_dev_gems 97 | 98 | if $ruby_dev_packages { 99 | $ruby_dev = $ruby_dev_packages 100 | } else { 101 | $ruby_dev = $::ruby::params::ruby_dev 102 | } 103 | } 104 | 'Archlinux': { 105 | $ruby_dev_gems = undef 106 | $ruby_dev = undef 107 | } 108 | } 109 | 110 | # The "version" switch seems to do nothing on a non-Debian distro. This is 111 | # probably the safest behavior for the moment, since RedHat doesn't change 112 | # the ruby package name the way Debian does when new versions become 113 | # available. It's a bit misleading for the user, though, since they can 114 | # specify a version and it will just silently continue installing the 115 | # default version. 116 | if $ruby_dev { 117 | package { $ruby_dev: 118 | ensure => $ensure, 119 | before => Package['rake', 'bundler'], 120 | require => Package['ruby'], 121 | } 122 | } 123 | 124 | if $rake_package { 125 | package { 'rake': 126 | ensure => $rake_ensure, 127 | name => $rake_package, 128 | provider => $rake_provider, 129 | require => Package['ruby'], 130 | } 131 | } 132 | 133 | if $bundler_package { 134 | package { 'bundler': 135 | ensure => $bundler_ensure, 136 | name => $bundler_package, 137 | provider => $bundler_provider, 138 | require => Package['ruby'], 139 | } 140 | } 141 | 142 | if $ruby_dev_gems { 143 | package { $ruby_dev_gems: 144 | ensure => $ensure, 145 | provider => gem, 146 | } 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /manifests/gemrc.pp: -------------------------------------------------------------------------------- 1 | # Manage global gemrc configuration 2 | # 3 | # This class allows the management of entries in /etc/gemrc 4 | # That can be useful when, e.g. configuring a rubygems proxy. 5 | 6 | # === Parameters 7 | # 8 | # [*sources*] 9 | # A YAML array of remote gem repositories to install gems from 10 | # 11 | # [*verbose*] 12 | # Verbosity of the gem command. false, true, and :really are the levels 13 | # 14 | # [*update_sources*] 15 | # Enable/disable automatic updating of repository metadata 16 | # 17 | # [*backtrace*] 18 | # Print backtrace when RubyGems encounters an error 19 | # 20 | # [*gempath*] 21 | # The paths in which to look for gems 22 | # 23 | # [*disable_default_gem_server*] 24 | # Force specification of gem server host on push 25 | # 26 | # [*gem_command*] 27 | # A string containing arguments for the specified gem command 28 | # This takes an array of Hashes, i.e.: 29 | # 30 | # gem_command => { 31 | # 'gem' => [ 'no-ri', 'http-proxy=http://waf-proxy' ], 32 | # 'push' => [ 'host=https://our.rubygems.host' ], 33 | # } 34 | 35 | class ruby::gemrc ( 36 | $sources = undef, 37 | Optional[Variant[Boolean, Enum[':really']]] $verbose = undef, 38 | Optional[Boolean] $update_sources = undef, 39 | Optional[Boolean] $backtrace = undef, 40 | Optional[Array[String]] $gempath = undef, 41 | Optional[Hash] $gem_command = undef, 42 | Stdlib::Absolutepath $gemrc = $::ruby::params::gemrc, 43 | String $owner = 'root', 44 | String $group = 'root', 45 | Pattern[/[0-7]{4}/] $mode = '0644', 46 | Optional[Boolean] $disable_default_gem_server = undef 47 | ) inherits ruby::params { 48 | 49 | $ensure = pick ($sources 50 | , $verbose 51 | , $update_sources 52 | , $backtrace 53 | , $gempath 54 | , $disable_default_gem_server 55 | , $gem_command 56 | , 'No need for gemrc.' 57 | ) ? { 58 | 'No need for gemrc.' => 'absent', 59 | default => 'file', 60 | } 61 | 62 | file { 'gemrc': 63 | ensure => $ensure, 64 | path => $::ruby::params::gemrc, 65 | mode => $mode, 66 | owner => $owner, 67 | group => $group, 68 | content => template('ruby/gemrc.yaml.erb'), 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # Class: ruby 2 | # 3 | # This class installs Ruby and manages rubygems 4 | # 5 | # Parameters: 6 | # 7 | # version: (default installed) 8 | # Set the version of Ruby to install 9 | # 10 | # gems_version: (default installed) 11 | # Set the version of Rubygems to be installed 12 | # 13 | # rubygems_update: (default false) 14 | # If set to true, the module will ensure that the rubygems package is 15 | # installed but will use rubygems-update (same as gem update --system 16 | # but versionable) to update Rubygems to the version defined in 17 | # $gems_version. If set to false then the rubygems package resource 18 | # will be versioned from $gems_version 19 | # 20 | # ruby_package: (default ruby) 21 | # Set the package name for ruby 22 | # 23 | # rubygems_package: (default rubygems) 24 | # Set the package name for rubygems 25 | # 26 | # Actions: 27 | # - Install Ruby 28 | # - Install Rubygems 29 | # - Optionally Update Rubygems 30 | # 31 | # Requires: 32 | # 33 | # Sample Usage: 34 | # 35 | # For a standard install using the latest Rubygems provided by 36 | # rubygems *without update* on Redhat use: 37 | # 38 | # class { 'ruby': 39 | # gems_version => 'latest', 40 | # } 41 | # 42 | # On Redhat this is equivalent to 43 | # $ yum install ruby rubygems 44 | # 45 | # To install a specific version of ruby and then call 46 | # gem update, use: 47 | # 48 | # class { 'ruby': 49 | # version => '1.8.7', 50 | # rubygems_update => true, 51 | # } 52 | # 53 | # On RedHat this is equivalent to 54 | # $ yum install ruby-1.8.7 rubygems 55 | # $ gem update --system 56 | # 57 | # To install a specific version of ruby and rubygems 58 | # use: 59 | # 60 | # class { 'ruby': 61 | # version => '1.8.7', 62 | # gems_version => '1.8.24', 63 | # rubygems_update => true, 64 | # } 65 | # 66 | # On Redhat this is equivalent to 67 | # $ yum install ruby-1.8.7 rubygems-1.8.24 68 | # $ gem update --system 69 | # 70 | # If you need to use different packages for either ruby or rubygems you 71 | # can. This could be for different versions or custom packages. For instance 72 | # the following installs ruby 1.9 on Ubuntu 12.04. 73 | # 74 | # class { 'ruby': 75 | # ruby_package => 'ruby1.9.1-full', 76 | # rubygems_package => 'rubygems1.9.1', 77 | # gems_version => 'latest', 78 | # } 79 | # 80 | # Ruby package names are not straightforward. Especially in Debian 81 | # osfamily Linux distributions 82 | # ruby is a virtual package that points to ruby1.8 83 | # ruby1.8 installs Ruby 1.8.7 (and earlier versions), requires a PPA for 14.04 or later 84 | # ruby1.9.1 installs Ruby 1.9.x 85 | # ruby1.9.1-full installs Ruby 1.9.x 86 | # ruby1.9.3 installs Ruby 1.9.x 87 | # Ruby 2.0.0 is availible from a PPA or Ubuntu 13.10 or later. 88 | # Ruby 2.1.0 is availible from a PPA. 89 | # ...and this should all be overridden if a package is specified 90 | # 91 | class ruby ( 92 | $version = $ruby::params::version, 93 | $latest_release = undef, 94 | $gems_version = $ruby::params::gems_version, 95 | $rubygems_update = $ruby::params::rubygems_update, 96 | $ruby_package = $ruby::params::ruby_package, 97 | $ruby_dev_packages = $ruby::params::ruby_dev, 98 | $rubygems_package = $ruby::params::rubygems_package, 99 | $suppress_warnings = false, 100 | $set_system_default = false, 101 | $system_default_bin = undef, 102 | $system_default_gem = undef, 103 | $gem_integration = false, 104 | $gem_integration_package = $ruby::params::gem_integration_package, 105 | $switch = undef 106 | ) inherits ruby::params { 107 | 108 | if $latest_release { 109 | $ruby_package_ensure = 'latest' 110 | } else { 111 | $ruby_package_ensure = 'installed' 112 | } 113 | 114 | case $::osfamily { 115 | 'Debian': { 116 | case $ruby_package { 117 | 'installed': { 118 | $real_ruby_package = $ruby_package 119 | } 120 | default:{ 121 | case $version { 122 | /^1\.8.*$/:{ 123 | $real_ruby_package = "${ruby::params::ruby_package}1.8" 124 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 { 125 | warning('Packages for Ruby 1.8 are not available from default repositories.') 126 | } 127 | } 128 | /^1\.9.*$/:{ 129 | $real_ruby_package = "${ruby::params::ruby_package}1.9.1" 130 | } 131 | /^2\.0.*$/:{ 132 | $real_ruby_package = "${ruby::params::ruby_package}2.0" 133 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 { 134 | warning('Packages for Ruby 2.0 are not available from default repositories.') 135 | } 136 | } 137 | /^2\.1.*$/:{ 138 | $real_ruby_package = "${ruby::params::ruby_package}2.1" 139 | if ! $suppress_warnings { 140 | warning('Packages for Ruby 2.1 are not available from default repositories.') 141 | } 142 | } 143 | default: { 144 | $real_ruby_package = $ruby_package 145 | } 146 | } 147 | } 148 | } 149 | } 150 | default: { 151 | $real_ruby_package = $ruby_package 152 | } 153 | } 154 | 155 | # The "version" switch seems to do nothing on a non-Debian distro. This is 156 | # probably the safest behavior for the moment, since RedHat doesn't change 157 | # the ruby package name the way Debian does when new versions become 158 | # available. It's a bit misleading for the user, though, since they can 159 | # specify a version and it will just silently continue installing the 160 | # default version. 161 | package { 'ruby': 162 | ensure => $ruby_package_ensure, 163 | name => $real_ruby_package, 164 | } 165 | 166 | # if rubygems_update is set to true then we only need to make the package 167 | # resource for rubygems ensure to installed, we'll let rubygems-update 168 | # take care of the versioning. 169 | 170 | if $rubygems_update == true { 171 | $rubygems_ensure = 'installed' 172 | } else { 173 | $rubygems_ensure = $gems_version 174 | } 175 | 176 | if $rubygems_package { 177 | package { 'rubygems': 178 | ensure => $rubygems_ensure, 179 | name => $rubygems_package, 180 | require => Package['ruby'], 181 | } 182 | } 183 | 184 | if $rubygems_update { 185 | package { 'rubygems-update': 186 | ensure => $gems_version, 187 | provider => 'gem', 188 | require => Package['rubygems'], 189 | notify => Exec['ruby::update_rubygems'], 190 | } 191 | 192 | exec { 'ruby::update_rubygems': 193 | path => '/usr/local/bin:/usr/bin:/bin', 194 | command => 'update_rubygems', 195 | refreshonly => true, 196 | } 197 | } 198 | 199 | if $set_system_default or $switch { 200 | case $::osfamily { 201 | 'Debian': { 202 | if $system_default_bin { 203 | $real_default_bin = $system_default_bin 204 | } else { 205 | case $version { 206 | /^1\.8.*$/:{ 207 | $real_default_bin = "${ruby::params::ruby_bin_base}1.8" 208 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 { 209 | warning('No binary for Ruby 1.8.x available from default repositories') 210 | } 211 | } 212 | /^1\.9.*$/:{ 213 | $real_default_bin = "${ruby::params::ruby_bin_base}1.9.1" 214 | } 215 | /^2\.0.*$/:{ 216 | $real_default_bin = "${ruby::params::ruby_bin_base}2.0" 217 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 { 218 | warning('No binary for Ruby 2.0.x available from default repositories') 219 | } 220 | } 221 | /^2\.1.*$/:{ 222 | $real_default_bin = "${ruby::params::ruby_bin_base}2.1" 223 | if ! $suppress_warnings { 224 | warning('No binary for Ruby 2.1.x available from default repositories') 225 | } 226 | } 227 | default: { 228 | fail('Unable to resolve default ruby binary') 229 | } 230 | } 231 | } 232 | if $system_default_gem { 233 | $real_default_gem = $system_default_gem 234 | } else { 235 | case $version { 236 | /^1\.8.*$/:{ 237 | $real_default_gem = "${ruby::params::ruby_gem_base}1.8" 238 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 { 239 | warning('No binary package for Ruby 1.8.x available from default repositories') 240 | } 241 | } 242 | /^1\.9.*$/:{ 243 | $real_default_gem = "${ruby::params::ruby_gem_base}1.9.1" 244 | } 245 | /^2\.0.*$/:{ 246 | $real_default_gem = "${ruby::params::ruby_gem_base}2.0" 247 | if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 { 248 | warning('No binary package for Ruby 2.0.x available from default repositories') 249 | } 250 | } 251 | /^2\.1.*$/:{ 252 | $real_default_gem = "${ruby::params::ruby_gem_base}2.1" 253 | if ! $suppress_warnings { 254 | warning('No binary package for Ruby 2.1.x available from default repositories') 255 | } 256 | } 257 | default: { 258 | fail('Unable to resolve default gem binary') 259 | } 260 | } 261 | } 262 | # update-alternatives does not support ruby in 14.04! 263 | file{'ruby_bin': 264 | ensure => link, 265 | path => $::ruby::params::ruby_bin_base, 266 | target => $real_default_bin, 267 | require => Package['ruby'], 268 | } 269 | # This should notify Exec['ruby::update_rubygems'] but if rubygems_update is false 270 | # it doesn't exist. 271 | file{'gem_bin': 272 | ensure => link, 273 | path => $::ruby::params::ruby_gem_base, 274 | target => $real_default_gem, 275 | require => Package['rubygems'], 276 | } 277 | } 278 | default: { 279 | if $switch { 280 | warning('The switch parameter is depreciated, use set_system_default') 281 | notice("The switch parameter for the ruby class does not work for ${::operatingsystem}, no action taken.") 282 | } 283 | if $set_system_default { 284 | notice("The set_system_default parameter for the ruby class does not work for ${::operatingsystem}, no action taken.") 285 | } 286 | } 287 | } 288 | } 289 | 290 | if $gem_integration { 291 | case $::osfamily { 292 | 'Debian': { 293 | if ! $suppress_warnings and $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '13.04') < 0 { 294 | warning('No package for rubygems_integration available from default repositories') 295 | } 296 | package{'rubygems_integration': 297 | ensure => $ruby_package_ensure, 298 | name => $gem_integration_package, 299 | require => Package['rubygems'], 300 | } 301 | } 302 | default: { 303 | notice("The gem_integration parameter for the ruby class does not work for ${::operatingsystem}, no action taken.") 304 | } 305 | } 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # Class: ruby::params 2 | # 3 | # This class handles the Ruby module parameters 4 | # 5 | class ruby::params { 6 | $version = 'installed' 7 | $gems_version = 'installed' 8 | $ruby_switch_package = 'ruby-switch' 9 | $rails_env = 'production' 10 | $minimum_path = ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'] 11 | $gem_integration_package = false 12 | $ruby_dev_gems = false 13 | 14 | case $::osfamily { 15 | 'redhat', 'amazon': { 16 | $ruby_package = 'ruby' 17 | $rubygems_package = 'rubygems' 18 | $ruby_dev = 'ruby-devel' 19 | $rubygems_update = false 20 | if $::operatingsystemmajrelease and versioncmp($::operatingsystemmajrelease, '5') == 0 { 21 | $rake_ensure = '10.3.2' 22 | $rake_package = 'rake' 23 | $rake_provider = 'gem' 24 | } else { 25 | $rake_ensure = 'installed' 26 | $rake_package = 'rubygem-rake' 27 | $rake_provider = 'yum' 28 | } 29 | $bundler_ensure = 'installed' 30 | $bundler_package = 'bundler' 31 | $bundler_provider = 'gem' 32 | } 33 | 'Archlinux': { 34 | $ruby_package = 'ruby' 35 | $rubygems_package = undef 36 | $ruby_dev = undef 37 | $rubygems_update = false 38 | $rake_ensure = 'installed' 39 | $rake_package = undef 40 | $rake_provider = 'pacman' 41 | $bundler_ensure = 'installed' 42 | $bundler_package = 'ruby-bundler' 43 | $bundler_provider = 'pacman' 44 | } 45 | 'debian': { 46 | $ruby_dev = [ 47 | 'ruby-dev', 48 | 'ri', 49 | 'pkg-config', 50 | ] 51 | $rake_ensure = 'installed' 52 | $rake_package = 'rake' 53 | $rake_provider = 'apt' 54 | $rubygems_update = false 55 | $ruby_gem_base = '/usr/bin/gem' 56 | $ruby_bin_base = '/usr/bin/ruby' 57 | $bundler_provider = 'gem' 58 | $bundler_package = 'bundler' 59 | case $::operatingsystemrelease { 60 | '10.04': { 61 | $bundler_ensure = '0.9.9' 62 | $ruby_package = 'ruby' 63 | $rubygems_package = 'rubygems' 64 | } 65 | '14.04': { 66 | #Ubuntu 14.04 changed ruby/rubygems to be all in one package. Specifying these as defaults will permit the module to behave as anticipated. 67 | $bundler_ensure = 'installed' 68 | $ruby_package = 'ruby' 69 | $rubygems_package = 'ruby1.9.1-full' 70 | } 71 | '18.04': { 72 | $bundler_ensure = 'installed' 73 | $ruby_package = 'ruby-full' 74 | $rubygems_package = 'rubygems' 75 | } 76 | default: { 77 | $bundler_ensure = 'installed' 78 | $ruby_package = 'ruby' 79 | $rubygems_package = 'rubygems' 80 | } 81 | } 82 | } 83 | 'FreeBSD': { 84 | $ruby_dev = [ 85 | 'ruby-build', 86 | ] 87 | $rake_ensure = 'installed' 88 | $rake_package = 'rake' 89 | $rake_provider = 'gem' 90 | $rubygems_update = false 91 | $ruby_gem_base = '/usr/local/bin/gem' 92 | $ruby_bin_base = '/usr/local/bin/ruby' 93 | $bundler_package = 'bundler' 94 | $bundler_provider = 'gem' 95 | $bundler_ensure = 'installed' 96 | $ruby_package = 'ruby' 97 | $rubygems_package = 'ruby20-gems' 98 | } 99 | default: { 100 | fail("Unsupported OS family: ${::osfamily}") 101 | } 102 | } 103 | 104 | $ruby_environment_file = '/etc/profile.d/ruby.sh' 105 | $gemrc = '/etc/gemrc' 106 | } 107 | -------------------------------------------------------------------------------- /manifests/rake.pp: -------------------------------------------------------------------------------- 1 | # == Define: ruby::rake 2 | # 3 | # This resource runs [Rake](http://docs.seattlerb.org/rake/) tasks. This resource was created to be sure that Rake tasks would only be executed once their requirements were met by the `ruby::dev` class. 4 | # 5 | # As running rake under bundle is a common scenario, the `bundle` parameter will automatically wrap a rake task as a `bundle exec rake` command. This ensures that the rake command passes through the sanity checking in the `ruby::rake` resource, and meets the dependency requirements needed for both rake and bundler tasks. 6 | # 7 | # === Parameters 8 | # 9 | # Most of the parameters for this resource are passed through to the underlying `exec` resource that runs the Rake task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available. 10 | # 11 | # [*task] 12 | # (this parameter is required) This parameter is the Ruby task to be performed as a string with command line options. e.g. `db:setup`. 13 | # [*rails_env] 14 | # (default is `production`) This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task. 15 | # [*bundle] 16 | # (default is false) If set to true, the Rake task is automatically run under a `ruby::bundler` resource. 17 | # [*creates] 18 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 19 | # [*cwd] 20 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 21 | # [*environment] 22 | # (default is undefined) This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task. 23 | # [*user] 24 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 25 | # [*group] 26 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 27 | # [*logoutput] 28 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 29 | # [*onlyif] 30 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 31 | # [*path] 32 | # (default is `['/usr/bin','/bin','/usr/sbin','/sbin']`) The rake executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the rake executable. This is then passed to the underlying `exec` resource that runs the rake task. 33 | # [*refresh] 34 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 35 | # [*refreshonly] 36 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 37 | # [*timeout] 38 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 39 | # [*tries] 40 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 41 | # [*try_sleep] 42 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 43 | # [*unless] 44 | # (default is undefined) Passed through to the underlying `exec` resource that runs the rake task. 45 | # 46 | # === Examples 47 | # 48 | # An example on setting up an application's database: 49 | # 50 | # ruby::rake { 'setup_app_db': 51 | # task => 'db:setup', 52 | # cwd => '/path/to/app', 53 | # } 54 | # 55 | # An example on setting up an application's database, with bundler: 56 | # 57 | # ruby::rake { 'setup_app_db': 58 | # task => 'db:setup', 59 | # bundle => true, 60 | # cwd => '/path/to/app', 61 | # } 62 | # 63 | define ruby::rake 64 | ( 65 | $task, 66 | $rails_env = undef, 67 | $bundle = false, 68 | $creates = undef, 69 | $cwd = undef, 70 | $environment = undef, 71 | $user = undef, 72 | $group = undef, 73 | $logoutput = undef, 74 | $onlyif = undef, 75 | $path = undef, 76 | $refresh = undef, 77 | $refreshonly = undef, 78 | $timeout = undef, 79 | $tries = undef, 80 | $try_sleep = undef, 81 | $unless = undef, 82 | ) { 83 | 84 | require ::ruby 85 | 86 | if $rails_env == undef { 87 | $rails_env_real = $ruby::params::rails_env 88 | } else { 89 | $rails_env_real = $rails_env 90 | } 91 | 92 | # Hmm this works on http://rubular.com/ 93 | # validate_re($task, '^[a-z][a-z0-9]*((:[a-z][a-z0-9]*)?)*$', "The rake task '${task}' does not conform to an expected format.") 94 | 95 | # ensure minimum path requirements for bundler 96 | if $path { 97 | $real_path = unique(flatten([$path, $ruby::params::minimum_path])) 98 | } else { 99 | $real_path = $ruby::params::minimum_path 100 | } 101 | 102 | # merge the environment and rails_env parameters 103 | if $environment { 104 | $real_environment = unique(flatten([$environment, ["RAILS_ENV=${rails_env_real}"]])) 105 | } else { 106 | $real_environment = "RAILS_ENV=${rails_env_real}" 107 | } 108 | 109 | $real_command = join(['rake', $task],' ') 110 | 111 | # wrapping rake tasks in bundler is a common practice, this makes sure 112 | # dependencies and requirements are met. 113 | if $bundle { 114 | ruby::bundle{"ruby_rake_${name}": 115 | command => 'exec', 116 | option => $real_command, 117 | rails_env => $rails_env_real, 118 | creates => $creates, 119 | cwd => $cwd, 120 | environment => $environment, 121 | user => $user, 122 | group => $group, 123 | logoutput => $logoutput, 124 | onlyif => $onlyif, 125 | path => $path, 126 | refresh => $refresh, 127 | refreshonly => $refreshonly, 128 | timeout => $timeout, 129 | tries => $tries, 130 | try_sleep => $try_sleep, 131 | unless => $unless, 132 | require => Package['rake'], 133 | } 134 | } else { 135 | exec{"ruby_rake_${name}": 136 | command => $real_command, 137 | creates => $creates, 138 | cwd => $cwd, 139 | environment => $real_environment, 140 | user => $user, 141 | group => $group, 142 | logoutput => $logoutput, 143 | onlyif => $onlyif, 144 | path => $real_path, 145 | refresh => $refresh, 146 | refreshonly => $refreshonly, 147 | timeout => $timeout, 148 | tries => $tries, 149 | try_sleep => $try_sleep, 150 | unless => $unless, 151 | require => Package['rake'], 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "puppetlabs-ruby", 3 | "version": "1.0.1", 4 | "author": "Puppet Labs", 5 | "summary": "Manages Ruby and Rubygems.", 6 | "license": "Apache-2.0", 7 | "source": "git@github.com:puppetlabs/puppetlabs-ruby.git", 8 | "project_page": "https://github.com/puppetlabs/puppetlabs-ruby", 9 | "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", 10 | "operatingsystem_support": [ 11 | { 12 | "operatingsystem": "RedHat", 13 | "operatingsystemrelease": [ 14 | "5", 15 | "6", 16 | "7" 17 | ] 18 | }, 19 | { 20 | "operatingsystem": "CentOS", 21 | "operatingsystemrelease": [ 22 | "5", 23 | "6", 24 | "7" 25 | ] 26 | }, 27 | { 28 | "operatingsystem": "OracleLinux", 29 | "operatingsystemrelease": [ 30 | "5", 31 | "6", 32 | "7" 33 | ] 34 | }, 35 | { 36 | "operatingsystem": "Scientific", 37 | "operatingsystemrelease": [ 38 | "5", 39 | "6", 40 | "7" 41 | ] 42 | }, 43 | { 44 | "operatingsystem": "FreeBSD", 45 | "operatingsystemrelease": [ 46 | "10" 47 | ] 48 | }, 49 | { 50 | "operatingsystem": "SLES", 51 | "operatingsystemrelease": [ 52 | "11 SP1" 53 | ] 54 | }, 55 | { 56 | "operatingsystem": "Debian", 57 | "operatingsystemrelease": [ 58 | "6", 59 | "7", 60 | "8" 61 | ] 62 | }, 63 | { 64 | "operatingsystem": "Ubuntu", 65 | "operatingsystemrelease": [ 66 | "10.04", 67 | "12.04", 68 | "14.04" 69 | ] 70 | } 71 | ], 72 | "requirements": [ 73 | {"name":"puppet", "version_requirement": ">= 4.7.0 < 6.0.0" } 74 | ], 75 | "dependencies": [ 76 | { 77 | "name":"puppetlabs/stdlib","version_requirement":">= 4.13.1 < 7.0.0" 78 | } 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /spec/classes/config_spec.rb: -------------------------------------------------------------------------------- 1 | # Only testing on RedHat because the outcome is the same on Debian. 2 | require 'spec_helper' 3 | describe 'ruby::config', :type => :class do 4 | describe 'when called with no parameters' do 5 | let (:facts) { { :osfamily => 'Redhat', 6 | :path => '/usr/local/bin:/usr/bin:/bin' } } 7 | it { 8 | should contain_file('ruby_environment').with({ 9 | 'ensure' => 'absent', 10 | }) 11 | } 12 | end 13 | 14 | describe 'when called setting gc_malloc_limit parameter' do 15 | let (:facts) { { :osfamily => 'Redhat', 16 | :path => '/usr/local/bin:/usr/bin:/bin' } } 17 | let (:params) { { :gc_malloc_limit => '10000' } } 18 | it { 19 | should contain_file('ruby_environment').with({ 20 | 'ensure' => 'file', 21 | 'path' => '/etc/profile.d/ruby.sh' 22 | }) 23 | } 24 | it { 25 | should contain_file('ruby_environment').with_content(/^export RUBY_GC_MALLOC_LIMIT=10000$/) 26 | } 27 | end 28 | 29 | describe 'when called setting heap_free_min parameter' do 30 | let (:facts) { { :osfamily => 'Redhat', 31 | :path => '/usr/local/bin:/usr/bin:/bin' } } 32 | let (:params) { { :heap_free_min => '10000' } } 33 | it { 34 | should contain_file('ruby_environment').with({ 35 | 'ensure' => 'file', 36 | 'path' => '/etc/profile.d/ruby.sh' 37 | }) 38 | } 39 | it { 40 | should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_FREE_MIN=10000$/) 41 | } 42 | end 43 | 44 | describe 'when called setting heap_slots_growth_factor parameter' do 45 | let (:facts) { { :osfamily => 'Redhat', 46 | :path => '/usr/local/bin:/usr/bin:/bin' } } 47 | let (:params) { { :heap_slots_growth_factor => '10000' } } 48 | it { 49 | should contain_file('ruby_environment').with({ 50 | 'ensure' => 'file', 51 | 'path' => '/etc/profile.d/ruby.sh' 52 | }) 53 | } 54 | it { 55 | should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_SLOTS_GROWTH_FACTOR=10000$/) 56 | } 57 | end 58 | 59 | describe 'when called setting heap_min_slots parameter' do 60 | let (:facts) { { :osfamily => 'Redhat', 61 | :path => '/usr/local/bin:/usr/bin:/bin' } } 62 | let (:params) { { :heap_min_slots => '10000' } } 63 | it { 64 | should contain_file('ruby_environment').with({ 65 | 'ensure' => 'file', 66 | 'path' => '/etc/profile.d/ruby.sh' 67 | }) 68 | } 69 | it { 70 | should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_MIN_SLOTS=10000$/) 71 | } 72 | end 73 | 74 | describe 'when called setting heap_slots_increment parameter' do 75 | let (:facts) { { :osfamily => 'Redhat', 76 | :path => '/usr/local/bin:/usr/bin:/bin' } } 77 | let (:params) { { :heap_slots_increment => '10000' } } 78 | it { 79 | should contain_file('ruby_environment').with({ 80 | 'ensure' => 'file', 81 | 'path' => '/etc/profile.d/ruby.sh' 82 | }) 83 | } 84 | it { 85 | should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_SLOTS_INCREMENT=10000$/) 86 | } 87 | end 88 | 89 | end -------------------------------------------------------------------------------- /spec/classes/dev_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'ruby::dev', :type => :class do 3 | describe 'with default ruby' do 4 | let :pre_condition do 5 | 'include ruby' 6 | end 7 | describe 'when called on an unsupported osfamily' do 8 | let (:facts) do 9 | { 10 | :osfamily => 'Unsupported', 11 | :path => '/usr/local/bin:/usr/bin:/bin' 12 | } 13 | end 14 | 15 | it 'should fail' do 16 | expect { 17 | should contain_class('ruby::dev') 18 | }.to raise_error(Puppet::Error, /Unsupported/) 19 | end 20 | end 21 | describe 'when called on Redhat' do 22 | let (:facts) do 23 | { 24 | :osfamily => 'RedHat', 25 | :path => '/usr/local/bin:/usr/bin:/bin' 26 | } 27 | end 28 | context 'with no parameters' do 29 | it { 30 | should contain_package('ruby-devel').with({ 31 | 'ensure' => 'installed', 32 | }) 33 | } 34 | context 'if on el 5 release' do 35 | let(:facts) do 36 | { 37 | :osfamily => 'RedHat', 38 | :operatingsystemmajrelease => '5', 39 | :path => '/usr/local/bin:/usr/bin:/bin' 40 | } 41 | end 42 | it { 43 | should contain_package('rake').with({ 44 | 'ensure' => '10.3.2', 45 | 'name' => 'rake', 46 | 'provider' => 'gem', 47 | }) 48 | } 49 | end 50 | context 'if on non-el5 release' do 51 | let (:facts) do 52 | { 53 | :osfamily => 'Redhat', 54 | :path => '/usr/local/bin:/usr/bin:/bin' 55 | } 56 | end 57 | it { 58 | should contain_package('rake').with({ 59 | 'ensure' => 'installed', 60 | 'name' => 'rubygem-rake', 61 | 'require' => 'Package[ruby]', 62 | }) 63 | } 64 | it { 65 | should contain_package('bundler').with({ 66 | 'ensure' => 'installed', 67 | 'name' => 'bundler', 68 | 'provider' => 'gem', 69 | 'require' => 'Package[ruby]', 70 | }) 71 | } 72 | end 73 | end 74 | context 'when using latest version' do 75 | let :params do 76 | { 77 | :ensure => 'latest', 78 | :rake_ensure => 'latest', 79 | :bundler_ensure => 'latest' 80 | } 81 | end 82 | it { 83 | should contain_package('ruby-devel').with_ensure('latest') 84 | } 85 | it { 86 | should contain_package('rake').with_ensure('latest') 87 | } 88 | it { 89 | should contain_package('bundler').with_ensure('latest') 90 | } 91 | end 92 | context 'when using custom packages' do 93 | let :params do 94 | { 95 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 96 | :rake_package => 'magic-rake', 97 | :bundler_package => 'sparkly-bundler' 98 | } 99 | end 100 | it { 101 | should contain_package('magic-ruby-dev') 102 | } 103 | it { 104 | should contain_package('sparkly-ruby-dev') 105 | } 106 | it { 107 | should contain_package('rake').with_name('magic-rake') 108 | } 109 | it { 110 | should contain_package('bundler').with_name('sparkly-bundler') 111 | } 112 | it { 113 | should_not contain_package('ruby-devel') 114 | } 115 | end 116 | end 117 | 118 | describe 'when called on Amazon' do 119 | let (:facts) do 120 | { 121 | :osfamily => 'Amazon', 122 | :path => '/usr/local/bin:/usr/bin:/bin' 123 | } 124 | end 125 | context 'with no parameters' do 126 | it { 127 | should contain_package('ruby-devel').with({ 128 | 'ensure' => 'installed', 129 | }) 130 | } 131 | it { 132 | should contain_package('rake').with({ 133 | 'ensure' => 'installed', 134 | 'name' => 'rubygem-rake', 135 | 'require' => 'Package[ruby]', 136 | }) 137 | } 138 | it { 139 | should contain_package('bundler').with({ 140 | 'ensure' => 'installed', 141 | 'name' => 'bundler', 142 | 'provider' => 'gem', 143 | 'require' => 'Package[ruby]', 144 | }) 145 | } 146 | end 147 | context 'when using latest version' do 148 | let :params do 149 | { 150 | :ensure => 'latest', 151 | :rake_ensure => 'latest', 152 | :bundler_ensure => 'latest' 153 | } 154 | end 155 | it { 156 | should contain_package('ruby-devel').with_ensure('latest') 157 | } 158 | it { 159 | should contain_package('rake').with_ensure('latest') 160 | } 161 | it { 162 | should contain_package('bundler').with_ensure('latest') 163 | } 164 | end 165 | context 'when using custom packages' do 166 | let :params do 167 | { 168 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 169 | :rake_package => 'magic-rake', 170 | :bundler_package => 'sparkly-bundler' 171 | } 172 | end 173 | it { 174 | should contain_package('magic-ruby-dev') 175 | } 176 | it { 177 | should contain_package('sparkly-ruby-dev') 178 | } 179 | it { 180 | should contain_package('rake').with_name('magic-rake') 181 | } 182 | it { 183 | should contain_package('bundler').with_name('sparkly-bundler') 184 | } 185 | it { 186 | should_not contain_package('ruby-devel') 187 | } 188 | end 189 | end 190 | 191 | describe 'when called on Debian' do 192 | let (:facts) do 193 | { 194 | :osfamily => 'Debian', 195 | :operatingsystem => 'Debian', 196 | :path => '/usr/local/bin:/usr/bin:/bin' 197 | } 198 | end 199 | context 'with no parameters' do 200 | it { 201 | should contain_package('ruby-dev').with({ 202 | 'ensure' => 'installed', 203 | }) 204 | } 205 | it { 206 | should contain_package('ri').with({ 207 | 'ensure' => 'installed', 208 | }) 209 | } 210 | it { 211 | should contain_package('pkg-config').with({ 212 | 'ensure' => 'installed', 213 | }) 214 | } 215 | it { 216 | should contain_package('rake').with({ 217 | 'ensure' => 'installed', 218 | 'name' => 'rake', 219 | 'require' => 'Package[ruby]', 220 | }) 221 | } 222 | context 'when on Ubuntu 10.04' do 223 | let (:facts) do 224 | { 225 | :osfamily => 'Debian', 226 | :operatingsystem => 'Ubuntu', 227 | :operatingsystemrelease => '10.04', 228 | :path => '/usr/local/bin:/usr/bin:/bin' 229 | } 230 | end 231 | it { 232 | should contain_package('bundler').with({ 233 | 'ensure' => '0.9.9', 234 | 'name' => 'bundler', 235 | 'provider' => 'gem', 236 | 'require' => 'Package[ruby]' 237 | }) 238 | } 239 | end 240 | context 'when on Ubuntu 12.04' do 241 | let (:facts) do 242 | { 243 | :osfamily => 'Debian', 244 | :operatingsystem => 'Ubuntu', 245 | :operatingsystemrelease => '12.04', 246 | :path => '/usr/local/bin:/usr/bin:/bin' 247 | } 248 | end 249 | it { 250 | should contain_package('bundler').with({ 251 | 'ensure' => 'installed', 252 | 'name' => 'bundler', 253 | 'provider' => 'gem', 254 | 'require' => 'Package[ruby]' 255 | }) 256 | } 257 | end 258 | context 'when on Ubuntu 14.04' do 259 | let (:facts) do 260 | { 261 | :osfamily => 'Debian', 262 | :operatingsystemrelease => '14.04', 263 | :path => '/usr/local/bin:/usr/bin:/bin' 264 | } 265 | end 266 | it { 267 | should contain_package('bundler').with({ 268 | 'ensure' => 'installed', 269 | 'name' => 'bundler', 270 | 'provider' => 'gem', 271 | 'require' => 'Package[ruby]' 272 | }) 273 | } 274 | end 275 | context 'when on other Debian or Ubuntu' do 276 | let (:facts) do 277 | { 278 | :osfamily => 'Debian', 279 | :operatingsystem => 'Ubuntu', 280 | :operatingsystemrelease => '14.04', 281 | :path => '/usr/local/bin:/usr/bin:/bin' 282 | } 283 | end 284 | it { 285 | should contain_package('bundler').with({ 286 | 'ensure' => 'installed', 287 | 'name' => 'bundler', 288 | 'provider' => 'gem', 289 | 'require' => 'Package[ruby]', 290 | }) 291 | } 292 | end 293 | end 294 | context 'when using latest version' do 295 | let :params do 296 | { 297 | :ensure => 'latest', 298 | :rake_ensure => 'latest', 299 | :bundler_ensure => 'latest' 300 | } 301 | end 302 | it { 303 | should contain_package('ruby-dev').with_ensure('latest') 304 | } 305 | it { 306 | should contain_package('ri').with_ensure('latest') 307 | } 308 | it { 309 | should contain_package('pkg-config').with_ensure('latest') 310 | } 311 | it { 312 | should contain_package('rake').with_ensure('latest') 313 | } 314 | it { 315 | should contain_package('bundler').with_ensure('latest') 316 | } 317 | end 318 | context 'when using custom packages' do 319 | let :params do 320 | { 321 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 322 | :rake_package => 'magic-rake', 323 | :bundler_package => 'sparkly-bundler' 324 | } 325 | end 326 | it { 327 | should contain_package('magic-ruby-dev') 328 | } 329 | it { 330 | should contain_package('sparkly-ruby-dev') 331 | } 332 | it { 333 | should contain_package('rake').with_name('magic-rake') 334 | } 335 | it { 336 | should contain_package('bundler').with_name('sparkly-bundler') 337 | } 338 | it { 339 | should_not contain_package('ruby-dev') 340 | } 341 | it { 342 | should_not contain_package('ri') 343 | } 344 | it { 345 | should_not contain_package('pkg-config') 346 | } 347 | end 348 | end 349 | describe 'when called on Arch Linux' do 350 | let (:facts) do 351 | { 352 | :osfamily => 'Archlinux', 353 | :path => '/usr/bin' 354 | } 355 | end 356 | context 'with no parameters' do 357 | it { should_not contain_package('ruby-dev') } 358 | it { should_not contain_package('rake') } 359 | it do 360 | should contain_package('bundler').with( 361 | { 362 | 'ensure' => 'installed', 363 | 'name' => 'ruby-bundler', 364 | 'provider' => 'pacman', 365 | 'require' => 'Package[ruby]', 366 | } 367 | ) 368 | end 369 | end 370 | end 371 | end 372 | 373 | describe 'with ruby 1.9.1' do 374 | let :pre_condition do 375 | 'class { \'ruby\': version => \'1.9.1\' }' 376 | end 377 | describe 'when called on Redhat' do 378 | let (:facts) do 379 | { 380 | :osfamily => 'RedHat', 381 | :path => '/usr/local/bin:/usr/bin:/bin' 382 | } 383 | end 384 | context 'with no parameters' do 385 | it { 386 | should contain_package('ruby-devel').with({ 387 | 'ensure' => 'installed', 388 | }) 389 | } 390 | it { 391 | should contain_package('rake').with({ 392 | 'ensure' => 'installed', 393 | 'name' => 'rubygem-rake', 394 | 'require' => 'Package[ruby]', 395 | }) 396 | } 397 | it { 398 | should contain_package('bundler').with({ 399 | 'ensure' => 'installed', 400 | 'name' => 'bundler', 401 | 'provider' => 'gem', 402 | 'require' => 'Package[ruby]', 403 | }) 404 | } 405 | end 406 | end 407 | 408 | describe 'when called on Amazon' do 409 | let (:facts) do 410 | { 411 | :osfamily => 'Amazon', 412 | :path => '/usr/local/bin:/usr/bin:/bin' 413 | } 414 | end 415 | context 'with no parameters' do 416 | it { 417 | should contain_package('ruby-devel').with({ 418 | 'ensure' => 'installed', 419 | }) 420 | } 421 | it { 422 | should contain_package('rake').with({ 423 | 'ensure' => 'installed', 424 | 'name' => 'rubygem-rake', 425 | 'require' => 'Package[ruby]', 426 | }) 427 | } 428 | it { 429 | should contain_package('bundler').with({ 430 | 'ensure' => 'installed', 431 | 'name' => 'bundler', 432 | 'provider' => 'gem', 433 | 'require' => 'Package[ruby]', 434 | }) 435 | } 436 | end 437 | end 438 | describe 'when called on Debian' do 439 | let (:facts) do 440 | { 441 | :osfamily => 'Debian', 442 | :path => '/usr/local/bin:/usr/bin:/bin' 443 | } 444 | end 445 | context 'with no parameters' do 446 | it { 447 | should contain_package('ruby1.9.1-dev').with({ 448 | 'ensure' => 'installed', 449 | }) 450 | } 451 | it { 452 | should contain_package('ri1.9.1').with({ 453 | 'ensure' => 'installed', 454 | }) 455 | } 456 | it { 457 | should contain_package('pkg-config').with({ 458 | 'ensure' => 'installed', 459 | }) 460 | } 461 | it { 462 | should contain_package('rake').with({ 463 | 'ensure' => 'installed', 464 | 'name' => 'rake', 465 | 'require' => 'Package[ruby]', 466 | }) 467 | } 468 | it { 469 | should contain_package('bundler').with({ 470 | 'ensure' => 'installed', 471 | 'name' => 'bundler', 472 | 'provider' => 'gem', 473 | 'require' => 'Package[ruby]', 474 | }) 475 | } 476 | end 477 | context 'when using latest version' do 478 | let :params do 479 | { 480 | :ensure => 'latest', 481 | :rake_ensure => 'latest', 482 | :bundler_ensure => 'latest' 483 | } 484 | end 485 | it { 486 | should contain_package('ruby1.9.1-dev').with_ensure('latest') 487 | } 488 | it { 489 | should contain_package('ri1.9.1').with_ensure('latest') 490 | } 491 | it { 492 | should contain_package('pkg-config').with_ensure('latest') 493 | } 494 | it { 495 | should contain_package('rake').with_ensure('latest') 496 | } 497 | it { 498 | should contain_package('bundler').with_ensure('latest') 499 | } 500 | end 501 | context 'when using custom packages' do 502 | let :params do 503 | { 504 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 505 | :rake_package => 'magic-rake', 506 | :bundler_package => 'sparkly-bundler' 507 | } 508 | end 509 | it { 510 | should contain_package('magic-ruby-dev') 511 | } 512 | it { 513 | should contain_package('sparkly-ruby-dev') 514 | } 515 | it { 516 | should contain_package('rake').with_name('magic-rake') 517 | } 518 | it { 519 | should contain_package('bundler').with_name('sparkly-bundler') 520 | } 521 | it { 522 | should_not contain_package('ruby1.9.1-dev') 523 | } 524 | it { 525 | should_not contain_package('ri1.9.1') 526 | } 527 | it { 528 | should_not contain_package('pkg-config') 529 | } 530 | end 531 | end 532 | end 533 | 534 | describe 'with ruby 2.0.0' do 535 | let :pre_condition do 536 | 'class { \'ruby\': version => \'2.0.0\' }' 537 | end 538 | describe 'when called on Redhat' do 539 | let (:facts) do 540 | { 541 | :osfamily => 'RedHat', 542 | :path => '/usr/local/bin:/usr/bin:/bin' 543 | } 544 | end 545 | context 'with no parameters' do 546 | it { 547 | should contain_package('ruby-devel').with({ 548 | 'ensure' => 'installed', 549 | }) 550 | } 551 | it { 552 | should contain_package('rake').with({ 553 | 'ensure' => 'installed', 554 | 'name' => 'rubygem-rake', 555 | 'require' => 'Package[ruby]', 556 | }) 557 | } 558 | it { 559 | should contain_package('bundler').with({ 560 | 'ensure' => 'installed', 561 | 'name' => 'bundler', 562 | 'provider' => 'gem', 563 | 'require' => 'Package[ruby]', 564 | }) 565 | } 566 | end 567 | end 568 | 569 | describe 'when called on Amazon' do 570 | let (:facts) do 571 | { 572 | :osfamily => 'Amazon', 573 | :path => '/usr/local/bin:/usr/bin:/bin' 574 | } 575 | end 576 | context 'with no parameters' do 577 | it { 578 | should contain_package('ruby-devel').with({ 579 | 'ensure' => 'installed', 580 | }) 581 | } 582 | it { 583 | should contain_package('rake').with({ 584 | 'ensure' => 'installed', 585 | 'name' => 'rubygem-rake', 586 | 'require' => 'Package[ruby]', 587 | }) 588 | } 589 | it { 590 | should contain_package('bundler').with({ 591 | 'ensure' => 'installed', 592 | 'name' => 'bundler', 593 | 'provider' => 'gem', 594 | 'require' => 'Package[ruby]', 595 | }) 596 | } 597 | end 598 | end 599 | 600 | describe 'when called on Debian' do 601 | let (:facts) do 602 | { 603 | :osfamily => 'Debian', 604 | :operatingsystem => 'Debian', 605 | :operatingsystemrelease => '6', 606 | :path => '/usr/local/bin:/usr/bin:/bin' 607 | } 608 | end 609 | context 'with no parameters' do 610 | it { 611 | should contain_package('ruby2.0-dev').with({ 612 | 'ensure' => 'installed', 613 | }) 614 | } 615 | it { 616 | should contain_package('ri').with({ 617 | 'ensure' => 'installed', 618 | }) 619 | } 620 | it { 621 | should contain_package('pkg-config').with({ 622 | 'ensure' => 'installed', 623 | }) 624 | } 625 | it { 626 | should contain_package('rake').with({ 627 | 'ensure' => 'installed', 628 | 'name' => 'rake', 629 | 'require' => 'Package[ruby]', 630 | }) 631 | } 632 | it { 633 | should contain_package('bundler').with({ 634 | 'ensure' => 'installed', 635 | 'name' => 'bundler', 636 | 'provider' => 'gem', 637 | 'require' => 'Package[ruby]', 638 | }) 639 | } 640 | end 641 | context 'when using latest version' do 642 | let :params do 643 | { 644 | :ensure => 'latest', 645 | :rake_ensure => 'latest', 646 | :bundler_ensure => 'latest' 647 | } 648 | end 649 | it { 650 | should contain_package('ruby2.0-dev').with_ensure('latest') 651 | } 652 | it { 653 | should contain_package('ri').with_ensure('latest') 654 | } 655 | it { 656 | should contain_package('pkg-config').with_ensure('latest') 657 | } 658 | it { 659 | should contain_package('rake').with_ensure('latest') 660 | } 661 | it { 662 | should contain_package('bundler').with_ensure('latest') 663 | } 664 | end 665 | context 'when using custom packages' do 666 | let :params do 667 | { 668 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 669 | :rake_package => 'magic-rake', 670 | :bundler_package => 'sparkly-bundler' 671 | } 672 | end 673 | it { 674 | should contain_package('magic-ruby-dev') 675 | } 676 | it { 677 | should contain_package('sparkly-ruby-dev') 678 | } 679 | it { 680 | should contain_package('rake').with_name('magic-rake') 681 | } 682 | it { 683 | should contain_package('bundler').with_name('sparkly-bundler') 684 | } 685 | it { 686 | should_not contain_package('ruby2.0-dev') 687 | } 688 | it { 689 | should_not contain_package('ri') 690 | } 691 | it { 692 | should_not contain_package('pkg-config') 693 | } 694 | end 695 | end 696 | end 697 | 698 | describe 'with ruby 2.1.1' do 699 | let :pre_condition do 700 | 'class { \'ruby\': version => \'2.1.1\' }' 701 | end 702 | describe 'when called on Redhat' do 703 | let (:facts) do 704 | { 705 | :osfamily => 'RedHat', 706 | :path => '/usr/local/bin:/usr/bin:/bin' 707 | } 708 | end 709 | context 'with no parameters' do 710 | it { 711 | should contain_package('ruby-devel').with({ 712 | 'ensure' => 'installed', 713 | }) 714 | } 715 | it { 716 | should contain_package('rake').with({ 717 | 'ensure' => 'installed', 718 | 'name' => 'rubygem-rake', 719 | 'require' => 'Package[ruby]', 720 | }) 721 | } 722 | it { 723 | should contain_package('bundler').with({ 724 | 'ensure' => 'installed', 725 | 'name' => 'bundler', 726 | 'provider' => 'gem', 727 | 'require' => 'Package[ruby]', 728 | }) 729 | } 730 | end 731 | end 732 | 733 | describe 'when called on Amazon' do 734 | let (:facts) do 735 | { 736 | :osfamily => 'Amazon', 737 | :path => '/usr/local/bin:/usr/bin:/bin' 738 | } 739 | end 740 | context 'with no parameters' do 741 | it { 742 | should contain_package('ruby-devel').with({ 743 | 'ensure' => 'installed', 744 | }) 745 | } 746 | it { 747 | should contain_package('rake').with({ 748 | 'ensure' => 'installed', 749 | 'name' => 'rubygem-rake', 750 | 'require' => 'Package[ruby]', 751 | }) 752 | } 753 | it { 754 | should contain_package('bundler').with({ 755 | 'ensure' => 'installed', 756 | 'name' => 'bundler', 757 | 'provider' => 'gem', 758 | 'require' => 'Package[ruby]', 759 | }) 760 | } 761 | end 762 | end 763 | 764 | describe 'when called on Debian' do 765 | let (:facts) do 766 | { 767 | :osfamily => 'Debian', 768 | :operatingsystem => 'Debian', 769 | :path => '/usr/local/bin:/usr/bin:/bin' 770 | } 771 | end 772 | context 'with no parameters' do 773 | it { 774 | should contain_package('ruby2.1-dev').with({ 775 | 'ensure' => 'installed', 776 | }) 777 | } 778 | it { 779 | should contain_package('ri').with({ 780 | 'ensure' => 'installed', 781 | }) 782 | } 783 | it { 784 | should contain_package('pkg-config').with({ 785 | 'ensure' => 'installed', 786 | }) 787 | } 788 | it { 789 | should contain_package('rake').with({ 790 | 'ensure' => 'installed', 791 | 'name' => 'rake', 792 | 'require' => 'Package[ruby]', 793 | }) 794 | } 795 | it { 796 | should contain_package('bundler').with({ 797 | 'ensure' => 'installed', 798 | 'name' => 'bundler', 799 | 'provider' => 'gem', 800 | 'require' => 'Package[ruby]', 801 | }) 802 | } 803 | end 804 | context 'when using latest version' do 805 | let :params do 806 | { 807 | :ensure => 'latest', 808 | :rake_ensure => 'latest', 809 | :bundler_ensure => 'latest' 810 | } 811 | end 812 | it { 813 | should contain_package('ruby2.1-dev').with_ensure('latest') 814 | } 815 | it { 816 | should contain_package('ri').with_ensure('latest') 817 | } 818 | it { 819 | should contain_package('pkg-config').with_ensure('latest') 820 | } 821 | it { 822 | should contain_package('rake').with_ensure('latest') 823 | } 824 | it { 825 | should contain_package('bundler').with_ensure('latest') 826 | } 827 | end 828 | context 'when using custom packages' do 829 | let :params do 830 | { 831 | :ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'], 832 | :rake_package => 'magic-rake', 833 | :bundler_package => 'sparkly-bundler' 834 | } 835 | end 836 | it { 837 | should contain_package('magic-ruby-dev') 838 | } 839 | it { 840 | should contain_package('sparkly-ruby-dev') 841 | } 842 | it { 843 | should contain_package('rake').with_name('magic-rake') 844 | } 845 | it { 846 | should contain_package('bundler').with_name('sparkly-bundler') 847 | } 848 | it { 849 | should_not contain_package('ruby2.1-dev') 850 | } 851 | it { 852 | should_not contain_package('ri') 853 | } 854 | it { 855 | should_not contain_package('pkg-config') 856 | } 857 | end 858 | end 859 | end 860 | end 861 | -------------------------------------------------------------------------------- /spec/classes/gemrc_spec.rb: -------------------------------------------------------------------------------- 1 | # Only testing on RedHat because the outcome is the same on Debian. 2 | require 'spec_helper' 3 | describe 'ruby::gemrc', :type => :class do 4 | describe 'when called with no parameters' do 5 | let (:facts) { { :osfamily => 'Redhat', 6 | :path => '/usr/local/bin:/usr/bin:/bin' } } 7 | it { 8 | should contain_file('gemrc').with({ 9 | 'ensure' => 'absent', 10 | }) 11 | } 12 | end 13 | 14 | describe 'when called setting verbose parameter' do 15 | let (:facts) { { :osfamily => 'Redhat', 16 | :path => '/usr/local/bin:/usr/bin:/bin' } } 17 | let (:params) { { :verbose => ':really' } } 18 | it { 19 | should contain_file('gemrc').with({ 20 | 'ensure' => 'file', 21 | 'path' => '/etc/gemrc' 22 | }) 23 | } 24 | it { 25 | should contain_file('gemrc').with_content(/^:verbose: :really$/) 26 | } 27 | end 28 | 29 | describe 'when called setting sources parameter' do 30 | let (:facts) { { :osfamily => 'Redhat', 31 | :path => '/usr/local/bin:/usr/bin:/bin' } } 32 | let (:params) { { :sources => [ 'https://rubygems.org', 'https://ourgems.org' ] } } 33 | it { 34 | should contain_file('gemrc').with({ 35 | 'ensure' => 'file', 36 | 'path' => '/etc/gemrc' 37 | }) 38 | } 39 | it { 40 | should contain_file('gemrc').with_content(/:sources:\n\s{2}-\shttps:\/\/rubygems.org\n\s{2}-\shttps:\/\/ourgems.org/) 41 | } 42 | end 43 | 44 | describe 'when called setting update_sources parameter' do 45 | let (:facts) { { :osfamily => 'Redhat', 46 | :path => '/usr/local/bin:/usr/bin:/bin' } } 47 | let (:params) { { :update_sources => false } } 48 | it { 49 | should contain_file('gemrc').with({ 50 | 'ensure' => 'file', 51 | 'path' => '/etc/gemrc' 52 | }) 53 | } 54 | it { 55 | should contain_file('gemrc').with_content(/^:update_sources: false$/) 56 | } 57 | end 58 | 59 | describe 'when called setting backtrace parameter' do 60 | let (:facts) { { :osfamily => 'Redhat', 61 | :path => '/usr/local/bin:/usr/bin:/bin' } } 62 | let (:params) { { :backtrace => true } } 63 | it { 64 | should contain_file('gemrc').with({ 65 | 'ensure' => 'file', 66 | 'path' => '/etc/gemrc' 67 | }) 68 | } 69 | it { 70 | should contain_file('gemrc').with_content(/^:backtrace: true$/) 71 | } 72 | end 73 | 74 | describe 'when called setting gempath parameter' do 75 | let (:facts) { { :osfamily => 'Redhat', 76 | :path => '/usr/local/bin:/usr/bin:/bin' } } 77 | let (:params) { { :gempath => [ '/usr/local/share/gems', '/var/lib/gems' ] } } 78 | it { 79 | should contain_file('gemrc').with({ 80 | 'ensure' => 'file', 81 | 'path' => '/etc/gemrc' 82 | }) 83 | } 84 | it { 85 | should contain_file('gemrc').with_content(%r{^:gempath: /usr/local/share/gems:/var/lib/gems$}) 86 | } 87 | end 88 | 89 | describe 'when called setting disable_default_gem_server parameter' do 90 | let (:facts) { { :osfamily => 'Redhat', 91 | :path => '/usr/local/bin:/usr/bin:/bin' } } 92 | let (:params) { { :disable_default_gem_server => true } } 93 | it { 94 | should contain_file('gemrc').with({ 95 | 'ensure' => 'file', 96 | 'path' => '/etc/gemrc' 97 | }) 98 | } 99 | it { 100 | should contain_file('gemrc').with_content(%r{^:disable_default_gem_server: true$}) 101 | } 102 | end 103 | 104 | describe 'when called setting gem_command parameter' do 105 | let (:facts) { { :osfamily => 'Redhat', 106 | :path => '/usr/local/bin:/usr/bin:/bin' } } 107 | let (:params) { { :gem_command => { 'push' => [ 'host=https://gemshost.internal', 'quiet' ]} } } 108 | it { 109 | should contain_file('gemrc').with({ 110 | 'ensure' => 'file', 111 | 'path' => '/etc/gemrc' 112 | }) 113 | } 114 | it { 115 | should contain_file('gemrc').with_content(%r{^push: --host=https:..gemshost.internal --quiet$}) 116 | } 117 | end 118 | 119 | end 120 | -------------------------------------------------------------------------------- /spec/classes/init_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'ruby', :type => :class do 3 | 4 | context 'On the Amazon operating system' do 5 | let :facts do 6 | { 7 | :osfamily => 'Amazon', 8 | } 9 | end 10 | it { should contain_class('ruby::params') } 11 | it { 12 | should contain_package('ruby').with({ 13 | 'ensure' => 'installed', 14 | 'name' => 'ruby', 15 | }) 16 | } 17 | it { 18 | should contain_package('rubygems').with({ 19 | 'ensure' => 'installed', 20 | 'name' => 'rubygems', 21 | 'require' => 'Package[ruby]', 22 | }) 23 | } 24 | it { should_not contain_package('ruby-switch') } 25 | it { should_not contain_package('rubygems-integration') } 26 | it { should_not contain_package('rubygems-update') } 27 | it { should_not contain_exec('ruby::update_rubygems') } 28 | it { should_not contain_exec('switch_ruby') } 29 | it { should_not contain_file('ruby_bin') } 30 | it { should_not contain_file('gem_bin') } 31 | 32 | describe 'when passed true to update rubygems' do 33 | let :params do 34 | { 35 | :rubygems_update => 'true' 36 | } 37 | end 38 | it { 39 | should contain_package('rubygems-update').with({ 40 | 'ensure' => 'installed', 41 | 'require' => 'Package[rubygems]', 42 | 'provider' => 'gem', 43 | 'notify' => 'Exec[ruby::update_rubygems]' 44 | }) 45 | } 46 | it { 47 | should contain_exec('ruby::update_rubygems').with({ 48 | 'path' => '/usr/local/bin:/usr/bin:/bin', 49 | 'command' => 'update_rubygems', 50 | 'refreshonly' => true 51 | }) 52 | } 53 | end 54 | 55 | describe 'when passed a custom rubygem version' do 56 | let :params do 57 | { 58 | :gems_version => '1.8.7' 59 | } 60 | end 61 | it { 62 | should contain_package('rubygems').with({ 63 | 'ensure' => '1.8.7' 64 | }) 65 | } 66 | it { should_not contain_package('rubygems-update') } 67 | describe 'with rubygems_update set to true' do 68 | let :params do 69 | { 70 | :gems_version => '1.8.7', 71 | :rubygems_update => 'true' 72 | } 73 | end 74 | it { 75 | should contain_package('rubygems-update').with({ 76 | 'ensure' => '1.8.7' 77 | }) 78 | } 79 | end 80 | end 81 | 82 | describe 'when given ruby and rubygem versions' do 83 | let :params do 84 | { 85 | :gems_version => '1.8.6', 86 | :version => '1.8.7' 87 | } 88 | end 89 | it { 90 | should contain_package('ruby').with({ 91 | 'ensure' => 'installed', 92 | 'name' => 'ruby' 93 | }) 94 | } 95 | it { should_not contain_package('rubygems-update') } 96 | 97 | describe 'with rubygems_update set to true' do 98 | let :params do 99 | { 100 | :gems_version => '1.8.6', 101 | :version => '1.8.7', 102 | :rubygems_update => 'true' 103 | } 104 | end 105 | it { 106 | should contain_package('rubygems-update').with({ 107 | 'ensure' => '1.8.6' 108 | }) 109 | } 110 | end 111 | end 112 | 113 | describe 'with a custom ruby package' do 114 | let :params do 115 | { 116 | :ruby_package => 'sparkly-ruby' 117 | } 118 | end 119 | it { 120 | should contain_package('ruby').with({ 121 | 'ensure' => 'installed', 122 | 'name' => 'sparkly-ruby' 123 | }) 124 | } 125 | end 126 | 127 | describe 'with a custom rubygems package' do 128 | let :params do 129 | { 130 | :rubygems_package => 'sparkly-rubygems' 131 | } 132 | end 133 | it { 134 | should contain_package('rubygems').with({ 135 | 'name' => 'sparkly-rubygems', 136 | }) 137 | } 138 | end 139 | 140 | describe 'with ruby 1.9.1' do 141 | let :params do 142 | { 143 | :version => '1.9.1' 144 | } 145 | end 146 | it { 147 | should contain_package('ruby').with({ 148 | 'ensure' => 'installed', 149 | 'name' => 'ruby' 150 | }) 151 | } 152 | end 153 | 154 | describe 'with ruby 2.0' do 155 | let :params do 156 | { 157 | :version => '2.0' 158 | } 159 | end 160 | it { 161 | should contain_package('ruby').with({ 162 | 'ensure' => 'installed', 163 | 'name' => 'ruby' 164 | }) 165 | } 166 | end 167 | 168 | describe 'when given a rubygem version and disable rubygems update' do 169 | let :params do 170 | { 171 | :gems_version => '1.8.7', 172 | :rubygems_update => false 173 | } 174 | end 175 | it { 176 | should contain_package('rubygems').with({ 177 | 'ensure' => '1.8.7', 178 | 'require' => 'Package[ruby]' 179 | }) 180 | } 181 | it { should_not contain_package('rubygems-update') } 182 | it { should_not contain_exec('ruby::update_rubygems') } 183 | end 184 | 185 | describe 'when using the latest release' do 186 | let :params do 187 | { 188 | :latest_release => true 189 | } 190 | end 191 | it { 192 | should contain_package('ruby').with({ 193 | 'ensure' => 'latest' 194 | }) 195 | } 196 | end 197 | 198 | describe 'when using ruby-switch' do 199 | let :params do 200 | { 201 | :switch => true 202 | } 203 | end 204 | it { should_not contain_package('ruby-switch') } 205 | it { should_not contain_exec('switch_ruby') } 206 | it { should_not contain_file('ruby_bin') } 207 | it { should_not contain_file('gem_bin') } 208 | end 209 | 210 | describe 'when setting the system default' do 211 | let :params do 212 | { 213 | :set_system_default => true 214 | } 215 | end 216 | it { should_not contain_package('ruby-switch') } 217 | it { should_not contain_exec('switch_ruby') } 218 | it { should_not contain_file('ruby_bin') } 219 | it { should_not contain_file('gem_bin') } 220 | end 221 | 222 | describe 'when using rubygem package integrations' do 223 | let :params do 224 | { 225 | :gem_integration => true 226 | } 227 | end 228 | it { should_not contain_package('rubygems-integration') } 229 | end 230 | 231 | end 232 | 233 | context 'On a RedHat family operating system' do 234 | let :facts do 235 | { 236 | :osfamily => 'RedHat', 237 | } 238 | end 239 | it { should contain_class('ruby::params') } 240 | it { 241 | should contain_package('ruby').with({ 242 | 'ensure' => 'installed', 243 | 'name' => 'ruby', 244 | }) 245 | } 246 | it { 247 | should contain_package('rubygems').with({ 248 | 'ensure' => 'installed', 249 | 'name' => 'rubygems', 250 | 'require' => 'Package[ruby]', 251 | }) 252 | } 253 | 254 | it { should_not contain_package('ruby-switch') } 255 | it { should_not contain_package('rubygems-integration') } 256 | it { should_not contain_package('rubygems-update') } 257 | it { should_not contain_exec('ruby::update_rubygems') } 258 | it { should_not contain_exec('switch_ruby') } 259 | it { should_not contain_file('ruby_bin') } 260 | it { should_not contain_file('gem_bin') } 261 | 262 | describe 'when rubygems_update is set to true' do 263 | let :params do 264 | { 265 | :rubygems_update => 'true' 266 | } 267 | end 268 | it { 269 | should contain_package('rubygems-update').with({ 270 | 'ensure' => 'installed', 271 | 'require' => 'Package[rubygems]', 272 | 'provider' => 'gem', 273 | 'notify' => 'Exec[ruby::update_rubygems]' 274 | }) 275 | } 276 | it { 277 | should contain_exec('ruby::update_rubygems').with({ 278 | 'path' => '/usr/local/bin:/usr/bin:/bin', 279 | 'command' => 'update_rubygems', 280 | 'refreshonly' => true 281 | }) 282 | } 283 | end 284 | 285 | describe 'when passed a custom rubygem version' do 286 | let :params do 287 | { 288 | :gems_version => '1.8.7' 289 | } 290 | end 291 | it { 292 | should contain_package('rubygems').with({ 293 | 'ensure' => '1.8.7' 294 | }) 295 | } 296 | it { should_not contain_package('rubygems-update') } 297 | 298 | describe 'when rubygems_update is set to true' do 299 | let :params do 300 | { 301 | :gems_version => '1.8.7', 302 | :rubygems_update => 'true' 303 | } 304 | end 305 | it { 306 | should contain_package('rubygems-update').with({ 307 | 'ensure' => '1.8.7' 308 | }) 309 | } 310 | end 311 | end 312 | 313 | describe 'when given ruby and rubygem versions' do 314 | let :params do 315 | { 316 | :gems_version => '1.8.6', 317 | :version => '1.8.7' 318 | } 319 | end 320 | it { 321 | should contain_package('ruby').with({ 322 | 'ensure' => 'installed', 323 | 'name' => 'ruby' 324 | }) 325 | } 326 | it { should_not contain_package('rubygems-update') } 327 | 328 | describe 'when rubygems_update is set to true' do 329 | let :params do 330 | { 331 | :gems_version => '1.8.6', 332 | :version => '1.8.7', 333 | :rubygems_update => 'true' 334 | } 335 | end 336 | it { 337 | should contain_package('rubygems-update').with({ 338 | 'ensure' => '1.8.6' 339 | }) 340 | } 341 | end 342 | end 343 | 344 | describe 'with a custom ruby package' do 345 | let :params do 346 | { 347 | :ruby_package => 'sparkly-ruby' 348 | } 349 | end 350 | it { 351 | should contain_package('ruby').with({ 352 | 'ensure' => 'installed', 353 | 'name' => 'sparkly-ruby' 354 | }) 355 | } 356 | end 357 | 358 | describe 'with a custom rubygems package' do 359 | let :params do 360 | { 361 | :rubygems_package => 'sparkly-rubygems' 362 | } 363 | end 364 | it { 365 | should contain_package('rubygems').with({ 366 | 'name' => 'sparkly-rubygems', 367 | }) 368 | } 369 | end 370 | 371 | describe 'with ruby 1.9.1' do 372 | let :params do 373 | { 374 | :version => '1.9.1' 375 | } 376 | end 377 | it { 378 | should contain_package('ruby').with({ 379 | 'ensure' => 'installed', 380 | 'name' => 'ruby' 381 | }) 382 | } 383 | end 384 | 385 | describe 'with ruby 2.0' do 386 | let :params do 387 | { 388 | :version => '2.0' 389 | } 390 | end 391 | it { 392 | should contain_package('ruby').with({ 393 | 'ensure' => 'installed', 394 | 'name' => 'ruby' 395 | }) 396 | } 397 | end 398 | 399 | describe 'when given a rubygem version and disable rubygems update' do 400 | let :params do 401 | { 402 | :gems_version => '1.8.7', 403 | :rubygems_update => false 404 | } 405 | end 406 | it { 407 | should contain_package('rubygems').with({ 408 | 'ensure' => '1.8.7', 409 | 'require' => 'Package[ruby]' 410 | }) 411 | } 412 | it { should_not contain_package('rubygems-update') } 413 | it { should_not contain_exec('ruby::update_rubygems') } 414 | end 415 | 416 | describe 'when using the latest release' do 417 | let :params do 418 | { 419 | :latest_release => true 420 | } 421 | end 422 | it { 423 | should contain_package('ruby').with({ 424 | 'ensure' => 'latest' 425 | }) 426 | } 427 | end 428 | 429 | describe 'when using ruby-switch' do 430 | let :params do 431 | { 432 | :switch => true 433 | } 434 | end 435 | it { should_not contain_package('ruby-switch') } 436 | it { should_not contain_exec('switch_ruby') } 437 | it { should_not contain_file('ruby_bin') } 438 | it { should_not contain_file('gem_bin') } 439 | end 440 | 441 | describe 'when setting the system default' do 442 | let :params do 443 | { 444 | :set_system_default => true 445 | } 446 | end 447 | it { should_not contain_package('ruby-switch') } 448 | it { should_not contain_exec('switch_ruby') } 449 | it { should_not contain_file('ruby_bin') } 450 | it { should_not contain_file('gem_bin') } 451 | end 452 | 453 | describe 'when using rubygem package integrations' do 454 | let :params do 455 | { 456 | :gem_integration => true 457 | } 458 | end 459 | it { should_not contain_package('rubygems-integration') } 460 | end 461 | 462 | end 463 | 464 | context 'On a Debian family operating system' do 465 | let :facts do 466 | { 467 | :osfamily => 'Debian', 468 | :operatingsystem => 'Debian', 469 | :operatingsystemrelease => '6.0', 470 | } 471 | end 472 | it { should contain_class('ruby::params') } 473 | it { 474 | should contain_package('ruby').with({ 475 | 'ensure' => 'installed', 476 | 'name' => 'ruby', 477 | }) 478 | } 479 | it { 480 | should contain_package('rubygems').with({ 481 | 'ensure' => 'installed', 482 | 'name' => 'rubygems', 483 | 'require' => 'Package[ruby]', 484 | }) 485 | } 486 | it { should_not contain_package('rubygems-update') } 487 | it { should_not contain_exec('ruby::update_rubygems') } 488 | it { should_not contain_package('ruby-switch') } 489 | it { should_not contain_exec('switch_ruby') } 490 | it { should_not contain_file('ruby_bin') } 491 | it { should_not contain_file('gem_bin') } 492 | 493 | describe 'with a custom ruby package' do 494 | let :params do 495 | { 496 | :ruby_package => 'sparkly-ruby' 497 | } 498 | end 499 | it { 500 | should contain_package('ruby').with({ 501 | 'ensure' => 'installed', 502 | 'name' => 'sparkly-ruby' 503 | }) 504 | } 505 | end 506 | 507 | describe 'with a custom rubygems package' do 508 | let :params do 509 | { 510 | :rubygems_package => 'sparkly-rubygems' 511 | } 512 | end 513 | it { 514 | should contain_package('rubygems').with({ 515 | 'name' => 'sparkly-rubygems', 516 | }) 517 | } 518 | end 519 | 520 | describe 'when using the latest release' do 521 | let :params do 522 | { 523 | :latest_release => true 524 | } 525 | end 526 | it { 527 | should contain_package('ruby').with({ 528 | 'ensure' => 'latest' 529 | }) 530 | } 531 | end 532 | 533 | describe 'with ruby 1.8 with switch' do 534 | let :params do 535 | { 536 | :version => '1.8', 537 | :switch => true 538 | } 539 | end 540 | it { 541 | should contain_package('ruby').with({ 542 | 'ensure' => 'installed', 543 | 'name' => 'ruby1.8' 544 | }) 545 | } 546 | it { 547 | should contain_file('ruby_bin').with({ 548 | 'ensure' => 'link', 549 | 'path' => '/usr/bin/ruby', 550 | 'target' => '/usr/bin/ruby1.8', 551 | 'require' => 'Package[ruby]' 552 | } ) 553 | } 554 | it { 555 | should contain_file('gem_bin').with({ 556 | 'ensure' => 'link', 557 | 'path' => '/usr/bin/gem', 558 | 'target' => '/usr/bin/gem1.8', 559 | 'require' => 'Package[rubygems]' 560 | } ) 561 | } 562 | end 563 | 564 | describe 'with ruby 1.9.1 with switch' do 565 | let :params do 566 | { 567 | :version => '1.9.1', 568 | :switch => true 569 | } 570 | end 571 | it { 572 | should contain_package('ruby').with({ 573 | 'ensure' => 'installed', 574 | 'name' => 'ruby1.9.1' 575 | }) 576 | } 577 | it { 578 | should contain_file('ruby_bin').with({ 579 | 'ensure' => 'link', 580 | 'path' => '/usr/bin/ruby', 581 | 'target' => '/usr/bin/ruby1.9.1', 582 | 'require' => 'Package[ruby]' 583 | } ) 584 | } 585 | it { 586 | should contain_file('gem_bin').with({ 587 | 'ensure' => 'link', 588 | 'path' => '/usr/bin/gem', 589 | 'target' => '/usr/bin/gem1.9.1', 590 | 'require' => 'Package[rubygems]' 591 | } ) 592 | } 593 | end 594 | 595 | describe 'with ruby 2.0 with switch' do 596 | let :params do 597 | { 598 | :version => '2.0', 599 | :switch => true 600 | } 601 | end 602 | it { 603 | should contain_package('ruby').with({ 604 | 'ensure' => 'installed', 605 | 'name' => 'ruby2.0' 606 | }) 607 | } 608 | it { 609 | should contain_file('ruby_bin').with({ 610 | 'ensure' => 'link', 611 | 'path' => '/usr/bin/ruby', 612 | 'target' => '/usr/bin/ruby2.0', 613 | 'require' => 'Package[ruby]' 614 | } ) 615 | } 616 | it { 617 | should contain_file('gem_bin').with({ 618 | 'ensure' => 'link', 619 | 'path' => '/usr/bin/gem', 620 | 'target' => '/usr/bin/gem2.0', 621 | 'require' => 'Package[rubygems]' 622 | } ) 623 | } 624 | end 625 | 626 | describe 'with ruby 2.1 with switch' do 627 | let :params do 628 | { 629 | :version => '2.1', 630 | :switch => true 631 | } 632 | end 633 | it { 634 | should contain_package('ruby').with({ 635 | 'ensure' => 'installed', 636 | 'name' => 'ruby2.1' 637 | }) 638 | } 639 | it { 640 | should contain_file('ruby_bin').with({ 641 | 'ensure' => 'link', 642 | 'path' => '/usr/bin/ruby', 643 | 'target' => '/usr/bin/ruby2.1', 644 | 'require' => 'Package[ruby]' 645 | } ) 646 | } 647 | it { 648 | should contain_file('gem_bin').with({ 649 | 'ensure' => 'link', 650 | 'path' => '/usr/bin/gem', 651 | 'target' => '/usr/bin/gem2.1', 652 | 'require' => 'Package[rubygems]' 653 | } ) 654 | } 655 | end 656 | 657 | describe 'with ruby 1.8 with set_system_default' do 658 | let :params do 659 | { 660 | :version => '1.8', 661 | :set_system_default => true 662 | } 663 | end 664 | it { 665 | should contain_package('ruby').with({ 666 | 'ensure' => 'installed', 667 | 'name' => 'ruby1.8' 668 | }) 669 | } 670 | it { 671 | should contain_file('ruby_bin').with({ 672 | 'ensure' => 'link', 673 | 'path' => '/usr/bin/ruby', 674 | 'target' => '/usr/bin/ruby1.8', 675 | 'require' => 'Package[ruby]' 676 | } ) 677 | } 678 | it { 679 | should contain_file('gem_bin').with({ 680 | 'ensure' => 'link', 681 | 'path' => '/usr/bin/gem', 682 | 'target' => '/usr/bin/gem1.8', 683 | 'require' => 'Package[rubygems]' 684 | } ) 685 | } 686 | end 687 | 688 | describe 'with ruby 1.9.1 with set_system_default' do 689 | let :params do 690 | { 691 | :version => '1.9.1', 692 | :set_system_default => true 693 | } 694 | end 695 | it { 696 | should contain_package('ruby').with({ 697 | 'ensure' => 'installed', 698 | 'name' => 'ruby1.9.1' 699 | }) 700 | } 701 | it { 702 | should contain_file('ruby_bin').with({ 703 | 'ensure' => 'link', 704 | 'path' => '/usr/bin/ruby', 705 | 'target' => '/usr/bin/ruby1.9.1', 706 | 'require' => 'Package[ruby]' 707 | } ) 708 | } 709 | it { 710 | should contain_file('gem_bin').with({ 711 | 'ensure' => 'link', 712 | 'path' => '/usr/bin/gem', 713 | 'target' => '/usr/bin/gem1.9.1', 714 | 'require' => 'Package[rubygems]' 715 | } ) 716 | } 717 | end 718 | 719 | describe 'with ruby 2.0 with set_system_default' do 720 | let :params do 721 | { 722 | :version => '2.0', 723 | :set_system_default => true 724 | } 725 | end 726 | it { 727 | should contain_package('ruby').with({ 728 | 'ensure' => 'installed', 729 | 'name' => 'ruby2.0' 730 | }) 731 | } 732 | it { 733 | should contain_file('ruby_bin').with({ 734 | 'ensure' => 'link', 735 | 'path' => '/usr/bin/ruby', 736 | 'target' => '/usr/bin/ruby2.0', 737 | 'require' => 'Package[ruby]' 738 | } ) 739 | } 740 | it { 741 | should contain_file('gem_bin').with({ 742 | 'ensure' => 'link', 743 | 'path' => '/usr/bin/gem', 744 | 'target' => '/usr/bin/gem2.0', 745 | 'require' => 'Package[rubygems]' 746 | } ) 747 | } 748 | end 749 | 750 | describe 'with ruby 2.1 with set_system_default' do 751 | let :params do 752 | { 753 | :version => '2.1', 754 | :set_system_default => true 755 | } 756 | end 757 | it { 758 | should contain_package('ruby').with({ 759 | 'ensure' => 'installed', 760 | 'name' => 'ruby2.1' 761 | }) 762 | } 763 | it { 764 | should contain_file('ruby_bin').with({ 765 | 'ensure' => 'link', 766 | 'path' => '/usr/bin/ruby', 767 | 'target' => '/usr/bin/ruby2.1', 768 | 'require' => 'Package[ruby]' 769 | } ) 770 | } 771 | it { 772 | should contain_file('gem_bin').with({ 773 | 'ensure' => 'link', 774 | 'path' => '/usr/bin/gem', 775 | 'target' => '/usr/bin/gem2.1', 776 | 'require' => 'Package[rubygems]' 777 | } ) 778 | } 779 | end 780 | 781 | end 782 | 783 | context 'On Ubuntu 12.04 LTS (Precise Pangolin)' do 784 | let :facts do 785 | { 786 | :osfamily => 'Debian', 787 | :operatingsystem => 'Ubuntu', 788 | :operatingsystemrelease => '12.04' 789 | } 790 | end 791 | it { should contain_class('ruby::params') } 792 | it { 793 | should contain_package('ruby').with({ 794 | 'ensure' => 'installed', 795 | 'name' => 'ruby', 796 | }) 797 | } 798 | it { 799 | should contain_package('rubygems').with({ 800 | 'ensure' => 'installed', 801 | 'name' => 'rubygems', 802 | 'require' => 'Package[ruby]', 803 | }) 804 | } 805 | it { should_not contain_package('rubygems-update') } 806 | it { should_not contain_exec('ruby::update_rubygems') } 807 | it { should_not contain_package('ruby-switch') } 808 | it { should_not contain_exec('switch_ruby') } 809 | it { should_not contain_file('ruby_bin') } 810 | it { should_not contain_file('gem_bin') } 811 | 812 | describe 'with a custom ruby package' do 813 | let :params do 814 | { 815 | :ruby_package => 'sparkly-ruby' 816 | } 817 | end 818 | it { 819 | should contain_package('ruby').with({ 820 | 'ensure' => 'installed', 821 | 'name' => 'sparkly-ruby' 822 | }) 823 | } 824 | end 825 | 826 | describe 'with a custom rubygems package' do 827 | let :params do 828 | { 829 | :rubygems_package => 'sparkly-rubygems' 830 | } 831 | end 832 | it { 833 | should contain_package('rubygems').with({ 834 | 'name' => 'sparkly-rubygems', 835 | }) 836 | } 837 | end 838 | 839 | describe 'when using the latest release' do 840 | let :params do 841 | { 842 | :latest_release => true 843 | } 844 | end 845 | it { 846 | should contain_package('ruby').with({ 847 | 'ensure' => 'latest' 848 | }) 849 | } 850 | end 851 | 852 | describe 'with ruby 1.8 with switch' do 853 | let :params do 854 | { 855 | :version => '1.8', 856 | :switch => true 857 | } 858 | end 859 | it { 860 | should contain_package('ruby').with({ 861 | 'ensure' => 'installed', 862 | 'name' => 'ruby1.8' 863 | }) 864 | } 865 | it { 866 | should contain_file('ruby_bin').with({ 867 | 'ensure' => 'link', 868 | 'path' => '/usr/bin/ruby', 869 | 'target' => '/usr/bin/ruby1.8', 870 | 'require' => 'Package[ruby]' 871 | } ) 872 | } 873 | it { 874 | should contain_file('gem_bin').with({ 875 | 'ensure' => 'link', 876 | 'path' => '/usr/bin/gem', 877 | 'target' => '/usr/bin/gem1.8', 878 | 'require' => 'Package[rubygems]' 879 | } ) 880 | } 881 | end 882 | 883 | describe 'with ruby 1.9.1 with switch' do 884 | let :params do 885 | { 886 | :version => '1.9.1', 887 | :switch => true 888 | } 889 | end 890 | it { 891 | should contain_package('ruby').with({ 892 | 'ensure' => 'installed', 893 | 'name' => 'ruby1.9.1' 894 | }) 895 | } 896 | it { 897 | should contain_file('ruby_bin').with({ 898 | 'ensure' => 'link', 899 | 'path' => '/usr/bin/ruby', 900 | 'target' => '/usr/bin/ruby1.9.1', 901 | 'require' => 'Package[ruby]' 902 | } ) 903 | } 904 | it { 905 | should contain_file('gem_bin').with({ 906 | 'ensure' => 'link', 907 | 'path' => '/usr/bin/gem', 908 | 'target' => '/usr/bin/gem1.9.1', 909 | 'require' => 'Package[rubygems]' 910 | } ) 911 | } 912 | end 913 | 914 | describe 'with ruby 2.0 with switch' do 915 | let :params do 916 | { 917 | :version => '2.0', 918 | :switch => true 919 | } 920 | end 921 | it { 922 | should contain_package('ruby').with({ 923 | 'ensure' => 'installed', 924 | 'name' => 'ruby2.0' 925 | }) 926 | } 927 | it { 928 | should contain_file('ruby_bin').with({ 929 | 'ensure' => 'link', 930 | 'path' => '/usr/bin/ruby', 931 | 'target' => '/usr/bin/ruby2.0', 932 | 'require' => 'Package[ruby]' 933 | } ) 934 | } 935 | it { 936 | should contain_file('gem_bin').with({ 937 | 'ensure' => 'link', 938 | 'path' => '/usr/bin/gem', 939 | 'target' => '/usr/bin/gem2.0', 940 | 'require' => 'Package[rubygems]' 941 | } ) 942 | } 943 | end 944 | 945 | describe 'with ruby 2.1 with switch' do 946 | let :params do 947 | { 948 | :version => '2.1', 949 | :switch => true 950 | } 951 | end 952 | it { 953 | should contain_package('ruby').with({ 954 | 'ensure' => 'installed', 955 | 'name' => 'ruby2.1' 956 | }) 957 | } 958 | it { 959 | should contain_file('ruby_bin').with({ 960 | 'ensure' => 'link', 961 | 'path' => '/usr/bin/ruby', 962 | 'target' => '/usr/bin/ruby2.1', 963 | 'require' => 'Package[ruby]' 964 | } ) 965 | } 966 | it { 967 | should contain_file('gem_bin').with({ 968 | 'ensure' => 'link', 969 | 'path' => '/usr/bin/gem', 970 | 'target' => '/usr/bin/gem2.1', 971 | 'require' => 'Package[rubygems]' 972 | } ) 973 | } 974 | end 975 | 976 | describe 'with ruby 1.8 with set_system_default' do 977 | let :params do 978 | { 979 | :version => '1.8', 980 | :set_system_default => true 981 | } 982 | end 983 | it { 984 | should contain_package('ruby').with({ 985 | 'ensure' => 'installed', 986 | 'name' => 'ruby1.8' 987 | }) 988 | } 989 | it { 990 | should contain_file('ruby_bin').with({ 991 | 'ensure' => 'link', 992 | 'path' => '/usr/bin/ruby', 993 | 'target' => '/usr/bin/ruby1.8', 994 | 'require' => 'Package[ruby]' 995 | } ) 996 | } 997 | it { 998 | should contain_file('gem_bin').with({ 999 | 'ensure' => 'link', 1000 | 'path' => '/usr/bin/gem', 1001 | 'target' => '/usr/bin/gem1.8', 1002 | 'require' => 'Package[rubygems]' 1003 | } ) 1004 | } 1005 | end 1006 | 1007 | describe 'with ruby 1.9.1 with set_system_default' do 1008 | let :params do 1009 | { 1010 | :version => '1.9.1', 1011 | :set_system_default => true 1012 | } 1013 | end 1014 | it { 1015 | should contain_package('ruby').with({ 1016 | 'ensure' => 'installed', 1017 | 'name' => 'ruby1.9.1' 1018 | }) 1019 | } 1020 | it { 1021 | should contain_file('ruby_bin').with({ 1022 | 'ensure' => 'link', 1023 | 'path' => '/usr/bin/ruby', 1024 | 'target' => '/usr/bin/ruby1.9.1', 1025 | 'require' => 'Package[ruby]' 1026 | } ) 1027 | } 1028 | it { 1029 | should contain_file('gem_bin').with({ 1030 | 'ensure' => 'link', 1031 | 'path' => '/usr/bin/gem', 1032 | 'target' => '/usr/bin/gem1.9.1', 1033 | 'require' => 'Package[rubygems]' 1034 | } ) 1035 | } 1036 | end 1037 | 1038 | describe 'with ruby 2.0 with set_system_default' do 1039 | let :params do 1040 | { 1041 | :version => '2.0', 1042 | :set_system_default => true 1043 | } 1044 | end 1045 | it { 1046 | should contain_package('ruby').with({ 1047 | 'ensure' => 'installed', 1048 | 'name' => 'ruby2.0' 1049 | }) 1050 | } 1051 | it { 1052 | should contain_file('ruby_bin').with({ 1053 | 'ensure' => 'link', 1054 | 'path' => '/usr/bin/ruby', 1055 | 'target' => '/usr/bin/ruby2.0', 1056 | 'require' => 'Package[ruby]' 1057 | } ) 1058 | } 1059 | it { 1060 | should contain_file('gem_bin').with({ 1061 | 'ensure' => 'link', 1062 | 'path' => '/usr/bin/gem', 1063 | 'target' => '/usr/bin/gem2.0', 1064 | 'require' => 'Package[rubygems]' 1065 | } ) 1066 | } 1067 | end 1068 | 1069 | describe 'with ruby 2.1 with set_system_default' do 1070 | let :params do 1071 | { 1072 | :version => '2.1', 1073 | :set_system_default => true 1074 | } 1075 | end 1076 | it { 1077 | should contain_package('ruby').with({ 1078 | 'ensure' => 'installed', 1079 | 'name' => 'ruby2.1' 1080 | }) 1081 | } 1082 | it { 1083 | should contain_file('ruby_bin').with({ 1084 | 'ensure' => 'link', 1085 | 'path' => '/usr/bin/ruby', 1086 | 'target' => '/usr/bin/ruby2.1', 1087 | 'require' => 'Package[ruby]' 1088 | } ) 1089 | } 1090 | it { 1091 | should contain_file('gem_bin').with({ 1092 | 'ensure' => 'link', 1093 | 'path' => '/usr/bin/gem', 1094 | 'target' => '/usr/bin/gem2.1', 1095 | 'require' => 'Package[rubygems]' 1096 | } ) 1097 | } 1098 | end 1099 | 1100 | end 1101 | 1102 | context 'On Ubuntu 13.10 (Saucy Salamander)' do 1103 | let :facts do 1104 | { 1105 | :osfamily => 'Debian', 1106 | :operatingsystem => 'Ubuntu', 1107 | :operatingsystemrelease => '13.10' 1108 | } 1109 | end 1110 | it { should contain_class('ruby::params') } 1111 | it { 1112 | should contain_package('ruby').with({ 1113 | 'ensure' => 'installed', 1114 | 'name' => 'ruby', 1115 | }) 1116 | } 1117 | it { 1118 | should contain_package('rubygems').with({ 1119 | 'ensure' => 'installed', 1120 | 'name' => 'rubygems', 1121 | 'require' => 'Package[ruby]', 1122 | }) 1123 | } 1124 | it { should_not contain_package('rubygems-update') } 1125 | it { should_not contain_exec('ruby::update_rubygems') } 1126 | it { should_not contain_package('ruby-switch') } 1127 | it { should_not contain_exec('switch_ruby') } 1128 | it { should_not contain_file('ruby_bin') } 1129 | it { should_not contain_file('gem_bin') } 1130 | 1131 | describe 'with a custom ruby package' do 1132 | let :params do 1133 | { 1134 | :ruby_package => 'sparkly-ruby' 1135 | } 1136 | end 1137 | it { 1138 | should contain_package('ruby').with({ 1139 | 'ensure' => 'installed', 1140 | 'name' => 'sparkly-ruby' 1141 | }) 1142 | } 1143 | end 1144 | 1145 | describe 'with a custom rubygems package' do 1146 | let :params do 1147 | { 1148 | :rubygems_package => 'sparkly-rubygems' 1149 | } 1150 | end 1151 | it { 1152 | should contain_package('rubygems').with({ 1153 | 'name' => 'sparkly-rubygems', 1154 | }) 1155 | } 1156 | end 1157 | 1158 | describe 'when using the latest release' do 1159 | let :params do 1160 | { 1161 | :latest_release => true 1162 | } 1163 | end 1164 | it { 1165 | should contain_package('ruby').with({ 1166 | 'ensure' => 'latest' 1167 | }) 1168 | } 1169 | end 1170 | 1171 | describe 'with ruby 1.8 with switch' do 1172 | let :params do 1173 | { 1174 | :version => '1.8', 1175 | :switch => true 1176 | } 1177 | end 1178 | it { 1179 | should contain_package('ruby').with({ 1180 | 'ensure' => 'installed', 1181 | 'name' => 'ruby1.8' 1182 | }) 1183 | } 1184 | it { 1185 | should contain_file('ruby_bin').with({ 1186 | 'ensure' => 'link', 1187 | 'path' => '/usr/bin/ruby', 1188 | 'target' => '/usr/bin/ruby1.8', 1189 | 'require' => 'Package[ruby]' 1190 | } ) 1191 | } 1192 | it { 1193 | should contain_file('gem_bin').with({ 1194 | 'ensure' => 'link', 1195 | 'path' => '/usr/bin/gem', 1196 | 'target' => '/usr/bin/gem1.8', 1197 | 'require' => 'Package[rubygems]' 1198 | } ) 1199 | } 1200 | end 1201 | 1202 | describe 'with ruby 1.9.1 with switch' do 1203 | let :params do 1204 | { 1205 | :version => '1.9.1', 1206 | :switch => true 1207 | } 1208 | end 1209 | it { 1210 | should contain_package('ruby').with({ 1211 | 'ensure' => 'installed', 1212 | 'name' => 'ruby1.9.1' 1213 | }) 1214 | } 1215 | it { 1216 | should contain_file('ruby_bin').with({ 1217 | 'ensure' => 'link', 1218 | 'path' => '/usr/bin/ruby', 1219 | 'target' => '/usr/bin/ruby1.9.1', 1220 | 'require' => 'Package[ruby]' 1221 | } ) 1222 | } 1223 | it { 1224 | should contain_file('gem_bin').with({ 1225 | 'ensure' => 'link', 1226 | 'path' => '/usr/bin/gem', 1227 | 'target' => '/usr/bin/gem1.9.1', 1228 | 'require' => 'Package[rubygems]' 1229 | } ) 1230 | } 1231 | end 1232 | 1233 | describe 'with ruby 2.0 with switch' do 1234 | let :params do 1235 | { 1236 | :version => '2.0', 1237 | :switch => true 1238 | } 1239 | end 1240 | it { 1241 | should contain_package('ruby').with({ 1242 | 'ensure' => 'installed', 1243 | 'name' => 'ruby2.0' 1244 | }) 1245 | } 1246 | it { 1247 | should contain_file('ruby_bin').with({ 1248 | 'ensure' => 'link', 1249 | 'path' => '/usr/bin/ruby', 1250 | 'target' => '/usr/bin/ruby2.0', 1251 | 'require' => 'Package[ruby]' 1252 | } ) 1253 | } 1254 | it { 1255 | should contain_file('gem_bin').with({ 1256 | 'ensure' => 'link', 1257 | 'path' => '/usr/bin/gem', 1258 | 'target' => '/usr/bin/gem2.0', 1259 | 'require' => 'Package[rubygems]' 1260 | } ) 1261 | } 1262 | end 1263 | 1264 | describe 'with ruby 2.1 with switch' do 1265 | let :params do 1266 | { 1267 | :version => '2.1', 1268 | :switch => true 1269 | } 1270 | end 1271 | it { 1272 | should contain_package('ruby').with({ 1273 | 'ensure' => 'installed', 1274 | 'name' => 'ruby2.1' 1275 | }) 1276 | } 1277 | it { 1278 | should contain_file('ruby_bin').with({ 1279 | 'ensure' => 'link', 1280 | 'path' => '/usr/bin/ruby', 1281 | 'target' => '/usr/bin/ruby2.1', 1282 | 'require' => 'Package[ruby]' 1283 | } ) 1284 | } 1285 | it { 1286 | should contain_file('gem_bin').with({ 1287 | 'ensure' => 'link', 1288 | 'path' => '/usr/bin/gem', 1289 | 'target' => '/usr/bin/gem2.1', 1290 | 'require' => 'Package[rubygems]' 1291 | } ) 1292 | } 1293 | end 1294 | 1295 | describe 'with ruby 1.8 with set_system_default' do 1296 | let :params do 1297 | { 1298 | :version => '1.8', 1299 | :set_system_default => true 1300 | } 1301 | end 1302 | it { 1303 | should contain_package('ruby').with({ 1304 | 'ensure' => 'installed', 1305 | 'name' => 'ruby1.8' 1306 | }) 1307 | } 1308 | it { 1309 | should contain_file('ruby_bin').with({ 1310 | 'ensure' => 'link', 1311 | 'path' => '/usr/bin/ruby', 1312 | 'target' => '/usr/bin/ruby1.8', 1313 | 'require' => 'Package[ruby]' 1314 | } ) 1315 | } 1316 | it { 1317 | should contain_file('gem_bin').with({ 1318 | 'ensure' => 'link', 1319 | 'path' => '/usr/bin/gem', 1320 | 'target' => '/usr/bin/gem1.8', 1321 | 'require' => 'Package[rubygems]' 1322 | } ) 1323 | } 1324 | end 1325 | 1326 | describe 'with ruby 1.9.1 with set_system_default' do 1327 | let :params do 1328 | { 1329 | :version => '1.9.1', 1330 | :set_system_default => true 1331 | } 1332 | end 1333 | it { 1334 | should contain_package('ruby').with({ 1335 | 'ensure' => 'installed', 1336 | 'name' => 'ruby1.9.1' 1337 | }) 1338 | } 1339 | it { 1340 | should contain_file('ruby_bin').with({ 1341 | 'ensure' => 'link', 1342 | 'path' => '/usr/bin/ruby', 1343 | 'target' => '/usr/bin/ruby1.9.1', 1344 | 'require' => 'Package[ruby]' 1345 | } ) 1346 | } 1347 | it { 1348 | should contain_file('gem_bin').with({ 1349 | 'ensure' => 'link', 1350 | 'path' => '/usr/bin/gem', 1351 | 'target' => '/usr/bin/gem1.9.1', 1352 | 'require' => 'Package[rubygems]' 1353 | } ) 1354 | } 1355 | end 1356 | 1357 | describe 'with ruby 2.0 with set_system_default' do 1358 | let :params do 1359 | { 1360 | :version => '2.0', 1361 | :set_system_default => true 1362 | } 1363 | end 1364 | it { 1365 | should contain_package('ruby').with({ 1366 | 'ensure' => 'installed', 1367 | 'name' => 'ruby2.0' 1368 | }) 1369 | } 1370 | it { 1371 | should contain_file('ruby_bin').with({ 1372 | 'ensure' => 'link', 1373 | 'path' => '/usr/bin/ruby', 1374 | 'target' => '/usr/bin/ruby2.0', 1375 | 'require' => 'Package[ruby]' 1376 | } ) 1377 | } 1378 | it { 1379 | should contain_file('gem_bin').with({ 1380 | 'ensure' => 'link', 1381 | 'path' => '/usr/bin/gem', 1382 | 'target' => '/usr/bin/gem2.0', 1383 | 'require' => 'Package[rubygems]' 1384 | } ) 1385 | } 1386 | end 1387 | 1388 | describe 'with ruby 2.1 with set_system_default' do 1389 | let :params do 1390 | { 1391 | :version => '2.1', 1392 | :set_system_default => true 1393 | } 1394 | end 1395 | it { 1396 | should contain_package('ruby').with({ 1397 | 'ensure' => 'installed', 1398 | 'name' => 'ruby2.1' 1399 | }) 1400 | } 1401 | it { 1402 | should contain_file('ruby_bin').with({ 1403 | 'ensure' => 'link', 1404 | 'path' => '/usr/bin/ruby', 1405 | 'target' => '/usr/bin/ruby2.1', 1406 | 'require' => 'Package[ruby]' 1407 | } ) 1408 | } 1409 | it { 1410 | should contain_file('gem_bin').with({ 1411 | 'ensure' => 'link', 1412 | 'path' => '/usr/bin/gem', 1413 | 'target' => '/usr/bin/gem2.1', 1414 | 'require' => 'Package[rubygems]' 1415 | } ) 1416 | } 1417 | end 1418 | 1419 | end 1420 | 1421 | context 'On Ubuntu 14.04 LTS (Trusty Tahr)' do 1422 | let :facts do 1423 | { 1424 | :osfamily => 'Debian', 1425 | :operatingsystem => 'Ubuntu', 1426 | :operatingsystemrelease => '14.04' 1427 | } 1428 | end 1429 | it { should contain_class('ruby::params') } 1430 | it { 1431 | should contain_package('ruby').with({ 1432 | 'ensure' => 'installed', 1433 | 'name' => 'ruby', 1434 | }) 1435 | } 1436 | it { 1437 | should contain_package('rubygems').with({ 1438 | 'ensure' => 'installed', 1439 | 'name' => 'ruby1.9.1-full', 1440 | 'require' => 'Package[ruby]', 1441 | }) 1442 | } 1443 | it { should_not contain_package('rubygems-update') } 1444 | it { should_not contain_exec('ruby::update_rubygems') } 1445 | it { should_not contain_package('ruby-switch') } 1446 | it { should_not contain_exec('switch_ruby') } 1447 | it { should_not contain_file('ruby_bin') } 1448 | it { should_not contain_file('gem_bin') } 1449 | 1450 | describe 'with a custom ruby package' do 1451 | let :params do 1452 | { 1453 | :ruby_package => 'sparkly-ruby' 1454 | } 1455 | end 1456 | it { 1457 | should contain_package('ruby').with({ 1458 | 'ensure' => 'installed', 1459 | 'name' => 'sparkly-ruby' 1460 | }) 1461 | } 1462 | end 1463 | 1464 | describe 'with a custom rubygems package' do 1465 | let :params do 1466 | { 1467 | :rubygems_package => 'sparkly-rubygems' 1468 | } 1469 | end 1470 | it { 1471 | should contain_package('rubygems').with({ 1472 | 'name' => 'sparkly-rubygems', 1473 | }) 1474 | } 1475 | end 1476 | 1477 | describe 'when using the latest release' do 1478 | let :params do 1479 | { 1480 | :latest_release => true 1481 | } 1482 | end 1483 | it { 1484 | should contain_package('ruby').with({ 1485 | 'ensure' => 'latest' 1486 | }) 1487 | } 1488 | end 1489 | 1490 | describe 'with ruby 1.8 with switch' do 1491 | let :params do 1492 | { 1493 | :version => '1.8', 1494 | :switch => true 1495 | } 1496 | end 1497 | it { 1498 | should contain_package('ruby').with({ 1499 | 'ensure' => 'installed', 1500 | 'name' => 'ruby1.8' 1501 | }) 1502 | } 1503 | it { 1504 | should contain_file('ruby_bin').with({ 1505 | 'ensure' => 'link', 1506 | 'path' => '/usr/bin/ruby', 1507 | 'target' => '/usr/bin/ruby1.8', 1508 | 'require' => 'Package[ruby]' 1509 | } ) 1510 | } 1511 | it { 1512 | should contain_file('gem_bin').with({ 1513 | 'ensure' => 'link', 1514 | 'path' => '/usr/bin/gem', 1515 | 'target' => '/usr/bin/gem1.8', 1516 | 'require' => 'Package[rubygems]' 1517 | } ) 1518 | } 1519 | end 1520 | 1521 | describe 'with ruby 1.9.1 with switch' do 1522 | let :params do 1523 | { 1524 | :version => '1.9.1', 1525 | :switch => true 1526 | } 1527 | end 1528 | it { 1529 | should contain_package('ruby').with({ 1530 | 'ensure' => 'installed', 1531 | 'name' => 'ruby1.9.1' 1532 | }) 1533 | } 1534 | it { 1535 | should contain_file('ruby_bin').with({ 1536 | 'ensure' => 'link', 1537 | 'path' => '/usr/bin/ruby', 1538 | 'target' => '/usr/bin/ruby1.9.1', 1539 | 'require' => 'Package[ruby]' 1540 | } ) 1541 | } 1542 | it { 1543 | should contain_file('gem_bin').with({ 1544 | 'ensure' => 'link', 1545 | 'path' => '/usr/bin/gem', 1546 | 'target' => '/usr/bin/gem1.9.1', 1547 | 'require' => 'Package[rubygems]' 1548 | } ) 1549 | } 1550 | end 1551 | 1552 | describe 'with ruby 2.0 with switch' do 1553 | let :params do 1554 | { 1555 | :version => '2.0', 1556 | :switch => true 1557 | } 1558 | end 1559 | it { 1560 | should contain_package('ruby').with({ 1561 | 'ensure' => 'installed', 1562 | 'name' => 'ruby2.0' 1563 | }) 1564 | } 1565 | it { 1566 | should contain_file('ruby_bin').with({ 1567 | 'ensure' => 'link', 1568 | 'path' => '/usr/bin/ruby', 1569 | 'target' => '/usr/bin/ruby2.0', 1570 | 'require' => 'Package[ruby]' 1571 | } ) 1572 | } 1573 | it { 1574 | should contain_file('gem_bin').with({ 1575 | 'ensure' => 'link', 1576 | 'path' => '/usr/bin/gem', 1577 | 'target' => '/usr/bin/gem2.0', 1578 | 'require' => 'Package[rubygems]' 1579 | } ) 1580 | } 1581 | end 1582 | 1583 | describe 'with ruby 2.1 with switch' do 1584 | let :params do 1585 | { 1586 | :version => '2.1', 1587 | :switch => true 1588 | } 1589 | end 1590 | it { 1591 | should contain_package('ruby').with({ 1592 | 'ensure' => 'installed', 1593 | 'name' => 'ruby2.1' 1594 | }) 1595 | } 1596 | it { 1597 | should contain_file('ruby_bin').with({ 1598 | 'ensure' => 'link', 1599 | 'path' => '/usr/bin/ruby', 1600 | 'target' => '/usr/bin/ruby2.1', 1601 | 'require' => 'Package[ruby]' 1602 | } ) 1603 | } 1604 | it { 1605 | should contain_file('gem_bin').with({ 1606 | 'ensure' => 'link', 1607 | 'path' => '/usr/bin/gem', 1608 | 'target' => '/usr/bin/gem2.1', 1609 | 'require' => 'Package[rubygems]' 1610 | } ) 1611 | } 1612 | end 1613 | 1614 | describe 'with ruby 1.8 with set_system_default' do 1615 | let :params do 1616 | { 1617 | :version => '1.8', 1618 | :set_system_default => true 1619 | } 1620 | end 1621 | it { 1622 | should contain_package('ruby').with({ 1623 | 'ensure' => 'installed', 1624 | 'name' => 'ruby1.8' 1625 | }) 1626 | } 1627 | it { 1628 | should contain_file('ruby_bin').with({ 1629 | 'ensure' => 'link', 1630 | 'path' => '/usr/bin/ruby', 1631 | 'target' => '/usr/bin/ruby1.8', 1632 | 'require' => 'Package[ruby]' 1633 | } ) 1634 | } 1635 | it { 1636 | should contain_file('gem_bin').with({ 1637 | 'ensure' => 'link', 1638 | 'path' => '/usr/bin/gem', 1639 | 'target' => '/usr/bin/gem1.8', 1640 | 'require' => 'Package[rubygems]' 1641 | } ) 1642 | } 1643 | end 1644 | 1645 | describe 'with ruby 1.9.1 with set_system_default' do 1646 | let :params do 1647 | { 1648 | :version => '1.9.1', 1649 | :set_system_default => true 1650 | } 1651 | end 1652 | it { 1653 | should contain_package('ruby').with({ 1654 | 'ensure' => 'installed', 1655 | 'name' => 'ruby1.9.1' 1656 | }) 1657 | } 1658 | it { 1659 | should contain_file('ruby_bin').with({ 1660 | 'ensure' => 'link', 1661 | 'path' => '/usr/bin/ruby', 1662 | 'target' => '/usr/bin/ruby1.9.1', 1663 | 'require' => 'Package[ruby]' 1664 | } ) 1665 | } 1666 | it { 1667 | should contain_file('gem_bin').with({ 1668 | 'ensure' => 'link', 1669 | 'path' => '/usr/bin/gem', 1670 | 'target' => '/usr/bin/gem1.9.1', 1671 | 'require' => 'Package[rubygems]' 1672 | } ) 1673 | } 1674 | end 1675 | 1676 | describe 'with ruby 2.0 with set_system_default' do 1677 | let :params do 1678 | { 1679 | :version => '2.0', 1680 | :set_system_default => true 1681 | } 1682 | end 1683 | it { 1684 | should contain_package('ruby').with({ 1685 | 'ensure' => 'installed', 1686 | 'name' => 'ruby2.0' 1687 | }) 1688 | } 1689 | it { 1690 | should contain_file('ruby_bin').with({ 1691 | 'ensure' => 'link', 1692 | 'path' => '/usr/bin/ruby', 1693 | 'target' => '/usr/bin/ruby2.0', 1694 | 'require' => 'Package[ruby]' 1695 | } ) 1696 | } 1697 | it { 1698 | should contain_file('gem_bin').with({ 1699 | 'ensure' => 'link', 1700 | 'path' => '/usr/bin/gem', 1701 | 'target' => '/usr/bin/gem2.0', 1702 | 'require' => 'Package[rubygems]' 1703 | } ) 1704 | } 1705 | end 1706 | 1707 | describe 'with ruby 2.1 with set_system_default' do 1708 | let :params do 1709 | { 1710 | :version => '2.1', 1711 | :set_system_default => true 1712 | } 1713 | end 1714 | it { 1715 | should contain_package('ruby').with({ 1716 | 'ensure' => 'installed', 1717 | 'name' => 'ruby2.1' 1718 | }) 1719 | } 1720 | it { 1721 | should contain_file('ruby_bin').with({ 1722 | 'ensure' => 'link', 1723 | 'path' => '/usr/bin/ruby', 1724 | 'target' => '/usr/bin/ruby2.1', 1725 | 'require' => 'Package[ruby]' 1726 | } ) 1727 | } 1728 | it { 1729 | should contain_file('gem_bin').with({ 1730 | 'ensure' => 'link', 1731 | 'path' => '/usr/bin/gem', 1732 | 'target' => '/usr/bin/gem2.1', 1733 | 'require' => 'Package[rubygems]' 1734 | } ) 1735 | } 1736 | end 1737 | 1738 | end 1739 | 1740 | context 'On Ubuntu 18.04 LTS (Bionic Beaver)' do 1741 | let :facts do 1742 | { 1743 | :osfamily => 'Debian', 1744 | :operatingsystem => 'Ubuntu', 1745 | :operatingsystemrelease => '18.04' 1746 | } 1747 | end 1748 | it { should contain_class('ruby::params') } 1749 | it { 1750 | should contain_package('ruby').with({ 1751 | 'ensure' => 'installed', 1752 | 'name' => 'ruby-full', 1753 | }) 1754 | } 1755 | it { 1756 | should contain_package('rubygems').with({ 1757 | 'ensure' => 'installed', 1758 | 'name' => 'rubygems', 1759 | 'require' => 'Package[ruby]', 1760 | }) 1761 | } 1762 | it { should_not contain_package('rubygems-update') } 1763 | it { should_not contain_exec('ruby::update_rubygems') } 1764 | it { should_not contain_package('ruby-switch') } 1765 | it { should_not contain_exec('switch_ruby') } 1766 | it { should_not contain_file('ruby_bin') } 1767 | it { should_not contain_file('gem_bin') } 1768 | 1769 | describe 'with a custom ruby package' do 1770 | let :params do 1771 | { 1772 | :ruby_package => 'sparkly-ruby' 1773 | } 1774 | end 1775 | it { 1776 | should contain_package('ruby').with({ 1777 | 'ensure' => 'installed', 1778 | 'name' => 'sparkly-ruby' 1779 | }) 1780 | } 1781 | end 1782 | 1783 | describe 'with a custom rubygems package' do 1784 | let :params do 1785 | { 1786 | :rubygems_package => 'sparkly-rubygems' 1787 | } 1788 | end 1789 | it { 1790 | should contain_package('rubygems').with({ 1791 | 'name' => 'sparkly-rubygems', 1792 | }) 1793 | } 1794 | end 1795 | 1796 | describe 'when using the latest release' do 1797 | let :params do 1798 | { 1799 | :latest_release => true 1800 | } 1801 | end 1802 | it { 1803 | should contain_package('ruby').with({ 1804 | 'ensure' => 'latest' 1805 | }) 1806 | } 1807 | end 1808 | end 1809 | 1810 | 1811 | context 'On a Archlinux family operating system' do 1812 | let :facts do 1813 | { 1814 | :osfamily => 'Archlinux', 1815 | :operatingsystem => 'Archlinux', 1816 | } 1817 | end 1818 | it { should contain_class('ruby::params') } 1819 | it { 1820 | should contain_package('ruby').with({ 1821 | 'ensure' => 'installed', 1822 | 'name' => 'ruby', 1823 | }) 1824 | } 1825 | it { should_not contain_package('rubygems') } 1826 | it { should_not contain_package('rubygems-update') } 1827 | it { should_not contain_exec('ruby::update_rubygems') } 1828 | it { should_not contain_package('ruby-switch') } 1829 | it { should_not contain_exec('switch_ruby') } 1830 | it { should_not contain_file('ruby_bin') } 1831 | it { should_not contain_file('gem_bin') } 1832 | 1833 | describe 'when using the latest release' do 1834 | let :params do 1835 | { 1836 | :latest_release => true 1837 | } 1838 | end 1839 | it { 1840 | should contain_package('ruby').with({ 1841 | 'ensure' => 'latest' 1842 | }) 1843 | } 1844 | end 1845 | end 1846 | 1847 | context 'With an Unkown operating system' do 1848 | let :facts do 1849 | { 1850 | :osfamily => 'Unknown', 1851 | } 1852 | end 1853 | it do 1854 | expect { 1855 | should contain_class('ruby::params') 1856 | }.to raise_error(Puppet::Error, /Unsupported OS family: Unknown/) 1857 | end 1858 | end 1859 | 1860 | end 1861 | -------------------------------------------------------------------------------- /spec/defines/bundle_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'ruby::bundle', :type => :define do 3 | describe 'on RedHat based systems' do 4 | let (:facts) do 5 | { 6 | :osfamily => 'RedHat', 7 | :processorcount => '4' 8 | } 9 | end 10 | let :pre_condition do 11 | "include ruby\ninclude ruby::dev" 12 | end 13 | context 'with no parameters' do 14 | let :title do 15 | 'install' 16 | end 17 | it { 18 | should contain_exec('ruby_bundle_install').with({ 19 | 'command' => 'bundle install', 20 | 'environment' => 'RAILS_ENV=production', 21 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 22 | 'unless' => 'bundle check', 23 | 'require' => 'Package[bundler]' 24 | }) 25 | } 26 | end 27 | context 'with the install command' do 28 | let :title do 29 | 'install' 30 | end 31 | let :params do 32 | { 33 | :command => 'install', 34 | } 35 | end 36 | it { 37 | should contain_exec('ruby_bundle_install').with({ 38 | 'command' => 'bundle install', 39 | 'environment' => 'RAILS_ENV=production', 40 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 41 | 'unless' => 'bundle check', 42 | 'require' => 'Package[bundler]' 43 | }) 44 | } 45 | end 46 | context 'with the update command' do 47 | let :title do 48 | 'update' 49 | end 50 | let :params do 51 | { 52 | :command => 'update', 53 | } 54 | end 55 | it { 56 | should contain_exec('ruby_bundle_update').with({ 57 | 'command' => 'bundle update', 58 | 'environment' => 'RAILS_ENV=production', 59 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 60 | 'unless' => 'bundle outdated', 61 | 'require' => 'Package[bundler]' 62 | }) 63 | } 64 | end 65 | context 'with the install command with multicore 0' do 66 | let :title do 67 | 'install' 68 | end 69 | let :params do 70 | { 71 | :command => 'install', 72 | :multicore => '0' 73 | } 74 | end 75 | it { 76 | should contain_exec('ruby_bundle_install').with({ 77 | 'command' => 'bundle install --jobs 4', 78 | 'environment' => 'RAILS_ENV=production', 79 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 80 | 'unless' => 'bundle check', 81 | 'require' => 'Package[bundler]' 82 | }) 83 | } 84 | end 85 | context 'with the install command with multicore less than max' do 86 | let :title do 87 | 'install' 88 | end 89 | let :params do 90 | { 91 | :command => 'install', 92 | :multicore => '3' 93 | } 94 | end 95 | it { 96 | should contain_exec('ruby_bundle_install').with({ 97 | 'command' => 'bundle install --jobs 3', 98 | 'environment' => 'RAILS_ENV=production', 99 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 100 | 'unless' => 'bundle check', 101 | 'require' => 'Package[bundler]' 102 | }) 103 | } 104 | end 105 | context 'with the install command with multicore greater than max' do 106 | let :title do 107 | 'install' 108 | end 109 | let :params do 110 | { 111 | :command => 'install', 112 | :multicore => '17' 113 | } 114 | end 115 | it { 116 | should contain_exec('ruby_bundle_install').with({ 117 | 'command' => 'bundle install --jobs 4', 118 | 'environment' => 'RAILS_ENV=production', 119 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 120 | 'unless' => 'bundle check', 121 | 'require' => 'Package[bundler]' 122 | }) 123 | } 124 | end 125 | context 'with the update command with multicore 0' do 126 | let :title do 127 | 'update' 128 | end 129 | let :params do 130 | { 131 | :command => 'update', 132 | :multicore => '0' 133 | } 134 | end 135 | it { 136 | should contain_exec('ruby_bundle_update').with({ 137 | 'command' => 'bundle update --jobs 4', 138 | 'environment' => 'RAILS_ENV=production', 139 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 140 | 'unless' => 'bundle outdated', 141 | 'require' => 'Package[bundler]' 142 | }) 143 | } 144 | end 145 | context 'with the update command with multicore less than max' do 146 | let :title do 147 | 'update' 148 | end 149 | let :params do 150 | { 151 | :command => 'update', 152 | :multicore => '3' 153 | } 154 | end 155 | it { 156 | should contain_exec('ruby_bundle_update').with({ 157 | 'command' => 'bundle update --jobs 3', 158 | 'environment' => 'RAILS_ENV=production', 159 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 160 | 'unless' => 'bundle outdated', 161 | 'require' => 'Package[bundler]' 162 | }) 163 | } 164 | end 165 | context 'with the update command with multicore greater than max' do 166 | let :title do 167 | 'update' 168 | end 169 | let :params do 170 | { 171 | :command => 'update', 172 | :multicore => '17' 173 | } 174 | end 175 | it { 176 | should contain_exec('ruby_bundle_update').with({ 177 | 'command' => 'bundle update --jobs 4', 178 | 'environment' => 'RAILS_ENV=production', 179 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 180 | 'unless' => 'bundle outdated', 181 | 'require' => 'Package[bundler]' 182 | }) 183 | } 184 | end 185 | context 'with the install command with multicore 0' do 186 | let :title do 187 | 'install' 188 | end 189 | let :params do 190 | { 191 | :command => 'install', 192 | :multicore => '0' 193 | } 194 | end 195 | it { 196 | should contain_exec('ruby_bundle_install').with({ 197 | 'command' => 'bundle install --jobs 4', 198 | 'environment' => 'RAILS_ENV=production', 199 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 200 | 'unless' => 'bundle check', 201 | 'require' => 'Package[bundler]' 202 | }) 203 | } 204 | end 205 | context 'with the install command with multicore less than max' do 206 | let :title do 207 | 'install' 208 | end 209 | let :params do 210 | { 211 | :command => 'install', 212 | :multicore => '3' 213 | } 214 | end 215 | it { 216 | should contain_exec('ruby_bundle_install').with({ 217 | 'command' => 'bundle install --jobs 3', 218 | 'environment' => 'RAILS_ENV=production', 219 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 220 | 'unless' => 'bundle check', 221 | 'require' => 'Package[bundler]' 222 | }) 223 | } 224 | end 225 | context 'with the install command with multicore greater than max' do 226 | let :title do 227 | 'install' 228 | end 229 | let :params do 230 | { 231 | :command => 'install', 232 | :multicore => '17' 233 | } 234 | end 235 | it { 236 | should contain_exec('ruby_bundle_install').with({ 237 | 'command' => 'bundle install --jobs 4', 238 | 'environment' => 'RAILS_ENV=production', 239 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 240 | 'unless' => 'bundle check', 241 | 'require' => 'Package[bundler]' 242 | }) 243 | } 244 | end 245 | context 'with the update command with multicore 0' do 246 | let :title do 247 | 'update' 248 | end 249 | let :params do 250 | { 251 | :command => 'update', 252 | :multicore => '0' 253 | } 254 | end 255 | it { 256 | should contain_exec('ruby_bundle_update').with({ 257 | 'command' => 'bundle update --jobs 4', 258 | 'environment' => 'RAILS_ENV=production', 259 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 260 | 'unless' => 'bundle outdated', 261 | 'require' => 'Package[bundler]' 262 | }) 263 | } 264 | end 265 | context 'with the update command with multicore less than max' do 266 | let :title do 267 | 'update' 268 | end 269 | let :params do 270 | { 271 | :command => 'update', 272 | :multicore => '3' 273 | } 274 | end 275 | it { 276 | should contain_exec('ruby_bundle_update').with({ 277 | 'command' => 'bundle update --jobs 3', 278 | 'environment' => 'RAILS_ENV=production', 279 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 280 | 'unless' => 'bundle outdated', 281 | 'require' => 'Package[bundler]' 282 | }) 283 | } 284 | end 285 | context 'with the update command with multicore greater than max' do 286 | let :title do 287 | 'update' 288 | end 289 | let :params do 290 | { 291 | :command => 'update', 292 | :multicore => '17' 293 | } 294 | end 295 | it { 296 | should contain_exec('ruby_bundle_update').with({ 297 | 'command' => 'bundle update --jobs 4', 298 | 'environment' => 'RAILS_ENV=production', 299 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 300 | 'unless' => 'bundle outdated', 301 | 'require' => 'Package[bundler]' 302 | }) 303 | } 304 | end 305 | context 'when using the install command with options' do 306 | let :title do 307 | 'install_with_options' 308 | end 309 | let :params do 310 | { 311 | :command => 'install', 312 | :option => '--clean --deployment --gemfile=magical --path=/path/to/wherever --no-prune --without test development foo baa' 313 | } 314 | end 315 | it { 316 | should contain_exec('ruby_bundle_install_with_options').with({ 317 | 'command' => 'bundle install --clean --deployment --gemfile=magical --path=/path/to/wherever --no-prune --without test development foo baa', 318 | 'environment' => 'RAILS_ENV=production', 319 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 320 | 'unless' => 'bundle check', 321 | 'require' => 'Package[bundler]' 322 | }) 323 | } 324 | end 325 | context 'when using the update command with options' do 326 | let :title do 327 | 'update_with_options' 328 | end 329 | let :params do 330 | { 331 | :command => 'update', 332 | :option => '--local --source=http://some.gem.repo.org' 333 | } 334 | end 335 | it { 336 | should contain_exec('ruby_bundle_update_with_options').with({ 337 | 'command' => 'bundle update --local --source=http://some.gem.repo.org', 338 | 'environment' => 'RAILS_ENV=production', 339 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 340 | 'unless' => 'bundle outdated --local --source=http://some.gem.repo.org', 341 | 'require' => 'Package[bundler]' 342 | }) 343 | } 344 | end 345 | context 'when using the exec command with options' do 346 | let :title do 347 | 'exec_with_options' 348 | end 349 | let :params do 350 | { 351 | :command => 'exec', 352 | :option => 'echo foo >> test', 353 | :unless => 'grep foo test' 354 | } 355 | end 356 | it { 357 | should contain_exec('ruby_bundle_exec_with_options').with({ 358 | 'command' => 'bundle exec echo foo >> test', 359 | 'environment' => 'RAILS_ENV=production', 360 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 361 | 'unless' => 'grep foo test', 362 | 'require' => 'Package[bundler]' 363 | }) 364 | } 365 | end 366 | context 'when using the exec command without options' do 367 | let :title do 368 | 'exec_without_options' 369 | end 370 | let :params do 371 | { 372 | :command => 'exec', 373 | } 374 | end 375 | it do 376 | expect { 377 | should contain_exec('ruby_bundle_exec_without_options') 378 | }.to raise_error(Puppet::Error, /When given the exec command the ruby::bundle resource requires the command to be executed to be passed to the option parameter/) 379 | end 380 | end 381 | context 'with more paths' do 382 | let :title do 383 | 'install' 384 | end 385 | let :params do 386 | { 387 | :command => 'install', 388 | :path => ['/usr/share/foo/bin','/path/to/sbin'] 389 | } 390 | end 391 | it { 392 | should contain_exec('ruby_bundle_install').with({ 393 | 'path' => ['/usr/share/foo/bin', '/path/to/sbin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 394 | }) 395 | } 396 | end 397 | context 'with more environment variables' do 398 | let :title do 399 | 'install' 400 | end 401 | let :params do 402 | { 403 | :command => 'install', 404 | :environment => ['SHIELDS=up','PHASERS=stun'] 405 | } 406 | end 407 | it { 408 | should contain_exec('ruby_bundle_install').with({ 409 | 'environment' => ['SHIELDS=up', 'PHASERS=stun', 'RAILS_ENV=production'], 410 | }) 411 | } 412 | end 413 | context 'with a custom Rails environment' do 414 | let :title do 415 | 'install' 416 | end 417 | let :params do 418 | { 419 | :command => 'install', 420 | :rails_env => 'test' 421 | } 422 | end 423 | it { 424 | should contain_exec('ruby_bundle_install').with({ 425 | 'environment' => 'RAILS_ENV=test', 426 | }) 427 | } 428 | end 429 | context 'that all parameters pass through' do 430 | let :title do 431 | 'install' 432 | end 433 | let :params do 434 | { 435 | :command => 'install', 436 | :creates => '/path/to/file', 437 | :cwd => '/path/to/dir', 438 | :user => 'nobody', 439 | :group => 'anyone', 440 | :logoutput => true, 441 | :onlyif => 'confused', 442 | :refresh => true, 443 | :refreshonly => true, 444 | :timeout => '300', 445 | :tries => '2', 446 | :try_sleep => '30' 447 | } 448 | end 449 | it { 450 | should contain_exec('ruby_bundle_install').with({ 451 | 'command' => 'bundle install', 452 | 'creates' => '/path/to/file', 453 | 'cwd' => '/path/to/dir', 454 | 'user' => 'nobody', 455 | 'group' => 'anyone', 456 | 'logoutput' => true, 457 | 'onlyif' => 'confused', 458 | 'refresh' => true, 459 | 'refreshonly' => true, 460 | 'timeout' => '300', 461 | 'tries' => '2', 462 | 'try_sleep' => '30' 463 | }) 464 | } 465 | end 466 | end 467 | describe 'on Amazon based systems' do 468 | let (:facts) do 469 | { 470 | :osfamily => 'Amazon' 471 | } 472 | end 473 | let :pre_condition do 474 | "include ruby\ninclude ruby::dev" 475 | end 476 | context 'with no parameters' do 477 | let :title do 478 | 'install' 479 | end 480 | it { 481 | should contain_exec('ruby_bundle_install').with({ 482 | 'command' => 'bundle install', 483 | 'environment' => 'RAILS_ENV=production', 484 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 485 | 'unless' => 'bundle check', 486 | 'require' => 'Package[bundler]' 487 | }) 488 | } 489 | end 490 | end 491 | describe 'on Debian based systems' do 492 | let (:facts) do 493 | { 494 | :osfamily => 'Debian' 495 | } 496 | end 497 | let :pre_condition do 498 | "include ruby\ninclude ruby::dev" 499 | end 500 | context 'with no parameters' do 501 | let :title do 502 | 'install' 503 | end 504 | it { 505 | should contain_exec('ruby_bundle_install').with({ 506 | 'command' => 'bundle install', 507 | 'environment' => 'RAILS_ENV=production', 508 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 509 | 'unless' => 'bundle check', 510 | 'require' => 'Package[bundler]' 511 | }) 512 | } 513 | end 514 | end 515 | describe 'on an Unknown OS' do 516 | let :facts do 517 | { 518 | :osfamily => 'Unknown' 519 | } 520 | end 521 | let :title do 522 | 'test' 523 | end 524 | it do 525 | expect { 526 | should contain_class('puppet::params') 527 | }.to raise_error(Puppet::Error, /Unsupported OS family: Unknown/) 528 | end 529 | end 530 | end -------------------------------------------------------------------------------- /spec/defines/rake_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'ruby::rake', :type => :define do 3 | describe 'on RedHat based systems' do 4 | let (:facts) do 5 | { 6 | :osfamily => 'RedHat', 7 | } 8 | end 9 | let :pre_condition do 10 | "include ruby\ninclude ruby::dev" 11 | end 12 | context 'with minimum parameters' do 13 | let :title do 14 | 'db_setup' 15 | end 16 | let :params do 17 | { 18 | :task => 'db:setup' 19 | } 20 | end 21 | it { 22 | should contain_exec('ruby_rake_db_setup').with({ 23 | 'command' => 'rake db:setup', 24 | 'environment' => 'RAILS_ENV=production', 25 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 26 | 'require' => 'Package[rake]' 27 | }) 28 | } 29 | end 30 | context 'with more paths' do 31 | let :title do 32 | 'db_setup' 33 | end 34 | let :params do 35 | { 36 | :task => 'db:setup', 37 | :path => ['/usr/share/foo/bin','/path/to/sbin'] 38 | } 39 | end 40 | it { 41 | should contain_exec('ruby_rake_db_setup').with({ 42 | 'path' => ['/usr/share/foo/bin', '/path/to/sbin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 43 | }) 44 | } 45 | end 46 | context 'with more environment variables' do 47 | let :title do 48 | 'db_setup' 49 | end 50 | let :params do 51 | { 52 | :task => 'db:setup', 53 | :environment => ['SHIELDS=up','PHASERS=stun'] 54 | } 55 | end 56 | it { 57 | should contain_exec('ruby_rake_db_setup').with({ 58 | 'environment' => ['SHIELDS=up', 'PHASERS=stun', 'RAILS_ENV=production'], 59 | }) 60 | } 61 | end 62 | context 'with a custom Rails environment' do 63 | let :title do 64 | 'db_setup' 65 | end 66 | let :params do 67 | { 68 | :task => 'db:setup', 69 | :rails_env => 'test' 70 | } 71 | end 72 | it { 73 | should contain_exec('ruby_rake_db_setup').with({ 74 | 'environment' => 'RAILS_ENV=test', 75 | }) 76 | } 77 | end 78 | context 'checking parameter passthrough' do 79 | let :title do 80 | 'db_setup' 81 | end 82 | let :params do 83 | { 84 | :task => 'db:setup', 85 | :creates => '/path/to/file', 86 | :cwd => '/path/to/dir', 87 | :user => 'nobody', 88 | :group => 'anybody', 89 | :logoutput => true, 90 | :onlyif => 'confused', 91 | :refresh => true, 92 | :refreshonly => true, 93 | :timeout => '300', 94 | :tries => '2', 95 | :try_sleep => '30', 96 | :unless => 'not true' 97 | } 98 | end 99 | it { 100 | should_not contain_ruby__bundle('ruby_rake_db_setup') 101 | } 102 | it { 103 | should contain_exec('ruby_rake_db_setup').with({ 104 | 'command' => 'rake db:setup', 105 | 'creates' => '/path/to/file', 106 | 'cwd' => '/path/to/dir', 107 | 'user' => 'nobody', 108 | 'group' => 'anybody', 109 | 'logoutput' => true, 110 | 'onlyif' => 'confused', 111 | 'refresh' => true, 112 | 'refreshonly' => true, 113 | 'timeout' => '300', 114 | 'tries' => '2', 115 | 'try_sleep' => '30', 116 | 'unless' => 'not true' 117 | }) 118 | } 119 | end 120 | context 'checking parameter passthrough when using the bundler wrapper' do 121 | let :title do 122 | 'db_setup' 123 | end 124 | let :params do 125 | { 126 | :task => 'db:setup', 127 | :bundle => true, 128 | :rails_env => 'test', 129 | :creates => '/path/to/file', 130 | :cwd => '/path/to/dir', 131 | :environment => 'test', 132 | :user => 'nobody', 133 | :group => 'anybody', 134 | :logoutput => true, 135 | :onlyif => 'confused', 136 | :path => ['/opt/app/bin','/usr/share/path'], 137 | :refresh => true, 138 | :refreshonly => true, 139 | :timeout => '300', 140 | :tries => '2', 141 | :try_sleep => '30', 142 | :unless => 'not true' 143 | } 144 | end 145 | it { 146 | should_not contain_exec('ruby_rake_db_setup') 147 | } 148 | it { 149 | should contain_ruby__bundle('ruby_rake_db_setup').with({ 150 | 'command' => 'exec', 151 | 'option' => 'rake db:setup', 152 | 'rails_env' => 'test', 153 | 'creates' => '/path/to/file', 154 | 'cwd' => '/path/to/dir', 155 | 'environment' => 'test', 156 | 'user' => 'nobody', 157 | 'group' => 'anybody', 158 | 'logoutput' => true, 159 | 'onlyif' => 'confused', 160 | 'path' => ['/opt/app/bin','/usr/share/path'], 161 | 'refresh' => true, 162 | 'refreshonly' => true, 163 | 'timeout' => '300', 164 | 'tries' => '2', 165 | 'try_sleep' => '30', 166 | 'unless' => 'not true' 167 | }) 168 | } 169 | end 170 | end 171 | describe 'on Amazon based systems' do 172 | let (:facts) do 173 | { 174 | :osfamily => 'Amazon', 175 | } 176 | end 177 | let :pre_condition do 178 | "include ruby\ninclude ruby::dev" 179 | end 180 | context 'with minimum parameters' do 181 | let :title do 182 | 'db_setup' 183 | end 184 | let :params do 185 | { 186 | :task => 'db:setup' 187 | } 188 | end 189 | it { 190 | should contain_exec('ruby_rake_db_setup').with({ 191 | 'command' => 'rake db:setup', 192 | 'environment' => 'RAILS_ENV=production', 193 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 194 | 'require' => 'Package[rake]' 195 | }) 196 | } 197 | end 198 | end 199 | describe 'on Debian based systems' do 200 | let (:facts) do 201 | { 202 | :osfamily => 'Debian', 203 | } 204 | end 205 | let :pre_condition do 206 | "include ruby\ninclude ruby::dev" 207 | end 208 | context 'with no parameters' do 209 | let :title do 210 | 'db_setup' 211 | end 212 | let :params do 213 | { 214 | :task => 'db:setup' 215 | } 216 | end 217 | it { 218 | should contain_exec('ruby_rake_db_setup').with({ 219 | 'command' => 'rake db:setup', 220 | 'environment' => 'RAILS_ENV=production', 221 | 'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'], 222 | 'require' => 'Package[rake]' 223 | }) 224 | } 225 | end 226 | end 227 | describe 'on an Unknown OS' do 228 | let :facts do 229 | { 230 | :osfamily => 'Unknown', 231 | } 232 | end 233 | let :title do 234 | 'test' 235 | end 236 | let :params do 237 | { 238 | :task => 'db:setup' 239 | } 240 | end 241 | it do 242 | expect { 243 | should contain_class('puppet::params') 244 | }.to raise_error(Puppet::Error, /Unsupported OS family: Unknown/) 245 | end 246 | end 247 | end 248 | -------------------------------------------------------------------------------- /spec/spec.opts: -------------------------------------------------------------------------------- 1 | --format s 2 | --colour 3 | --loadby mtime 4 | --backtrace 5 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | 3 | RSpec.configure do |config| 4 | config.hiera_config = 'spec/fixtures/hiera/hiera.yaml' 5 | config.before :each do 6 | # Ensure that we don't accidentally cache facts and environment between 7 | # test cases. This requires each example group to explicitly load the 8 | # facts being exercised with something like 9 | # Facter.collection.loader.load(:ipaddress) 10 | Facter.clear 11 | Facter.clear_messages 12 | end 13 | config.default_facts = { 14 | :environment => 'rp_env', 15 | :operatingsystemmajrelease => '6', 16 | :operatingsystemrelease => '6.1', 17 | :operatingsystem => 'RedHat', 18 | } 19 | end 20 | -------------------------------------------------------------------------------- /spec/spec_helper_system.rb: -------------------------------------------------------------------------------- 1 | require 'rspec-system/spec_helper' 2 | require 'rspec-system-puppet/helpers' 3 | require 'rspec-system-serverspec/helpers' 4 | include Serverspec::Helper::RSpecSystem 5 | include Serverspec::Helper::DetectOS 6 | include RSpecSystemPuppet::Helpers 7 | 8 | RSpec.configure do |c| 9 | # Project root 10 | proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) 11 | 12 | # Enable colour 13 | c.tty = true 14 | 15 | c.include RSpecSystemPuppet::Helpers 16 | 17 | # This is where we 'setup' the nodes before running our tests 18 | c.before :suite do 19 | # Install puppet 20 | puppet_install 21 | 22 | # Install modules and dependencies 23 | puppet_module_install(:source => proj_root, :module_name => 'ruby') 24 | 25 | # Install the appropriate version of puppetlabs-stdlib 26 | stdlib_ver = '4.6.0' 27 | 28 | shell("puppet module install puppetlabs-stdlib --version #{stdlib_ver}") 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /templates/gemrc.yaml.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Puppet 2 | # Any modifications will be overwritten on the next run 3 | <%- if @sources and ! @sources.empty? -%> 4 | :sources: 5 | - <%= Array(@sources).join("\n - ") %> 6 | <%- end -%> 7 | <%- unless @update_sources.nil? -%> 8 | :update_sources: <%= @update_sources %> 9 | <%- end -%> 10 | <%- unless @verbose.nil? -%> 11 | :verbose: <%= @verbose %> 12 | <%- end -%> 13 | <%- unless @backtrace.nil? -%> 14 | :backtrace: <%= @backtrace %> 15 | <%- end -%> 16 | <%- if @gempath -%> 17 | :gempath: <%= Array(@gempath).join(':') %> 18 | <%- end -%> 19 | <%- unless @disable_default_gem_server.nil? -%> 20 | :disable_default_gem_server: <%= @disable_default_gem_server %> 21 | <%- end -%> 22 | <%- if @gem_command and ! @gem_command.empty? -%> 23 | <%- @gem_command.each do |command,options| -%> 24 | <%= command %>: --<%= Array(options).join(' --') %> 25 | <%- end -%> 26 | <%- end -%> 27 | -------------------------------------------------------------------------------- /templates/ruby.sh.erb: -------------------------------------------------------------------------------- 1 | # Set environemnt variables for Ruby as per 2 | # http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning 3 | # This file is managed by Puppet, any changes may be overwritten 4 | <% if @gc_malloc_limit -%> 5 | export RUBY_GC_MALLOC_LIMIT=<%= @gc_malloc_limit %> 6 | <% end -%> 7 | <% if @heap_free_min -%> 8 | export RUBY_HEAP_FREE_MIN=<%= @heap_free_min %> 9 | <% end -%> 10 | <% if @heap_slots_growth_factor -%> 11 | export RUBY_HEAP_SLOTS_GROWTH_FACTOR=<%= @heap_slots_growth_factor %> 12 | <% end -%> 13 | <% if @heap_min_slots -%> 14 | export RUBY_HEAP_MIN_SLOTS=<%= @heap_min_slots %> 15 | <% end -%> 16 | <% if @heap_slots_increment -%> 17 | export RUBY_HEAP_SLOTS_INCREMENT=<%= @heap_slots_increment %> 18 | <% end -%> 19 | -------------------------------------------------------------------------------- /tests/dev.pp: -------------------------------------------------------------------------------- 1 | include ::ruby 2 | include ::ruby::dev 3 | -------------------------------------------------------------------------------- /tests/init.pp: -------------------------------------------------------------------------------- 1 | include ::ruby 2 | -------------------------------------------------------------------------------- /tests/params.pp: -------------------------------------------------------------------------------- 1 | include ::ruby::params 2 | -------------------------------------------------------------------------------- /tests/ruby1.8.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '1.8', 3 | } 4 | -------------------------------------------------------------------------------- /tests/ruby1.9.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '1.9', 3 | set_system_default => true, 4 | } 5 | -------------------------------------------------------------------------------- /tests/ruby1.9_switch.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '1.9.3', 3 | latest_release => true, 4 | rubygems_update => true, 5 | } 6 | include ::ruby::dev 7 | -------------------------------------------------------------------------------- /tests/ruby2.0.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '2.0', 3 | set_system_default => true, 4 | } 5 | -------------------------------------------------------------------------------- /tests/ruby2.1.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '2.1', 3 | set_system_default => true, 4 | } 5 | -------------------------------------------------------------------------------- /tests/ruby2_switch.pp: -------------------------------------------------------------------------------- 1 | class { '::ruby': 2 | version => '2.0.0', 3 | latest_release => true, 4 | rubygems_update => true, 5 | } 6 | include ::ruby::dev 7 | --------------------------------------------------------------------------------