-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from fnichol/testify
Update testing support and add unit tests for existing resources
- Loading branch information
Showing
12 changed files
with
432 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--default_path test/unit | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
site :opscode | ||
source 'http://api.berkshelf.com' | ||
|
||
metadata | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.