From 8ea3878d85561aa2758bba6d85c7f66e395147dd Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:08:08 -0700 Subject: [PATCH 01/11] Update Gemfile dependencies. --- Gemfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index de5c230b..f5768d9c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,16 @@ source "https://rubygems.org" -gem 'rake' -gem 'foodcritic' +gem "berkshelf", "~> 3.0.0.beta7" +gem "chefspec" +gem "emeril" +gem "foodcritic", "~> 3.0" +gem "rake" group :development do - gem 'emeril' + gem "guard-rspec" end group :integration do - gem 'berkshelf' - gem 'test-kitchen', '~> 1.0.0.alpha.6' - gem 'kitchen-vagrant' + gem "test-kitchen" + gem "kitchen-vagrant" end From 4131f6d1c2516122699863c890ad477d5f722119 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:08:27 -0700 Subject: [PATCH 02/11] Add unit tests to Rakefile. --- .rspec | 3 +++ Rakefile | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..ba746146 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--default_path test/unit +--color +--format documentation diff --git a/Rakefile b/Rakefile index 619e75e5..3b9aa5c9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,4 @@ #!/usr/bin/env rake -require 'foodcritic' begin require 'emeril/rake' @@ -7,6 +6,12 @@ rescue LoadError puts ">>>>> Emeril gem not loaded, omitting tasks" unless ENV['CI'] end +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:unit) do |t| + t.pattern = ["test/unit/**/*_spec.rb"] +end + +require 'foodcritic' FoodCritic::Rake::LintTask.new do |t| t.options = { :fail_tags => ['any'] } end @@ -18,4 +23,4 @@ rescue LoadError puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] end -task :default => [:foodcritic] +task :default => [:foodcritic, :unit] From 79562bb42815db59dce2fa4d6d23beb5b703bbe1 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:08:43 -0700 Subject: [PATCH 03/11] Add Guardfile. --- Guardfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Guardfile diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..538316c3 --- /dev/null +++ b/Guardfile @@ -0,0 +1,5 @@ +guard :rspec, spec_paths: ["test/unit"] do + watch(%r{^test/unit/.+_spec\.rb$}) + watch(%r{^(libraries|providers|recipes|resources)/(.+)\.rb$}) { |m| "test/unit/#{m[1]}/#{m[2]}_spec.rb" } + watch("test/unit/spec_helper.rb") { "test/unit" } +end From 0cf399a39e6262bd090bd54679bb15fec096fb74 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:09:00 -0700 Subject: [PATCH 04/11] Add spec coverage for rbenv_ruby resource. --- test/unit/resources/ruby_spec.rb | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/unit/resources/ruby_spec.rb diff --git a/test/unit/resources/ruby_spec.rb b/test/unit/resources/ruby_spec.rb new file mode 100644 index 00000000..48d488f9 --- /dev/null +++ b/test/unit/resources/ruby_spec.rb @@ -0,0 +1,62 @@ +require "chef/resource/lwrp_base" + +unless Chef::Resource.const_defined?("RbenvRuby") + Chef::Resource::LWRPBase.build_from_file( + "rbenv", + File.join(File.dirname(__FILE__), %w{.. .. .. resources ruby.rb}), + nil + ) +end + +describe Chef::Resource::RbenvRuby do + + let(:resource) { described_class.new("antruby") } + + it "sets the default attribute to definition" do + expect(resource.definition).to eq("antruby") + end + + it "attribute definition_file defaults to nil" do + expect(resource.definition_file).to be_nil + end + + it "attribute definition_file takes a String value" do + resource.definition_file("/blah/blah/rubay") + expect(resource.definition_file).to eq("/blah/blah/rubay") + end + + it "attribute root_path defaults to nil" do + expect(resource.root_path).to be_nil + end + + it "attribute root_path takes a String value" do + resource.root_path("/rootness/path") + expect(resource.root_path).to eq("/rootness/path") + end + + it "attribute user defaults to nil" do + expect(resource.user).to be_nil + end + + it "attribute user takes a String value" do + resource.user("curious_george") + expect(resource.user).to eq("curious_george") + end + + it "action defaults to :install" do + expect(resource.action).to eq(:install) + end + + it "actions include reinstall" do + expect(resource.allowed_actions).to include(:reinstall) + end + + it "#to_s includes user if provided" do + resource.user("molly") + expect(resource.to_s).to eq("rbenv_ruby[antruby] (molly)") + end + + it "#to_s includes system label if user is not provided" do + expect(resource.to_s).to eq("rbenv_ruby[antruby] (system)") + end +end From 8169aa3fa266bcaa0b17f30464a8d2db5ebf0a8e Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:16:53 -0700 Subject: [PATCH 05/11] Add spec coverage for rbenv_global resource. --- test/unit/resources/global_spec.rb | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/unit/resources/global_spec.rb diff --git a/test/unit/resources/global_spec.rb b/test/unit/resources/global_spec.rb new file mode 100644 index 00000000..f8efa51d --- /dev/null +++ b/test/unit/resources/global_spec.rb @@ -0,0 +1,49 @@ +require "chef/resource/lwrp_base" + +unless Chef::Resource.const_defined?("RbenvGlobal") + Chef::Resource::LWRPBase.build_from_file( + "rbenv", + File.join(File.dirname(__FILE__), %w{.. .. .. resources global.rb}), + nil + ) +end + +describe Chef::Resource::RbenvGlobal do + + let(:resource) { described_class.new("antruby") } + + it "sets the default attribute to rbenv_version" do + expect(resource.rbenv_version).to eq("antruby") + end + + it "attribute user defaults to nil" do + expect(resource.user).to be_nil + end + + it "attribute user takes a String value" do + resource.user("casper") + expect(resource.user).to eq("casper") + end + + it "attribute root_path defaults to nil" do + expect(resource.root_path).to be_nil + end + + it "attribute root_path takes a String value" do + resource.root_path("C:\\wintowne") + expect(resource.root_path).to eq("C:\\wintowne") + end + + it "action defaults to :create" do + expect(resource.action).to eq(:create) + end + + it "#to_s includes user if provided" do + resource.user("molly") + expect(resource.to_s).to eq("rbenv_global[antruby] (molly)") + end + + it "#to_s includes system label if user is not provided" do + expect(resource.to_s).to eq("rbenv_global[antruby] (system)") + end +end From f2a6ece209cfd63f21eec547d3a1e3b07fa27135 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:38:19 -0700 Subject: [PATCH 06/11] Refactor spec description in ruby_spec. --- test/unit/resources/ruby_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/resources/ruby_spec.rb b/test/unit/resources/ruby_spec.rb index 48d488f9..6df9a551 100644 --- a/test/unit/resources/ruby_spec.rb +++ b/test/unit/resources/ruby_spec.rb @@ -47,7 +47,7 @@ expect(resource.action).to eq(:install) end - it "actions include reinstall" do + it "actions include :reinstall" do expect(resource.allowed_actions).to include(:reinstall) end From c3afd146eda51bedbd01906fc8ad7c77d70b26dc Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 13:38:45 -0700 Subject: [PATCH 07/11] Add spec coverage for rbenv_gem resource. --- test/unit/resources/gem_spec.rb | 118 ++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 test/unit/resources/gem_spec.rb diff --git a/test/unit/resources/gem_spec.rb b/test/unit/resources/gem_spec.rb new file mode 100644 index 00000000..f28e3157 --- /dev/null +++ b/test/unit/resources/gem_spec.rb @@ -0,0 +1,118 @@ +require "chef/resource/lwrp_base" +require "chef/provider/package/rubygems" +require_relative "../../../libraries/chef_rbenv_mixin" +require_relative "../../../libraries/chef_provider_package_rbenvrubygems" + +unless Chef::Resource.const_defined?("RbenvGem") + Chef::Resource::LWRPBase.build_from_file( + "rbenv", + File.join(File.dirname(__FILE__), %w{.. .. .. resources gem.rb}), + nil + ) +end + +describe Chef::Resource::RbenvGem do + + let(:resource) { described_class.new("creamcorn") } + + it "sets the default attribute to package_name" do + expect(resource.package_name).to eq("creamcorn") + end + + it "attribute rbenv_version defaults to global" do + expect(resource.rbenv_version).to eq("global") + end + + it "attribute rbenv_version takes a String value" do + resource.rbenv_version("nextruby") + expect(resource.rbenv_version).to eq("nextruby") + end + + it "attribute version defaults to nil" do + expect(resource.version).to be_nil + end + + it "attribute version takes a String value" do + resource.version("1.0.99") + expect(resource.version).to eq("1.0.99") + end + + it "attribute response_file defaults to nil" do + expect(resource.response_file).to be_nil + end + + it "attribute response_file takes a String value" do + resource.response_file("/dont/think/so") + expect(resource.response_file).to eq("/dont/think/so") + end + + it "attribute source defaults to nil" do + expect(resource.source).to be_nil + end + + it "attribute source takes a String value" do + resource.source("outthere") + expect(resource.source).to eq("outthere") + end + + it "attribute options defaults to nil" do + expect(resource.options).to be_nil + end + + it "attribute options takes a String value" do + resource.options("--no-rdoc") + expect(resource.options).to eq("--no-rdoc") + end + + it "attribute options takes a Hash value" do + resource.options({ one: "two" }) + expect(resource.options).to eq({ one: "two" }) + end + + it "attribute gem_binary defaults to nil" do + expect(resource.gem_binary).to be_nil + end + + it "attribute gem_binary takes a String value" do + resource.gem_binary("/my/fav/gem") + expect(resource.gem_binary).to eq("/my/fav/gem") + end + + it "attribute user defaults to nil" do + expect(resource.user).to be_nil + end + + it "attribute user takes a String value" do + resource.user("masha") + expect(resource.user).to eq("masha") + end + + it "attribute root_path defaults to nil" do + expect(resource.root_path).to be_nil + end + + it "attribute root_path takes a String value" do + resource.root_path("C:\\crazytown") + expect(resource.root_path).to eq("C:\\crazytown") + end + + it "action defaults to :install" do + expect(resource.action).to eq(:install) + end + + it "actions include :upgrade" do + expect(resource.allowed_actions).to include(:upgrade) + end + + it "actions include :remove" do + expect(resource.allowed_actions).to include(:remove) + end + + it "actions include :purge" do + expect(resource.allowed_actions).to include(:purge) + end + + it "sets the provider to RbenvRubygems" do + expect(resource.provider).to eq(Chef::Provider::Package::RbenvRubygems) + end +end From b7c703a32a24f58831e066887dd2f52466a86e41 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 19:29:58 -0700 Subject: [PATCH 08/11] Add spec coverage for rbenv_rehash resource. --- test/unit/resources/rehash_spec.rb | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/unit/resources/rehash_spec.rb diff --git a/test/unit/resources/rehash_spec.rb b/test/unit/resources/rehash_spec.rb new file mode 100644 index 00000000..5bdd63af --- /dev/null +++ b/test/unit/resources/rehash_spec.rb @@ -0,0 +1,40 @@ +require "chef/resource/lwrp_base" + +unless Chef::Resource.const_defined?("RbenvRehash") + Chef::Resource::LWRPBase.build_from_file( + "rbenv", + File.join(File.dirname(__FILE__), %w{.. .. .. resources rehash.rb}), + nil + ) +end + +describe Chef::Resource::RbenvRehash do + + let(:resource) { described_class.new("yabba") } + + it "sets the default attribute to name" do + expect(resource.name).to eq("yabba") + end + + it "attribute user defaults to nil" do + expect(resource.user).to be_nil + end + + it "attribute user takes a String value" do + resource.name("jerry") + expect(resource.name).to eq("jerry") + end + + it "attribute root_path defaults to nil" do + expect(resource.root_path).to be_nil + end + + it "attribute root_path takes a String value" do + resource.root_path("/nowhere/there") + expect(resource.root_path).to eq("/nowhere/there") + end + + it "action defaults to :run" do + expect(resource.action).to eq(:run) + end +end From f3f9f3a3f8ec30d02edb4b68e78e27a623e8b7cd Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 19:49:41 -0700 Subject: [PATCH 09/11] Add spec coverage for rbenv_script resource. --- resources/script.rb | 2 +- test/unit/resources/script_spec.rb | 135 +++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 test/unit/resources/script_spec.rb diff --git a/resources/script.rb b/resources/script.rb index 455c5371..e345ce0e 100644 --- a/resources/script.rb +++ b/resources/script.rb @@ -33,7 +33,7 @@ attribute :returns, :kind_of => Array, :default => [ 0 ] attribute :timeout, :kind_of => Integer attribute :user, :kind_of => String -attribute :umask, :kind_of => String +attribute :umask, :kind_of => [String, Integer] def initialize(*args) super diff --git a/test/unit/resources/script_spec.rb b/test/unit/resources/script_spec.rb new file mode 100644 index 00000000..78db684b --- /dev/null +++ b/test/unit/resources/script_spec.rb @@ -0,0 +1,135 @@ +require "chef/resource/lwrp_base" + +unless Chef::Resource.const_defined?("RbenvScript") + Chef::Resource::LWRPBase.build_from_file( + "rbenv", + File.join(File.dirname(__FILE__), %w{.. .. .. resources script.rb}), + nil + ) +end + +describe Chef::Resource::RbenvScript do + + let(:resource) { described_class.new("gogo") } + + it "sets the default attribute to name" do + expect(resource.name).to eq("gogo") + end + + it "attribute rbenv_version defaults to nil" do + expect(resource.rbenv_version).to be_nil + end + + it "attribute rbenv_version takes a String value" do + resource.rbenv_version("bunnyruby") + expect(resource.rbenv_version).to eq("bunnyruby") + end + + it "attribute root_path defaults to nil" do + expect(resource.root_path).to be_nil + end + + it "attribute root_path takes a String value" do + resource.root_path("/yep") + expect(resource.root_path).to eq("/yep") + end + + it "attribute code defaults to nil" do + expect(resource.code).to be_nil + end + + it "attribute code takes a String value" do + resource.code("echo hi") + expect(resource.code).to eq("echo hi") + end + + it "attribute creates defaults to nil" do + expect(resource.creates).to be_nil + end + + it "attribute creates takes a String value" do + resource.creates("/tmp/thefile") + expect(resource.creates).to eq("/tmp/thefile") + end + + it "attribute cwd defaults to nil" do + expect(resource.cwd).to be_nil + end + + it "attribute cwd takes a String value" do + resource.cwd("/root") + expect(resource.cwd).to eq("/root") + end + + it "attribute environment defaults to nil" do + expect(resource.environment).to be_nil + end + + it "attribute environment takes a Hash value" do + resource.environment({ "BEANS" => "pinto" }) + expect(resource.environment).to eq({ "BEANS" => "pinto" }) + end + + it "attribute group defaults to nil" do + expect(resource.group).to be_nil + end + + it "attribute group takes a String value" do + resource.group("wheelers") + expect(resource.group).to eq("wheelers") + end + + it "attribute path defaults to nil" do + expect(resource.path).to be_nil + end + + it "attribute path takes an Array value" do + resource.path(["/tmp/pathpath"]) + expect(resource.path).to eq(["/tmp/pathpath"]) + end + + it "attribute returns defaults to 0" do + expect(resource.returns).to eq([0]) + end + + it "attribute returns takes an Array value" do + resource.returns([0, 127, 255]) + expect(resource.returns).to eq([0, 127, 255]) + end + + it "attribute timeout defaults to nil" do + expect(resource.timeout).to be_nil + end + + it "attribute timeout takes an Integer value" do + resource.timeout(123) + expect(resource.timeout).to eq(123) + end + + it "attribute user defaults to nil" do + expect(resource.user).to be_nil + end + + it "attribute user takes a String value" do + resource.user("eric") + expect(resource.user).to eq("eric") + end + + it "attribute umask defaults to nil" do + expect(resource.umask).to be_nil + end + + it "attribute umask takes a String value" do + resource.umask("0777") + expect(resource.umask).to eq("0777") + end + + it "attribute umask takes an Integer value" do + resource.umask(0640) + expect(resource.umask).to eq(0640) + end + + it "action defaults to :run" do + expect(resource.action).to eq(:run) + end +end From df45fcc4362b5086517d1b7f386905bbb1611d8f Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 20:17:55 -0700 Subject: [PATCH 10/11] Update .kitchen.yml format. --- .kitchen.yml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index 8053a09d..c50d9948 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,25 +1,15 @@ --- -driver_plugin: vagrant -driver_config: - require_chef_omnibus: true +driver: + name: vagrant platforms: - name: ubuntu-12.04 - driver_config: - box: opscode-ubuntu-12.04 - box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box run_list: - recipe[apt] - name: ubuntu-10.04 - driver_config: - box: opscode-ubuntu-10.04 - box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box run_list: - recipe[apt] -- name: centos-6.4 - driver_config: - box: opscode-centos-6.4 - box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box +- name: centos-6.5 suites: - name: system_ruby From d3338a0a8d30dadb59a9f0bbfd7f65c4fe068ea1 Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Sun, 2 Mar 2014 20:18:12 -0700 Subject: [PATCH 11/11] Update to Berkshelf 3.0 syntax in Berksfile. --- Berksfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Berksfile b/Berksfile index 04896dff..64472070 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,4 @@ -site :opscode +source 'http://api.berkshelf.com' metadata