Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring bundler version; add a test-kitchen test #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lock
.kitchen
29 changes: 29 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
driver:
name: vagrant
customize:
cpus: 2
memory: 1024
cpuexecutioncap: 75

provisioner:
name: chef_solo

platforms:
- name: ubuntu-12.04

suites:
- name: testkitchen_ruby_ng_cookbook
run_list:
- recipe[ruby-ng_test]
- recipe[minitest-handler]
attributes:
minitest:
recipes:
- ruby-ng_test::default
ruby-ng:
ruby_version: 2.1
# 1.9.8 is the newest version as of 05/13/2015, but we are testing if we can install
# a specific older version.
bundler_version: 1.9.7

8 changes: 8 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source 'https://api.berkshelf.com'

metadata

group :integration do
cookbook 'minitest-handler'
cookbook 'ruby-ng_test', path: 'test/cookbooks/ruby-ng_test'
end
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

group :integration do
gem 'berkshelf'
gem 'test-kitchen', '~> 1.3'
gem 'kitchen-vagrant'
end
5 changes: 5 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
default['ruby-ng']['experimental'] = false
default['ruby-ng']['ruby_version'] = '2.1'

# If this is set to "latest", Bundler is upgraded to the latest version. If this is not set,
# the existing (potentially outdated) version of Bundler is kept.
default['ruby-ng']['bundler_version'] = 'latest'

7 changes: 7 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@

package "ruby#{node['ruby-ng']['ruby_version']}"

bundler_version = node['ruby-ng']['bundler_version']

gem_package 'bundler' do
gem_binary '/usr/bin/gem'
options '-n /usr/bin'
if bundler_version == 'latest'
action :upgrade
elsif bundler_version
version bundler_version
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative 'helpers'

describe_recipe "ruby-ng::default" do
include Helpers::RubyNgTests

it 'Installs the ruby<version> package' do
package("ruby#{node['ruby-ng']['ruby_version']}").must_be_installed
end

# This test requires that node['ruby-ng']['bundler_version'] is set to a specific value, not to
# "latest".
it 'Installs the correct version of the bundler gem' do
cmd = 'gem list bundler'
gem_list_bundler_output = shell_out!(cmd).stdout
bundler_version = node['ruby-ng']['bundler_version']
assert(
gem_list_bundler_output.include?("bundler (#{bundler_version})"),
"Expected bundler version #{bundler_version} " \
"to be the only version reported in the results of command '#{cmd}'")
end
end

describe_recipe "ruby-ng::dev" do
it 'Installs the ruby<version>-dev package' do
package("ruby#{node['ruby-ng']['ruby_version']}-dev").must_be_installed
end

it 'Installs the build-essential package' do
package('build-essential').must_be_installed
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Helpers
module RubyNgTests
require 'chef/mixin/shell_out'

include Chef::Mixin::ShellOut
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources
end
end

6 changes: 6 additions & 0 deletions test/cookbooks/ruby-ng_test/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name 'ruby-ng_test'
description 'This cookbook is used with test-kitchen to test the parent cookbook, ruby-ng'
version '0.1.0'

depends 'ruby-ng'

2 changes: 2 additions & 0 deletions test/cookbooks/ruby-ng_test/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include_recipe 'ruby-ng'
include_recipe 'ruby-ng::dev'