diff options
134 files changed, 1632 insertions, 1444 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ad646f30..7382420ee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,20 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 13.6.48 --> -## [v13.6.48](https://github.com/chef/chef/tree/v13.6.48) (2017-12-19) +<!-- latest_release 13.6.51 --> +## [v13.6.51](https://github.com/chef/chef/tree/v13.6.51) (2017-12-20) #### Merged Pull Requests -- fix for data bag names partially matching search reserved words [#6652](https://github.com/chef/chef/pull/6652) ([sandratiffin](https://github.com/sandratiffin)) +- Modernize launchd resource [#6698](https://github.com/chef/chef/pull/6698) ([tas50](https://github.com/tas50)) <!-- latest_release --> <!-- release_rollup since=13.6.4 --> ### Changes since 13.6.4 release #### Merged Pull Requests +- Modernize launchd resource [#6698](https://github.com/chef/chef/pull/6698) ([tas50](https://github.com/tas50)) <!-- 13.6.51 --> +- Add an 's' for quantity of 0 cookbooks. [#6552](https://github.com/chef/chef/pull/6552) ([anoadragon453](https://github.com/anoadragon453)) <!-- 13.6.50 --> +- Fix yum_repository allowing priority of 0 and remove string regexes [#6697](https://github.com/chef/chef/pull/6697) ([tas50](https://github.com/tas50)) <!-- 13.6.49 --> +- Add descriptions and yard @since comments to all resources [#6696](https://github.com/chef/chef/pull/6696) ([tas50](https://github.com/tas50)) <!-- 13.6.48 --> +- Cleanup to some of the resource specs [#6692](https://github.com/chef/chef/pull/6692) ([tas50](https://github.com/tas50)) <!-- 13.6.48 --> - fix for data bag names partially matching search reserved words [#6652](https://github.com/chef/chef/pull/6652) ([sandratiffin](https://github.com/sandratiffin)) <!-- 13.6.48 --> - Modernize directory resource [#6693](https://github.com/chef/chef/pull/6693) ([tas50](https://github.com/tas50)) <!-- 13.6.47 --> - Modernize the ifconfig resource [#6684](https://github.com/chef/chef/pull/6684) ([tas50](https://github.com/tas50)) <!-- 13.6.46 --> diff --git a/Gemfile.lock b/Gemfile.lock index bab207f26d..1b6452a30c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,10 +17,10 @@ GIT PATH remote: . specs: - chef (13.6.48) + chef (13.6.51) addressable bundler (>= 1.10) - chef-config (= 13.6.48) + chef-config (= 13.6.51) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -47,10 +47,10 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (13.6.48-universal-mingw32) + chef (13.6.51-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 13.6.48) + chef-config (= 13.6.51) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -92,7 +92,7 @@ PATH PATH remote: chef-config specs: - chef-config (13.6.48) + chef-config (13.6.51) addressable fuzzyurl mixlib-config (~> 2.0) @@ -158,7 +158,7 @@ GEM gyoku (1.3.1) builder (>= 2.1.2) hashdiff (0.3.7) - hashie (3.5.6) + hashie (3.5.7) highline (1.7.10) htmlentities (4.3.4) httpclient (2.8.3) @@ -309,7 +309,7 @@ GEM simplecov-html (~> 0.10.0) simplecov-html (0.10.2) slop (3.6.0) - specinfra (2.72.1) + specinfra (2.73.0) net-scp net-ssh (>= 2.7, < 5.0) net-telnet @@ -1 +1 @@ -13.6.48
\ No newline at end of file +13.6.51
\ No newline at end of file diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index 346ef08ef0..9dadb7c54d 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "13.6.48" + VERSION = "13.6.51" end # diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index 6938ac280d..92084e7906 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -146,12 +146,12 @@ class Chef end if upload_failures == 0 - ui.info "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""}." + ui.info "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"}." elsif upload_failures > 0 && upload_ok > 0 - ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""} ok but #{upload_failures} " + - "cookbook#{upload_failures > 1 ? "s" : ""} upload failed." + ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"} ok but #{upload_failures} " + + "cookbook#{upload_failures == 1 ? "" : "s"} upload failed." elsif upload_failures > 0 && upload_ok == 0 - ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures > 1 ? "s" : ""}." + ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures == 1 ? "" : "s"}." exit 1 end end diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb index 8281410d42..8d868784dd 100644 --- a/lib/chef/provider/launchd.rb +++ b/lib/chef/provider/launchd.rb @@ -17,7 +17,6 @@ # require "chef/provider" -require "chef/resource/launchd" require "chef/resource/file" require "chef/resource/cookbook_file" require "chef/resource/macosx_service" diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb index 8397f84c71..c077922a20 100644 --- a/lib/chef/resource/apt_package.rb +++ b/lib/chef/resource/apt_package.rb @@ -21,6 +21,7 @@ require "chef/provider/package/apt" class Chef class Resource + # Use the apt_package resource to manage packages on Debian and Ubuntu platforms. class AptPackage < Chef::Resource::Package resource_name :apt_package provides :package, os: "linux", platform_family: "debian" diff --git a/lib/chef/resource/apt_preference.rb b/lib/chef/resource/apt_preference.rb index 603766d76b..87c5a5a016 100644 --- a/lib/chef/resource/apt_preference.rb +++ b/lib/chef/resource/apt_preference.rb @@ -20,6 +20,10 @@ require "chef/resource" class Chef class Resource + # The apt_preference resource allows for the creation of APT preference files. Preference files are used to control + # which package versions and sources are prioritized during installation. + # + # @since 13.3 class AptPreference < Chef::Resource resource_name :apt_preference provides :apt_preference diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index 8b69435246..5da0b4e37b 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -20,6 +20,10 @@ require "chef/resource" class Chef class Resource + # Use the apt_repository resource to specify additional APT repositories. Adding a new repository will update + # APT package cache immediately. + # + # @since 12.9 class AptRepository < Chef::Resource resource_name :apt_repository provides :apt_repository diff --git a/lib/chef/resource/apt_update.rb b/lib/chef/resource/apt_update.rb index 67ca7fbfea..0349614ad2 100644 --- a/lib/chef/resource/apt_update.rb +++ b/lib/chef/resource/apt_update.rb @@ -20,6 +20,9 @@ require "chef/resource" class Chef class Resource + # Use the apt_update resource to manage APT repository updates on Debian and Ubuntu platforms. + # + # @since 12.7 class AptUpdate < Chef::Resource resource_name :apt_update provides :apt_update diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb index 1238eedc42..ebc4a7790b 100644 --- a/lib/chef/resource/bash.rb +++ b/lib/chef/resource/bash.rb @@ -21,6 +21,10 @@ require "chef/provider/script" class Chef class Resource + # Use the bash resource to execute scripts using the Bash interpreter. This resource may also use any of the actions + # and properties that are available to the execute resource. Commands that are executed with this resource are (by + # their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if + # and only_if to guard this resource for idempotence. class Bash < Chef::Resource::Script def initialize(name, run_context = nil) diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb index 10e96839fb..b3c7b17cef 100644 --- a/lib/chef/resource/batch.rb +++ b/lib/chef/resource/batch.rb @@ -20,6 +20,11 @@ require "chef/resource/windows_script" class Chef class Resource + # Use the batch resource to execute a batch script using the cmd.exe interpreter on Windows. The batch resource + # creates and executes a temporary file (similar to how the script resource behaves), rather than running the + # command inline. Commands that are executed with this resource are (by their nature) not idempotent, as they are + # typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for + # idempotence. class Batch < Chef::Resource::WindowsScript provides :batch, os: "windows" diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb index b14591876a..d91777cb74 100644 --- a/lib/chef/resource/bff_package.rb +++ b/lib/chef/resource/bff_package.rb @@ -21,6 +21,10 @@ require "chef/provider/package/aix" class Chef class Resource + # Use the bff_package resource to manage packages for the AIX platform using the installp utility. When a package is + # installed from a local file, it must be added to the node using the remote_file or cookbook_file resources. + # + # @since 12.0 class BffPackage < Chef::Resource::Package end end diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb index 81cfd89e5e..5d2c5555be 100644 --- a/lib/chef/resource/breakpoint.rb +++ b/lib/chef/resource/breakpoint.rb @@ -20,6 +20,12 @@ require "chef/resource" class Chef class Resource + # Use the breakpoint resource to add breakpoints to recipes. Run the chef-shell in chef-client mode, and then use + # those breakpoints to debug recipes. Breakpoints are ignored by the chef-client during an actual chef-client run. + # That said, breakpoints are typically used to debug recipes only when running them in a non-production environment, + # after which they are removed from those recipes before the parent cookbook is uploaded to the Chef server. + # + # @since 12.0 class Breakpoint < Chef::Resource provides :breakpoint resource_name :breakpoint diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb index fcf3f02b86..8f3b3038c4 100644 --- a/lib/chef/resource/cab_package.rb +++ b/lib/chef/resource/cab_package.rb @@ -21,6 +21,9 @@ require "chef/mixin/uris" class Chef class Resource + # Use the cab_package resource to install or remove Microsoft Windows cabinet (.cab) packages. + # + # @since 12.15 class CabPackage < Chef::Resource::Package include Chef::Mixin::Uris diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb index 3a2d90e852..b6bbd0e209 100644 --- a/lib/chef/resource/chef_gem.rb +++ b/lib/chef/resource/chef_gem.rb @@ -21,6 +21,18 @@ require "chef/resource/gem_package" class Chef class Resource + # Use the chef_gem resource to install a gem only for the instance of Ruby that is dedicated to the chef-client. + # When a gem is installed from a local file, it must be added to the node using the remote_file or cookbook_file + # resources. + # + # The chef_gem resource works with all of the same properties and options as the gem_package resource, but does not + # accept the gem_binary property because it always uses the CurrentGemEnvironment under which the chef-client is + # running. In addition to performing actions similar to the gem_package resource, the chef_gem resource does the + # following: + # - Runs its actions immediately, before convergence, allowing a gem to be used in a recipe immediately after it is + # installed + # - Runs Gem.clear_paths after the action, ensuring that gem is aware of changes so that it can be required + # immediately after it is installed class ChefGem < Chef::Resource::Package::GemPackage resource_name :chef_gem diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb index 77bdcb197a..58bcab8b39 100644 --- a/lib/chef/resource/chocolatey_package.rb +++ b/lib/chef/resource/chocolatey_package.rb @@ -20,6 +20,9 @@ require "chef/resource/package" class Chef class Resource + # Use the chocolatey_package resource to manage packages using Chocolatey on the Microsoft Windows platform. + # + # @since 12.7 class ChocolateyPackage < Chef::Resource::Package resource_name :chocolatey_package @@ -31,7 +34,6 @@ class Chef property :options, String property :package_name, [String, Array], coerce: proc { |x| [x].flatten } - property :version, [String, Array], coerce: proc { |x| [x].flatten } property :returns, [Integer, Array], default: [ 0 ], desired_state: false end diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb index f58ad786fc..8c3de119e9 100644 --- a/lib/chef/resource/cookbook_file.rb +++ b/lib/chef/resource/cookbook_file.rb @@ -24,6 +24,15 @@ require "chef/mixin/securable" class Chef class Resource + # Use the cookbook_file resource to transfer files from a sub-directory of COOKBOOK_NAME/files/ to a specified path + # located on a host that is running the chef-client. The file is selected according to file specificity, which allows + # different source files to be used based on the hostname, host platform (operating system, distro, or as appropriate), + # or platform version. Files that are located in the COOKBOOK_NAME/files/default sub-directory may be used on any + # platform. + # + # During a chef-client run, the checksum for each local file is calculated and then compared against the checksum for + # the same file as it currently exists in the cookbook on the Chef server. A file is not transferred when the checksums + # match. Only files that require an update are transferred from the Chef server to a node. class CookbookFile < Chef::Resource::File include Chef::Mixin::Securable diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index a76d454bf0..2b70be7bb8 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -21,6 +21,8 @@ require "chef/resource" class Chef class Resource + # Use the cron resource to manage cron entries for time-based job scheduling. Properties for a schedule will default + # to * if not provided. The cron resource requires access to a crontab program, typically cron. class Cron < Chef::Resource identity_attr :command diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb index 4e7c22b660..ef302af6c0 100644 --- a/lib/chef/resource/csh.rb +++ b/lib/chef/resource/csh.rb @@ -21,6 +21,10 @@ require "chef/provider/script" class Chef class Resource + # Use the csh resource to execute scripts using the csh interpreter. This resource may also use any of the actions + # and properties that are available to the execute resource. Commands that are executed with this resource are (by + # their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if + # and only_if to guard this resource for idempotence. class Csh < Chef::Resource::Script def initialize(name, run_context = nil) diff --git a/lib/chef/resource/dnf_package.rb b/lib/chef/resource/dnf_package.rb index 05ed895e70..0e09d90d43 100644 --- a/lib/chef/resource/dnf_package.rb +++ b/lib/chef/resource/dnf_package.rb @@ -21,6 +21,11 @@ require "chef/mixin/shell_out" class Chef class Resource + # Use the dnf_package resource to install, upgrade, and remove packages with DNF for Fedora platforms. The dnf_package + # resource is able to resolve provides data for packages much like DNF can do when it is run from the command line. + # This allows a variety of options for installing packages, like minimum versions, virtual provides, and library names. + # + # @since 12.18 class DnfPackage < Chef::Resource::Package extend Chef::Mixin::Which extend Chef::Mixin::ShellOut diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb index 9ff3239884..c73fc506ad 100644 --- a/lib/chef/resource/dpkg_package.rb +++ b/lib/chef/resource/dpkg_package.rb @@ -20,6 +20,8 @@ require "chef/resource/package" class Chef class Resource + # Use the dpkg_package resource to manage packages for the dpkg platform. When a package is installed from a local + # file, it must be added to the node using the remote_file or cookbook_file resources. class DpkgPackage < Chef::Resource::Package resource_name :dpkg_package provides :dpkg_package, os: "linux" diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index d3b579e428..0840b9bca1 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -19,6 +19,11 @@ require "chef/dsl/powershell" class Chef class Resource + # The dsc_resource resource allows any DSC resource to be used in a Chef recipe, as well as any custom resources + # that have been added to your Windows PowerShell environment. Microsoft frequently adds new resources to the DSC + # resource collection. + # + # @since 12.2 class DscResource < Chef::Resource provides :dsc_resource, os: "windows" diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index 7682c7e778..cea52e422b 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -21,6 +21,11 @@ require "chef/dsl/powershell" class Chef class Resource + # Many DSC resources are comparable to built-in Chef resources. For example, both DSC and Chef have file, package, + # and service resources. The dsc_script resource is most useful for those DSC resources that do not have a direct + # comparison to a resource in Chef, such as the Archive resource, a custom DSC resource, an existing DSC script + # that performs an important task, and so on. Use the dsc_script resource to embed the code that defines a DSC + # configuration directly within a Chef recipe. class DscScript < Chef::Resource include Chef::DSL::Powershell diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index 7071be4b91..12133f4368 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -19,6 +19,8 @@ class Chef class Resource + # Use the env resource to manage environment keys in Microsoft Windows. After an environment key is set, Microsoft + # Windows must be restarted before the environment key will be available to the Task Scheduler. class Env < Chef::Resource resource_name :env provides :env, os: "windows" diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index ba1b8ae6e3..de927ec06e 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -22,6 +22,9 @@ require "chef/provider/execute" class Chef class Resource + # Use the execute resource to execute a single command. Commands that are executed with this resource are (by their + # nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if + # to guard this resource for idempotence. class Execute < Chef::Resource identity_attr :command diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index 0540385646..43d9c57150 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -25,6 +25,7 @@ require "pathname" class Chef class Resource + # Use the file resource to manage files directly on a node. class File < Chef::Resource include Chef::Mixin::Securable diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index eedddf28e7..caaba29129 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -26,6 +26,7 @@ require "chef/mixin/shell_out" class Chef class Resource + # Use the freebsd_package resource to manage packages for the FreeBSD platform. class FreebsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb index fc162a6033..8e3a426035 100644 --- a/lib/chef/resource/gem_package.rb +++ b/lib/chef/resource/gem_package.rb @@ -20,6 +20,8 @@ require "chef/resource/package" class Chef class Resource + # Use the gem_package resource to manage gem packages that are only included in recipes. When a package is installed + # from a local file, it must be added to the node using the remote_file or cookbook_file resources. class GemPackage < Chef::Resource::Package resource_name :gem_package diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb index 4799b54d3d..ac4f027552 100644 --- a/lib/chef/resource/git.rb +++ b/lib/chef/resource/git.rb @@ -20,6 +20,8 @@ require "chef/resource/scm" class Chef class Resource + # Use the git resource to manage source control resources that exist in a git repository. git version 1.6.5 (or higher) + # is required to use all of the functionality in the git resource. class Git < Chef::Resource::Scm def initialize(name, run_context = nil) diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index d3a4a1ce89..69a3827a5c 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -19,6 +19,7 @@ class Chef class Resource + # Use the group resource to manage a local group. class Group < Chef::Resource identity_attr :group_name diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb index c2d0a65c5b..6174a31079 100644 --- a/lib/chef/resource/homebrew_package.rb +++ b/lib/chef/resource/homebrew_package.rb @@ -23,6 +23,9 @@ require "chef/resource/package" class Chef class Resource + # Use the homebrew_package resource to manage packages for the macOS platform. + # + # @since 12.0 class HomebrewPackage < Chef::Resource::Package resource_name :homebrew_package provides :package, os: "darwin" diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb index 9fac3562f3..9d8fce9b22 100644 --- a/lib/chef/resource/http_request.rb +++ b/lib/chef/resource/http_request.rb @@ -22,6 +22,8 @@ require "chef/provider/http_request" class Chef class Resource + # Use the http_request resource to send an HTTP request (GET, PUT, POST, DELETE, HEAD, or OPTIONS) with an arbitrary + # message. This resource is often useful when custom callbacks are necessary. class HttpRequest < Chef::Resource identity_attr :url diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb index 4d2c957e17..296919dc1c 100644 --- a/lib/chef/resource/ips_package.rb +++ b/lib/chef/resource/ips_package.rb @@ -21,6 +21,7 @@ require "chef/provider/package/ips" class Chef class Resource + # Use the ips_package resource to manage packages (using Image Packaging System (IPS)) on the Solaris 11 platform. class IpsPackage < ::Chef::Resource::Package resource_name :ips_package provides :package, os: "solaris2" diff --git a/lib/chef/resource/ksh.rb b/lib/chef/resource/ksh.rb index 3097156329..8024f0d6bd 100644 --- a/lib/chef/resource/ksh.rb +++ b/lib/chef/resource/ksh.rb @@ -20,6 +20,12 @@ require "chef/resource/script" class Chef class Resource + # Use the ksh resource to execute scripts using the Korn shell (ksh) interpreter. This resource may also use any + # f the actions and properties that are available to the execute resource. Commands that are executed with this + # resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are + # run. Use not_if and only_if to guard this resource for idempotence. + # + # @since 12.6 class Ksh < Chef::Resource::Script def initialize(name, run_context = nil) diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb index 3fba76e220..121af1555c 100644 --- a/lib/chef/resource/launchd.rb +++ b/lib/chef/resource/launchd.rb @@ -17,19 +17,20 @@ # require "chef/resource" -require "chef/provider/launchd" class Chef class Resource + # Use the launchd resource to manage system-wide services (daemons) and per-user services (agents) on the macOS platform. + # + # @since 12.8 class Launchd < Chef::Resource + resource_name :launchd provides :launchd, os: "darwin" - identity_attr :label - default_action :create allowed_actions :create, :create_if_missing, :delete, :enable, :disable, :restart - property :label, String, default: lazy { name }, identity: true + property :label, String, identity: true, name_property: true property :backup, [Integer, FalseClass] property :cookbook, String property :group, [String, Integer] diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 5717ec7bad..7a106b1703 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -22,6 +22,16 @@ require "chef/mixin/securable" class Chef class Resource + # Use the link resource to create symbolic or hard links. + # + # A symbolic link—sometimes referred to as a soft link—is a directory entry that associates a file name with a string + # that contains an absolute or relative path to a file on any file system. In other words, “a file that contains a path + # that points to another file.” A symbolic link creates a new file with a new inode that points to the inode location + # of the original file. + # + # A hard link is a directory entry that associates a file with another file in the same file system. In other words, + # “multiple directory entries to the same file.” A hard link creates a new file that points to the same inode as the + # original file. class Link < Chef::Resource include Chef::Mixin::Securable diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index 32d9629b73..b6da123526 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -21,7 +21,10 @@ require "chef/resource" class Chef class Resource - # Sends a string to a log provider. + # Use the log resource to create log entries. The log resource behaves like any other resource: built into the resource + # collection during the compile phase, and then run during the execution phase. (To create a log entry that is not built + # into the resource collection, use Chef::Log instead of the log resource.) + # # Allows logging a :debug, :info, :warn, and :error levels # Defaults to :info level # diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb index 3685334c17..e787529f48 100644 --- a/lib/chef/resource/macports_package.rb +++ b/lib/chef/resource/macports_package.rb @@ -20,6 +20,7 @@ require "chef/resource/package" class Chef class Resource + # Use the macports_package resource to manage packages for the macOS platform. class MacportsPackage < Chef::Resource::Package resource_name :macports_package end diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb index df6e705f15..354582d1cf 100644 --- a/lib/chef/resource/mdadm.rb +++ b/lib/chef/resource/mdadm.rb @@ -21,6 +21,10 @@ require "chef/resource" class Chef class Resource + # Use the mdadm resource to manage RAID devices in a Linux environment using the mdadm utility. The mdadm resource + # will create and assemble an array, but it will not create the config file that is used to persist the array upon + # reboot. If the config file is required, it must be done by specifying a template with the correct array layout, + # and then by using the mount provider to create a file systems table (fstab) entry. class Mdadm < Chef::Resource identity_attr :raid_device diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index 9df2bbcdbc..1a1f8c0565 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -21,6 +21,7 @@ require "chef/resource" class Chef class Resource + # Use the mount resource to manage a mounted file system. class Mount < Chef::Resource identity_attr :device diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb index 93c8fbbe21..77eeed898f 100644 --- a/lib/chef/resource/msu_package.rb +++ b/lib/chef/resource/msu_package.rb @@ -21,6 +21,9 @@ require "chef/mixin/uris" class Chef class Resource + # Use the msu_package resource to install Microsoft Update(MSU) packages on Microsoft Windows machines. + # + # @since 12.17 class MsuPackage < Chef::Resource::Package include Chef::Mixin::Uris diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb index 6fffecf16e..f2534413ea 100644 --- a/lib/chef/resource/ohai.rb +++ b/lib/chef/resource/ohai.rb @@ -19,6 +19,8 @@ class Chef class Resource + # Use the ohai resource to reload the Ohai configuration on a node. This allows recipes that change system attributes + # (like a recipe that adds a user) to refer to those attributes later on during the chef-client run. class Ohai < Chef::Resource resource_name :ohai provides :ohai diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb index d0f9fe877f..e5cdefe684 100644 --- a/lib/chef/resource/openbsd_package.rb +++ b/lib/chef/resource/openbsd_package.rb @@ -25,6 +25,9 @@ require "chef/mixin/shell_out" class Chef class Resource + # Use the openbsd_package resource to manage packages for the OpenBSD platform. + # + # @since 12.1 class OpenbsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb index 5647f203d2..60810fd5ad 100644 --- a/lib/chef/resource/package.rb +++ b/lib/chef/resource/package.rb @@ -21,6 +21,12 @@ require "chef/resource" class Chef class Resource + # Use the package resource to manage packages. When the package is installed from a local file (such as with RubyGems, + # dpkg, or RPM Package Manager), the file must be added to the node using the remote_file or cookbook_file resources. + # + # This resource is the base resource for several other resources used for package management on specific platforms. + # While it is possible to use each of these specific resources, it is recommended to use the package resource as often + # as possible. class Package < Chef::Resource resource_name :package diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb index 66b39d164d..73d8afb0de 100644 --- a/lib/chef/resource/pacman_package.rb +++ b/lib/chef/resource/pacman_package.rb @@ -20,6 +20,7 @@ require "chef/resource/package" class Chef class Resource + # Use the pacman_package resource to manage packages (using pacman) on the Arch Linux platform. class PacmanPackage < Chef::Resource::Package resource_name :pacman_package provides :pacman_package, os: "linux" diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb index 31c0f31b8c..6bc598e4ee 100644 --- a/lib/chef/resource/paludis_package.rb +++ b/lib/chef/resource/paludis_package.rb @@ -21,6 +21,9 @@ require "chef/provider/package/paludis" class Chef class Resource + # Use the paludis_package resource to manage packages for the Paludis platform. + # + # @since 12.1 class PaludisPackage < Chef::Resource::Package resource_name :paludis_package provides :paludis_package, os: "linux" diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb index 60af0e92da..c00246ac6b 100644 --- a/lib/chef/resource/perl.rb +++ b/lib/chef/resource/perl.rb @@ -21,6 +21,10 @@ require "chef/provider/script" class Chef class Resource + # Use the perl resource to execute scripts using the Perl interpreter. This resource may also use any of the actions + # and properties that are available to the execute resource. Commands that are executed with this resource are (by + # their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and + # only_if to guard this resource for idempotence. class Perl < Chef::Resource::Script def initialize(name, run_context = nil) super diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb index ad66c7b42b..a2bc516711 100644 --- a/lib/chef/resource/portage_package.rb +++ b/lib/chef/resource/portage_package.rb @@ -20,6 +20,7 @@ require "chef/resource/package" class Chef class Resource + # Use the portage_package resource to manage packages for the Gentoo platform. class PortagePackage < Chef::Resource::Package resource_name :portage_package def initialize(name, run_context = nil) diff --git a/lib/chef/resource/powershell_package.rb b/lib/chef/resource/powershell_package.rb index 4d658d3cc5..05c59acf73 100644 --- a/lib/chef/resource/powershell_package.rb +++ b/lib/chef/resource/powershell_package.rb @@ -20,6 +20,11 @@ require "chef/mixin/uris" class Chef class Resource + # Use the powershell_package resource to install and manage packages via the Powershell Package Manager for the + # Microsoft Windows platform. The powershell_package resource requires administrative access, and a source must be + # configured in the Powershell Package Manager via the Register-PackageSource command + # + # @since 12.16 class PowershellPackage < Chef::Resource::Package include Chef::Mixin::Uris diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index b2bd6e718e..8ff58cfeab 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -19,6 +19,14 @@ require "chef/resource/windows_script" class Chef class Resource + # Use the powershell_script resource to execute a script using the Windows PowerShell interpreter, much like how the + # script and script-based resources—bash, csh, perl, python, and ruby—are used. The powershell_script is specific to + # the Microsoft Windows platform and the Windows PowerShell interpreter. + # + # The powershell_script resource creates and executes a temporary file (similar to how the script resource behaves), + # rather than running the command inline. Commands that are executed with this resource are (by their nature) not + # idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard + # this resource for idempotence. class PowershellScript < Chef::Resource::WindowsScript provides :powershell_script, os: "windows" diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb index bcad3d090b..8c9e74217a 100644 --- a/lib/chef/resource/python.rb +++ b/lib/chef/resource/python.rb @@ -20,6 +20,10 @@ require "chef/provider/script" class Chef class Resource + # Use the python resource to execute scripts using the Python interpreter. This resource may also use any of the actions + # and properties that are available to the execute resource. Commands that are executed with this resource are (by + # their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and + # only_if to guard this resource for idempotence. class Python < Chef::Resource::Script def initialize(name, run_context = nil) super diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index bdaa755533..e93c7f53c5 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -28,7 +28,7 @@ class Chef # immediate notifications. Delayed notifications produce unintuitive and # probably undesired results. # - # @since 12.0.0 + # @since 12.0 class Reboot < Chef::Resource resource_name :reboot diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index 549897bb1d..565ff278ea 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -21,6 +21,7 @@ require "chef/digester" class Chef class Resource + # Use the registry_key resource to create and delete registry keys in Microsoft Windows. class RegistryKey < Chef::Resource identity_attr :key state_attrs :values diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index 6e2928f3eb..b165606c79 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -23,6 +23,9 @@ require "chef/mixin/securable" class Chef class Resource + # Use the remote_directory resource to incrementally transfer a directory from a cookbook to a node. The director + # that is copied from the cookbook should be located under COOKBOOK_NAME/files/default/REMOTE_DIRECTORY. The + # remote_directory resource will obey file specificity. class RemoteDirectory < Chef::Resource::Directory include Chef::Mixin::Securable diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 25586af702..4db055a20d 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -25,6 +25,8 @@ require "chef/mixin/uris" class Chef class Resource + # Use the remote_file resource to transfer a file from a remote location using file specificity. This resource is + # similar to the file resource. class RemoteFile < Chef::Resource::File include Chef::Mixin::Securable diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb index 9412d28dce..922535f885 100644 --- a/lib/chef/resource/route.rb +++ b/lib/chef/resource/route.rb @@ -21,6 +21,7 @@ require "chef/resource" class Chef class Resource + # Use the route resource to manage the system routing table in a Linux environment. class Route < Chef::Resource default_action :add allowed_actions :add, :delete diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb index c93dfecaf5..3760412a77 100644 --- a/lib/chef/resource/rpm_package.rb +++ b/lib/chef/resource/rpm_package.rb @@ -21,6 +21,7 @@ require "chef/provider/package/rpm" class Chef class Resource + # Use the rpm_package resource to manage packages for the RPM Package Manager platform. class RpmPackage < Chef::Resource::Package resource_name :rpm_package provides :rpm_package, os: %w{linux aix} diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb index 91805a1db6..300405f89e 100644 --- a/lib/chef/resource/ruby.rb +++ b/lib/chef/resource/ruby.rb @@ -21,6 +21,10 @@ require "chef/provider/script" class Chef class Resource + # Use the ruby resource to execute scripts using the Ruby interpreter. This resource may also use any of the actions + # and properties that are available to the execute resource. Commands that are executed with this resource are (by + # their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and + # only_if to guard this resource for idempotence. class Ruby < Chef::Resource::Script def initialize(name, run_context = nil) super diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb index 87a4cfb7c5..89b90ae70b 100644 --- a/lib/chef/resource/ruby_block.rb +++ b/lib/chef/resource/ruby_block.rb @@ -22,6 +22,9 @@ require "chef/provider/ruby_block" class Chef class Resource + # Use the ruby_block resource to execute Ruby code during a chef-client run. Ruby code in the ruby_block resource is + # evaluated with other resources during convergence, whereas Ruby code outside of a ruby_block resource is evaluated + # before other resources, as the recipe is compiled. class RubyBlock < Chef::Resource default_action :run allowed_actions :create, :run diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb index 5039e2d8fe..a7191360ca 100644 --- a/lib/chef/resource/script.rb +++ b/lib/chef/resource/script.rb @@ -22,6 +22,10 @@ require "chef/provider/script" class Chef class Resource + # Use the script resource to execute scripts using a specified interpreter, such as Bash, csh, Perl, Python, or Ruby. + # This resource may also use any of the actions and properties that are available to the execute resource. Commands + # that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the + # environment in which they are run. Use not_if and only_if to guard this resource for idempotence. class Script < Chef::Resource::Execute identity_attr :name diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 83e44c9d30..dc23155b59 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -22,6 +22,7 @@ require "shellwords" class Chef class Resource + # Use the service resource to manage a service. class Service < Chef::Resource identity_attr :service_name diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb index 87173ccfa9..9e79cace3f 100644 --- a/lib/chef/resource/smartos_package.rb +++ b/lib/chef/resource/smartos_package.rb @@ -21,6 +21,7 @@ require "chef/provider/package/smartos" class Chef class Resource + # Use the smartos_package resource to manage packages for the SmartOS platform. class SmartosPackage < Chef::Resource::Package resource_name :smartos_package provides :package, os: "solaris2", platform_family: "smartos" diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb index d0f8c144af..24215bb456 100644 --- a/lib/chef/resource/solaris_package.rb +++ b/lib/chef/resource/solaris_package.rb @@ -22,6 +22,7 @@ require "chef/provider/package/solaris" class Chef class Resource + # The solaris_package resource is used to manage packages for the Solaris platform. class SolarisPackage < Chef::Resource::Package resource_name :solaris_package provides :package, os: "solaris2", platform_family: "nexentacore" diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb index 9966614eeb..473a48cefd 100644 --- a/lib/chef/resource/subversion.rb +++ b/lib/chef/resource/subversion.rb @@ -21,6 +21,7 @@ require "chef/resource/scm" class Chef class Resource + # Use the subversion resource to manage source control resources that exist in a Subversion repository. class Subversion < Chef::Resource::Scm allowed_actions :force_export diff --git a/lib/chef/resource/systemd_unit.rb b/lib/chef/resource/systemd_unit.rb index 66c4e6f594..b08b26efa7 100644 --- a/lib/chef/resource/systemd_unit.rb +++ b/lib/chef/resource/systemd_unit.rb @@ -21,6 +21,9 @@ require "iniparse" class Chef class Resource + # Use the systemd_unit resource to create, manage, and run systemd units. + # + # @since 12.11 class SystemdUnit < Chef::Resource resource_name :systemd_unit diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb index 896aa71340..4b5b82effb 100644 --- a/lib/chef/resource/template.rb +++ b/lib/chef/resource/template.rb @@ -24,6 +24,15 @@ require "chef/mixin/securable" class Chef class Resource + # A cookbook template is an Embedded Ruby (ERB) template that is used to dynamically generate static text files. + # Templates may contain Ruby expressions and statements, and are a great way to manage configuration files. Use the + # template resource to add cookbook templates to recipes; place the corresponding Embedded Ruby (ERB) template file + # in a cookbook’s /templates directory. + # + # Use the template resource to manage the contents of a file using an Embedded Ruby (ERB) template by transferring + # files from a sub-directory of COOKBOOK_NAME/templates/ to a specified path located on a host that is running the + # chef-client. This resource includes actions and properties from the file resource. Template files managed by the + # template resource follow the same file specificity rules as the remote_file and file resources. class Template < Chef::Resource::File include Chef::Mixin::Securable diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index 380671113a..39d8159d4f 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -20,6 +20,7 @@ require "chef/resource" class Chef class Resource + # Use the user resource to add users, update existing users, remove users, and to lock/unlock user passwords. class User < Chef::Resource resource_name :user_resource_abstract_base_class # this prevents magickal class name DSL wiring identity_attr :username diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb index e37bad4b0a..d373e1f19c 100644 --- a/lib/chef/resource/windows_package.rb +++ b/lib/chef/resource/windows_package.rb @@ -23,6 +23,8 @@ require "chef/win32/error" if RUBY_PLATFORM =~ /mswin|mingw|windows/ class Chef class Resource + # Use the windows_package resource to manage Microsoft Installer Package (MSI) packages for the Microsoft Windows + # platform. class WindowsPackage < Chef::Resource::Package include Chef::Mixin::Uris diff --git a/lib/chef/resource/windows_path.rb b/lib/chef/resource/windows_path.rb index 5472a7e4fd..9274415755 100644 --- a/lib/chef/resource/windows_path.rb +++ b/lib/chef/resource/windows_path.rb @@ -20,6 +20,9 @@ require "chef/resource" class Chef class Resource + # Use the windows_path resource to manage the path environment variable on Microsoft Windows. + # + # @since 13.4 class WindowsPath < Chef::Resource provides :windows_path, os: "windows" diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 405f7f6dbe..1c7c61320f 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -20,6 +20,9 @@ require "chef/resource/service" class Chef class Resource + # Use the windows_service resource to manage a service on the Microsoft Windows platform. + # + # @since 12.0 class WindowsService < Chef::Resource::Service # Until #1773 is resolved, you need to manually specify the windows_service resource diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 344ce50b64..f61a119b5a 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -20,6 +20,9 @@ require "chef/resource" class Chef class Resource + # Use the windows_task resource to create, delete or run a Windows scheduled task. Requires Windows Server 2008 + # or later due to API usage. + # @since 13.0 class WindowsTask < Chef::Resource resource_name :windows_task diff --git a/lib/chef/resource/yum_repository.rb b/lib/chef/resource/yum_repository.rb index 012a74908a..7c30bc5457 100644 --- a/lib/chef/resource/yum_repository.rb +++ b/lib/chef/resource/yum_repository.rb @@ -1,6 +1,6 @@ # # Author:: Thom May (<thom@chef.io>) -# Copyright:: Copyright (c) 2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2016-2017 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,55 +20,59 @@ require "chef/resource" class Chef class Resource + # Use the yum_repository resource to manage a Yum repository configuration file located at /etc/yum.repos.d/repositoryid.repo + # on the local machine. This configuration file specifies which repositories to reference, how to handle cached data, etc. + # + # @since 12.14 class YumRepository < Chef::Resource resource_name :yum_repository provides :yum_repository # http://linux.die.net/man/5/yum.conf as well as # http://dnf.readthedocs.io/en/latest/conf_ref.html - property :baseurl, [String, Array], regex: /.*/ + property :baseurl, [String, Array] property :clean_headers, [TrueClass, FalseClass], default: false # deprecated property :clean_metadata, [TrueClass, FalseClass], default: true property :cost, String, regex: /^\d+$/ - property :description, String, regex: /.*/, default: "Yum Repository" + property :description, String, default: "Yum Repository" property :enabled, [TrueClass, FalseClass], default: true property :enablegroups, [TrueClass, FalseClass] - property :exclude, String, regex: /.*/ + property :exclude, String property :failovermethod, String, equal_to: %w{priority roundrobin} property :fastestmirror_enabled, [TrueClass, FalseClass] property :gpgcheck, [TrueClass, FalseClass], default: true - property :gpgkey, [String, Array], regex: /.*/ + property :gpgkey, [String, Array] property :http_caching, String, equal_to: %w{packages all none} - property :include_config, String, regex: /.*/ - property :includepkgs, String, regex: /.*/ + property :include_config, String + property :includepkgs, String property :keepalive, [TrueClass, FalseClass] property :make_cache, [TrueClass, FalseClass], default: true property :max_retries, [String, Integer] property :metadata_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/, /never/] - property :metalink, String, regex: /.*/ + property :metalink, String property :mirror_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/] - property :mirrorexpire, String, regex: /.*/ + property :mirrorexpire, String property :mirrorlist_expire, String, regex: [/^\d+$/, /^\d+[mhd]$/] - property :mirrorlist, String, regex: /.*/ + property :mirrorlist, String property :mode, default: "0644" property :options, Hash - property :password, String, regex: /.*/ - property :priority, String, regex: /^(\d?[0-9]|[0-9][0-9])$/ - property :proxy_password, String, regex: /.*/ - property :proxy_username, String, regex: /.*/ - property :proxy, String, regex: /.*/ + property :password, String + property :priority, String, regex: /^(\d?[1-9]|[0-9][0-9])$/ + property :proxy_password, String + property :proxy_username, String + property :proxy, String property :repo_gpgcheck, [TrueClass, FalseClass] property :report_instanceid, [TrueClass, FalseClass] - property :repositoryid, String, regex: /.*/, name_property: true + property :repositoryid, String, name_property: true property :skip_if_unavailable, [TrueClass, FalseClass] - property :source, String, regex: /.*/ - property :sslcacert, String, regex: /.*/ - property :sslclientcert, String, regex: /.*/ - property :sslclientkey, String, regex: /.*/ + property :source, String + property :sslcacert, String + property :sslclientcert, String + property :sslclientkey, String property :sslverify, [TrueClass, FalseClass] - property :timeout, String, regex: /^\d+$/ property :throttle, [String, Integer] - property :username, String, regex: /.*/ + property :timeout, String, regex: /^\d+$/ + property :username, String default_action :create allowed_actions :create, :remove, :makecache, :add, :delete diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb index 20b1a9f25f..f412d59988 100644 --- a/lib/chef/resource/zypper_package.rb +++ b/lib/chef/resource/zypper_package.rb @@ -20,6 +20,8 @@ require "chef/resource/package" class Chef class Resource + # Use the zypper_package resource to install, upgrade, and remove packages with Zypper for the SUSE Enterprise and + # OpenSUSE platforms. class ZypperPackage < Chef::Resource::Package resource_name :zypper_package provides :package, platform_family: "suse" diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb index 88b6fd9336..c0ec111c25 100644 --- a/lib/chef/resource/zypper_repository.rb +++ b/lib/chef/resource/zypper_repository.rb @@ -20,6 +20,11 @@ require "chef/resource" class Chef class Resource + # The zypper_repository resource allows for the creation of Zypper package repositories on SUSE Enterprise Linux and + # openSUSE systems. This resource maintains full compatibility with the zypper_repository resource in the existing + # zypper cookbook. + # + # @since 13.3 class ZypperRepository < Chef::Resource resource_name :zypper_repository provides :zypper_repo diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 0950808645..fc9dbfd0ea 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require "chef/version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("13.6.48") + VERSION = Chef::VersionString.new("13.6.51") end # diff --git a/spec/unit/resource/apt_package_spec.rb b/spec/unit/resource/apt_package_spec.rb index 78eccfb444..3911eb3154 100644 --- a/spec/unit/resource/apt_package_spec.rb +++ b/spec/unit/resource/apt_package_spec.rb @@ -31,7 +31,7 @@ describe Chef::Resource::AptPackage, "initialize" do let(:resource) { Chef::Resource::AptPackage.new("foo") } - it "should support default_release" do + it "supports default_release" do resource.default_release("lenny-backports") expect(resource.default_release).to eql("lenny-backports") end diff --git a/spec/unit/resource/bash_spec.rb b/spec/unit/resource/bash_spec.rb index 56c36df1ce..0b6b365eb8 100644 --- a/spec/unit/resource/bash_spec.rb +++ b/spec/unit/resource/bash_spec.rb @@ -20,21 +20,19 @@ require "spec_helper" describe Chef::Resource::Bash do - before(:each) do - @resource = Chef::Resource::Bash.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Bash.new("fakey_fakerton") } - it "should create a new Chef::Resource::Bash" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Bash) + it "creates a new Chef::Resource::Bash" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Bash) end - it "should have a resource name of :bash" do - expect(@resource.resource_name).to eql(:bash) + it "has a resource name of :bash" do + expect(resource.resource_name).to eql(:bash) end - it "should have an interpreter of bash" do - expect(@resource.interpreter).to eql("bash") + it "has an interpreter of bash" do + expect(resource.interpreter).to eql("bash") end end diff --git a/spec/unit/resource/batch_spec.rb b/spec/unit/resource/batch_spec.rb index e19ea15585..626d8b3365 100644 --- a/spec/unit/resource/batch_spec.rb +++ b/spec/unit/resource/batch_spec.rb @@ -33,7 +33,7 @@ describe Chef::Resource::Batch do end - it "should create a new Chef::Resource::Batch" do + it "creates a new Chef::Resource::Batch" do expect(@resource).to be_a_kind_of(Chef::Resource::Batch) end diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb index 2b09fb388f..0eac98c7d2 100644 --- a/spec/unit/resource/chef_gem_spec.rb +++ b/spec/unit/resource/chef_gem_spec.rb @@ -34,15 +34,15 @@ end describe Chef::Resource::ChefGem, "gem_binary" do let(:resource) { Chef::Resource::ChefGem.new("foo") } - it "should raise an exception when gem_binary is set" do + it "raises an exception when gem_binary is set" do expect { resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError) end - it "should set the gem_binary based on computing it from RbConfig" do + it "sets the gem_binary based on computing it from RbConfig" do expect(resource.gem_binary).to eql("#{RbConfig::CONFIG['bindir']}/gem") end - it "should set compile_time to false by default" do + it "sets compile_time to false by default" do expect(resource.compile_time).to be false end diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb index 9b433045c1..809c4c75b6 100644 --- a/spec/unit/resource/chocolatey_package_spec.rb +++ b/spec/unit/resource/chocolatey_package_spec.rb @@ -22,50 +22,50 @@ describe Chef::Resource::ChocolateyPackage do let(:resource) { Chef::Resource::ChocolateyPackage.new("fakey_fakerton") } - it "should create a new Chef::Resource::ChocolateyPackage" do + it "creates a new Chef::Resource::ChocolateyPackage" do expect(resource).to be_a_kind_of(Chef::Resource) expect(resource).to be_a_kind_of(Chef::Resource::Package) expect(resource).to be_a_instance_of(Chef::Resource::ChocolateyPackage) end - it "should have a resource name of :python" do + it "has a resource name of :python" do expect(resource.resource_name).to eql(:chocolatey_package) end - it "should coerce its name to a package_name array" do + it "coerces its name to a package_name array" do expect(resource.package_name).to eql(["fakey_fakerton"]) end - it "the package_name setter should coerce to arrays" do + it "the package_name setter coerces to arrays" do resource.package_name("git") expect(resource.package_name).to eql(["git"]) end - it "the package_name setter should accept arrays" do + it "the package_name setter accepts arrays" do resource.package_name(%w{git unzip}) expect(resource.package_name).to eql(%w{git unzip}) end - it "the name should accept arrays" do + it "the name accepts arrays" do resource = Chef::Resource::ChocolateyPackage.new(%w{git unzip}) expect(resource.package_name).to eql(%w{git unzip}) end - it "the default version should be nil" do + it "the default version is nil" do expect(resource.version).to eql(nil) end - it "the version setter should coerce to arrays" do + it "the version setter coerces to arrays" do resource.version("1.2.3") expect(resource.version).to eql(["1.2.3"]) end - it "the version setter should accept arrays" do + it "the version setter accepts arrays" do resource.version(["1.2.3", "4.5.6"]) expect(resource.version).to eql(["1.2.3", "4.5.6"]) end - it "the default returns should be 0" do + it "the default returns is 0" do expect(resource.returns).to eql([0]) end diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb index 0219945936..9a5f0a59bb 100644 --- a/spec/unit/resource/conditional_spec.rb +++ b/spec/unit/resource/conditional_spec.rb @@ -99,7 +99,7 @@ describe Chef::Resource::Conditional do expect(@conditional.continue?).to be_falsey end - it "should log a warning" do + it "logs a warning" do expect(Chef::Log).to receive(:warn).with("Command 'false' timed out") @conditional.continue? end @@ -202,7 +202,7 @@ describe Chef::Resource::Conditional do expect(@conditional.continue?).to be_truthy end - it "should log a warning" do + it "logs a warning" do expect(Chef::Log).to receive(:warn).with("Command 'false' timed out") @conditional.continue? end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index e2bfc321e8..bd9cf9d987 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -20,157 +20,154 @@ require "spec_helper" describe Chef::Resource::Cron do + let(:resource) { Chef::Resource::Cron.new("cronify") } - before(:each) do - @resource = Chef::Resource::Cron.new("cronify") + it "creates a new Chef::Resource::Cron" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Cron) end - it "should create a new Chef::Resource::Cron" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Cron) + it "has a name property" do + expect(resource.name).to eql("cronify") end - it "should have a name" do - expect(@resource.name).to eql("cronify") + it "has a default action of [:create]" do + expect(resource.action).to eql([:create]) end - it "should have a default action of 'create'" do - expect(@resource.action).to eql([:create]) + it "accepts create or delete for action" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :lolcat }.to raise_error(ArgumentError) end - it "should accept create or delete for action" do - expect { @resource.action :create }.not_to raise_error - expect { @resource.action :delete }.not_to raise_error - expect { @resource.action :lolcat }.to raise_error(ArgumentError) + it "allows you to set a command" do + resource.command "/bin/true" + expect(resource.command).to eql("/bin/true") end - it "should allow you to set a command" do - @resource.command "/bin/true" - expect(@resource.command).to eql("/bin/true") + it "allows you to set a user" do + resource.user "daemon" + expect(resource.user).to eql("daemon") end - it "should allow you to set a user" do - @resource.user "daemon" - expect(@resource.user).to eql("daemon") + it "allows you to specify the minute" do + resource.minute "30" + expect(resource.minute).to eql("30") end - it "should allow you to specify the minute" do - @resource.minute "30" - expect(@resource.minute).to eql("30") + it "allows you to specify the hour" do + resource.hour "6" + expect(resource.hour).to eql("6") end - it "should allow you to specify the hour" do - @resource.hour "6" - expect(@resource.hour).to eql("6") + it "allows you to specify the day" do + resource.day "10" + expect(resource.day).to eql("10") end - it "should allow you to specify the day" do - @resource.day "10" - expect(@resource.day).to eql("10") + it "allows you to specify the month" do + resource.month "10" + expect(resource.month).to eql("10") end - it "should allow you to specify the month" do - @resource.month "10" - expect(@resource.month).to eql("10") + it "allows you to specify the weekday" do + resource.weekday "2" + expect(resource.weekday).to eql("2") end - it "should allow you to specify the weekday" do - @resource.weekday "2" - expect(@resource.weekday).to eql("2") + it "allows you to specify the mailto variable" do + resource.mailto "test@example.com" + expect(resource.mailto).to eql("test@example.com") end - it "should allow you to specify the mailto variable" do - @resource.mailto "test@example.com" - expect(@resource.mailto).to eql("test@example.com") + it "allows you to specify the path" do + resource.path "/usr/bin:/usr/sbin" + expect(resource.path).to eql("/usr/bin:/usr/sbin") end - it "should allow you to specify the path" do - @resource.path "/usr/bin:/usr/sbin" - expect(@resource.path).to eql("/usr/bin:/usr/sbin") + it "allows you to specify the home directory" do + resource.home "/root" + expect(resource.home).to eql("/root") end - it "should allow you to specify the home directory" do - @resource.home "/root" - expect(@resource.home).to eql("/root") + it "allows you to specify the shell to run the command with" do + resource.shell "/bin/zsh" + expect(resource.shell).to eql("/bin/zsh") end - it "should allow you to specify the shell to run the command with" do - @resource.shell "/bin/zsh" - expect(@resource.shell).to eql("/bin/zsh") - end - - it "should allow you to specify environment variables hash" do + it "allows you to specify environment variables hash" do env = { "TEST" => "LOL" } - @resource.environment env - expect(@resource.environment).to eql(env) + resource.environment env + expect(resource.environment).to eql(env) end - it "should allow * for all time and date values" do + it "allows * for all time and date values" do %w{minute hour day month weekday}.each do |x| - expect(@resource.send(x, "*")).to eql("*") + expect(resource.send(x, "*")).to eql("*") end end - it "should allow ranges for all time and date values" do + it "allows ranges for all time and date values" do %w{minute hour day month weekday}.each do |x| - expect(@resource.send(x, "1-2,5")).to eql("1-2,5") + expect(resource.send(x, "1-2,5")).to eql("1-2,5") end end - it "should have a default value of * for all time and date values" do + it "has a default value of * for all time and date values" do %w{minute hour day month weekday}.each do |x| - expect(@resource.send(x)).to eql("*") + expect(resource.send(x)).to eql("*") end end - it "should have a default value of root for the user" do - expect(@resource.user).to eql("root") + it "has a default value of root for the user" do + expect(resource.user).to eql("root") end - it "should reject any minute over 59" do - expect { @resource.minute "60" }.to raise_error(RangeError) + it "rejects any minute over 59" do + expect { resource.minute "60" }.to raise_error(RangeError) end - it "should reject any hour over 23" do - expect { @resource.hour "24" }.to raise_error(RangeError) + it "rejects any hour over 23" do + expect { resource.hour "24" }.to raise_error(RangeError) end - it "should reject any day over 31" do - expect { @resource.day "32" }.to raise_error(RangeError) + it "rejects any day over 31" do + expect { resource.day "32" }.to raise_error(RangeError) end - it "should reject any month over 12" do - expect { @resource.month "13" }.to raise_error(RangeError) + it "rejects any month over 12" do + expect { resource.month "13" }.to raise_error(RangeError) end describe "weekday" do - it "should reject any weekday over 7" do - expect { @resource.weekday "8" }.to raise_error(RangeError) + it "rejects any weekday over 7" do + expect { resource.weekday "8" }.to raise_error(RangeError) end - it "should reject any symbols which don't represent day of week" do - expect { @resource.weekday :foo }.to raise_error(RangeError) + it "rejects any symbols which don't represent day of week" do + expect { resource.weekday :foo }.to raise_error(RangeError) end end - it "should convert integer schedule values to a string" do + it "converts integer schedule values to a string" do %w{minute hour day month weekday}.each do |x| - expect(@resource.send(x, 5)).to eql("5") + expect(resource.send(x, 5)).to eql("5") end end describe "when it has a time (minute, hour, day, month, weeekend) and user" do before do - @resource.command("tackle") - @resource.minute("1") - @resource.hour("2") - @resource.day("3") - @resource.month("4") - @resource.weekday("5") - @resource.user("root") + resource.command("tackle") + resource.minute("1") + resource.hour("2") + resource.day("3") + resource.month("4") + resource.weekday("5") + resource.user("root") end it "describes the state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:minute]).to eq("1") expect(state[:hour]).to eq("2") expect(state[:day]).to eq("3") @@ -180,7 +177,7 @@ describe Chef::Resource::Cron do end it "returns the command as its identity" do - expect(@resource.identity).to eq("tackle") + expect(resource.identity).to eq("tackle") end end end diff --git a/spec/unit/resource/csh_spec.rb b/spec/unit/resource/csh_spec.rb index 864175fc85..05f6f1d3ab 100644 --- a/spec/unit/resource/csh_spec.rb +++ b/spec/unit/resource/csh_spec.rb @@ -20,21 +20,19 @@ require "spec_helper" describe Chef::Resource::Csh do - before(:each) do - @resource = Chef::Resource::Csh.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Csh.new("fakey_fakerton") } - it "should create a new Chef::Resource::Csh" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Csh) + it "creates a new Chef::Resource::Csh" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Csh) end - it "should have a resource name of :csh" do - expect(@resource.resource_name).to eql(:csh) + it "has a resource name of :csh" do + expect(resource.resource_name).to eql(:csh) end - it "should have an interpreter of csh" do - expect(@resource.interpreter).to eql("csh") + it "has an interpreter of csh" do + expect(resource.interpreter).to eql("csh") end end diff --git a/spec/unit/resource/deploy_spec.rb b/spec/unit/resource/deploy_spec.rb index e008d79c29..fe3d6972da 100644 --- a/spec/unit/resource/deploy_spec.rb +++ b/spec/unit/resource/deploy_spec.rb @@ -248,7 +248,7 @@ describe Chef::Resource::Deploy do end describe "when it has no timeout attribute" do - it "should have no default timeout" do + it "has no default timeout" do expect(@resource.timeout).to be_nil end end diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb index b3a0134024..5d1e24cbb0 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/spec/unit/resource/directory_spec.rb @@ -20,63 +20,60 @@ require "spec_helper" describe Chef::Resource::Directory do + let(:resource) { Chef::Resource::Directory.new("fakey_fakerton") } - before(:each) do - @resource = Chef::Resource::Directory.new("fakey_fakerton") + it "creates a new Chef::Resource::Directory" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Directory) end - it "should create a new Chef::Resource::Directory" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Directory) + it "has a name" do + expect(resource.name).to eql("fakey_fakerton") end - it "should have a name" do - expect(@resource.name).to eql("fakey_fakerton") + it "has a default action of 'create'" do + expect(resource.action).to eql([:create]) end - it "should have a default action of 'create'" do - expect(@resource.action).to eql([:create]) + it "accepts create or delete for action" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :blues }.to raise_error(ArgumentError) end - it "should accept create or delete for action" do - expect { @resource.action :create }.not_to raise_error - expect { @resource.action :delete }.not_to raise_error - expect { @resource.action :blues }.to raise_error(ArgumentError) + it "uses the object name as the path by default" do + expect(resource.path).to eql("fakey_fakerton") end - it "should use the object name as the path by default" do - expect(@resource.path).to eql("fakey_fakerton") + it "accepts a string as the path" do + expect { resource.path "/tmp" }.not_to raise_error + expect(resource.path).to eql("/tmp") + expect { resource.path Hash.new }.to raise_error(ArgumentError) end - it "should accept a string as the path" do - expect { @resource.path "/tmp" }.not_to raise_error - expect(@resource.path).to eql("/tmp") - expect { @resource.path Hash.new }.to raise_error(ArgumentError) - end - - it "should allow you to have specify whether the action is recursive with true/false" do - expect { @resource.recursive true }.not_to raise_error - expect { @resource.recursive false }.not_to raise_error - expect { @resource.recursive "monkey" }.to raise_error(ArgumentError) + it "allows you to have specify whether the action is recursive with true/false" do + expect { resource.recursive true }.not_to raise_error + expect { resource.recursive false }.not_to raise_error + expect { resource.recursive "monkey" }.to raise_error(ArgumentError) end describe "when it has group, mode, and owner" do before do - @resource.path("/tmp/foo/bar/") - @resource.group("wheel") - @resource.mode("0664") - @resource.owner("root") + resource.path("/tmp/foo/bar/") + resource.group("wheel") + resource.mode("0664") + resource.owner("root") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:group]).to eq("wheel") expect(state[:mode]).to eq("0664") expect(state[:owner]).to eq("root") end it "returns the directory path as its identity" do - expect(@resource.identity).to eq("/tmp/foo/bar/") + expect(resource.identity).to eq("/tmp/foo/bar/") end end end diff --git a/spec/unit/resource/dnf_package_spec.rb b/spec/unit/resource/dnf_package_spec.rb index 0cc673d897..56c7ac7528 100644 --- a/spec/unit/resource/dnf_package_spec.rb +++ b/spec/unit/resource/dnf_package_spec.rb @@ -36,7 +36,7 @@ describe Chef::Resource::DnfPackage, "arch" do @resource = Chef::Resource::DnfPackage.new("foo") end - it "should set the arch variable to whatever is passed in" do + it "sets the arch variable to whatever is passed in" do @resource.arch("i386") expect(@resource.arch).to eql(["i386"]) end @@ -47,40 +47,40 @@ describe Chef::Resource::DnfPackage, "flush_cache" do @resource = Chef::Resource::DnfPackage.new("foo") end - it "should default the flush timing to false" do + it "defaults the flush timing to false" do flush_hash = { :before => false, :after => false } expect(@resource.flush_cache).to eq(flush_hash) end - it "should allow you to set the flush timing with an array" do + it "allows you to set the flush timing with an array" do flush_array = [ :before, :after ] flush_hash = { :before => true, :after => true } @resource.flush_cache(flush_array) expect(@resource.flush_cache).to eq(flush_hash) end - it "should allow you to set the flush timing with a hash" do + it "allows you to set the flush timing with a hash" do flush_hash = { :before => true, :after => true } @resource.flush_cache(flush_hash) expect(@resource.flush_cache).to eq(flush_hash) end - it "should allow 'true' for flush_cache" do + it "allows 'true' for flush_cache" do @resource.flush_cache(true) expect(@resource.flush_cache).to eq({ before: true, after: true }) end - it "should allow 'false' for flush_cache" do + it "allows 'false' for flush_cache" do @resource.flush_cache(false) expect(@resource.flush_cache).to eq({ before: false, after: false }) end - it "should allow ':before' for flush_cache" do + it "allows ':before' for flush_cache" do @resource.flush_cache(:before) expect(@resource.flush_cache).to eq({ before: true, after: false }) end - it "should allow ':after' for flush_cache" do + it "allows ':after' for flush_cache" do @resource.flush_cache(:after) expect(@resource.flush_cache).to eq({ before: false, after: true }) end @@ -91,7 +91,7 @@ describe Chef::Resource::DnfPackage, "allow_downgrade" do @resource = Chef::Resource::DnfPackage.new("foo") end - it "should allow you to specify whether allow_downgrade is true or false" do + it "allows you to specify whether allow_downgrade is true or false" do Chef::Config[:treat_deprecation_warnings_as_errors] = false expect { @resource.allow_downgrade true }.not_to raise_error expect { @resource.allow_downgrade false }.not_to raise_error diff --git a/spec/unit/resource/env_spec.rb b/spec/unit/resource/env_spec.rb index 1c63ab519f..c16a828e3b 100644 --- a/spec/unit/resource/env_spec.rb +++ b/spec/unit/resource/env_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Env do @resource = Chef::Resource::Env.new("FOO") end - it "should create a new Chef::Resource::Env" do + it "creates a new Chef::Resource::Env" do expect(@resource).to be_a_kind_of(Chef::Resource) expect(@resource).to be_a_kind_of(Chef::Resource::Env) end - it "should have a name" do + it "has a name" do expect(@resource.name).to eql("FOO") end - it "should have a default action of 'create'" do + it "has a default action of 'create'" do expect(@resource.action).to eql([:create]) end @@ -48,19 +48,19 @@ describe Chef::Resource::Env do end end - it "should use the object name as the key_name by default" do + it "uses the object name as the key_name by default" do expect(@resource.key_name).to eql("FOO") end - it "should accept a string as the env value via 'value'" do + it "accepts a string as the env value via 'value'" do expect { @resource.value "bar" }.not_to raise_error end - it "should not accept a Hash for the env value via 'to'" do + it "does not accept a Hash for the env value via 'to'" do expect { @resource.value Hash.new }.to raise_error(ArgumentError) end - it "should allow you to set an env value via 'to'" do + it "allows you to set an env value via 'to'" do @resource.value "bar" expect(@resource.value).to eql("bar") end diff --git a/spec/unit/resource/erl_call_spec.rb b/spec/unit/resource/erl_call_spec.rb index 6d1f45ec63..06d8b83651 100644 --- a/spec/unit/resource/erl_call_spec.rb +++ b/spec/unit/resource/erl_call_spec.rb @@ -25,44 +25,44 @@ describe Chef::Resource::ErlCall do @resource = Chef::Resource::ErlCall.new("fakey_fakerton") end - it "should create a new Chef::Resource::ErlCall" do + it "creates a new Chef::Resource::ErlCall" do expect(@resource).to be_a_kind_of(Chef::Resource) expect(@resource).to be_a_kind_of(Chef::Resource::ErlCall) end - it "should have a resource name of :erl_call" do + it "has a resource name of :erl_call" do expect(@resource.resource_name).to eql(:erl_call) end - it "should have a default action of run" do + it "has a default action of run" do expect(@resource.action).to eql([:run]) end - it "should accept run as an action" do + it "accepts run as an action" do expect { @resource.action :run }.not_to raise_error end - it "should allow you to set the code attribute" do + it "allows you to set the code attribute" do @resource.code "q()." expect(@resource.code).to eql("q().") end - it "should allow you to set the cookie attribute" do + it "allows you to set the cookie attribute" do @resource.cookie "nomnomnom" expect(@resource.cookie).to eql("nomnomnom") end - it "should allow you to set the distributed attribute" do + it "allows you to set the distributed attribute" do @resource.distributed true expect(@resource.distributed).to eql(true) end - it "should allow you to set the name_type attribute" do + it "allows you to set the name_type attribute" do @resource.name_type "sname" expect(@resource.name_type).to eql("sname") end - it "should allow you to set the node_name attribute" do + it "allows you to set the node_name attribute" do @resource.node_name "chef@erlang" expect(@resource.node_name).to eql("chef@erlang") end diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb index 575c80ba2f..c99e87b351 100644 --- a/spec/unit/resource/execute_spec.rb +++ b/spec/unit/resource/execute_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::Execute do let(:execute_resource) { Chef::Resource::Execute.new(resource_instance_name) } it_behaves_like "an execute resource" - it "default guard interpreter should be :execute interpreter" do + it "default guard interpreter is :execute interpreter" do expect(execute_resource.guard_interpreter).to be(:execute) end @@ -59,13 +59,13 @@ describe Chef::Resource::Execute do shared_examples_for "it received valid credentials" do describe "the validation method" do - it "should not raise an error" do + it "does not raise an error" do expect { execute_resource.validate_identity_platform(username, password, domain) }.not_to raise_error end end describe "the name qualification method" do - it "should correctly translate the user and domain" do + it "correctly translates the user and domain" do identity = nil expect { identity = execute_resource.qualify_user(username, password, domain) }.not_to raise_error expect(identity[:domain]).to eq(domain) @@ -76,7 +76,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received invalid credentials" do describe "the validation method" do - it "should raise an error" do + it "raises an error" do expect { execute_resource.validate_identity_platform(username, password, domain, elevated) }.to raise_error(ArgumentError) end end @@ -84,7 +84,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received invalid username and domain" do describe "the validation method" do - it "should raise an error" do + it "raises an error" do expect { execute_resource.qualify_user(username, password, domain) }.to raise_error(ArgumentError) end end @@ -92,7 +92,7 @@ describe Chef::Resource::Execute do shared_examples_for "it received credentials that are not valid on the platform" do describe "the validation method" do - it "should raise an error" do + it "raises an error" do expect { execute_resource.validate_identity_platform(username, password, domain) }.to raise_error(Chef::Exceptions::UnsupportedPlatform) end end diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index 4004798dad..9d2ee34aff 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -20,88 +20,86 @@ require "spec_helper" describe Chef::Resource::File do - before(:each) do - @resource = Chef::Resource::File.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::File.new("fakey_fakerton") } - it "should have a name" do - expect(@resource.name).to eql("fakey_fakerton") + it "has a name" do + expect(resource.name).to eql("fakey_fakerton") end - it "should have a default action of 'create'" do - expect(@resource.action).to eql([:create]) + it "has a default action of 'create'" do + expect(resource.action).to eql([:create]) end - it "should have a default content of nil" do - expect(@resource.content).to be_nil + it "has a default content of nil" do + expect(resource.content).to be_nil end - it "should be set to back up 5 files by default" do - expect(@resource.backup).to eql(5) + it "is set to back up 5 files by default" do + expect(resource.backup).to eql(5) end - it "should only accept strings for content" do - expect { @resource.content 5 }.to raise_error(ArgumentError) - expect { @resource.content :foo }.to raise_error(ArgumentError) - expect { @resource.content "hello" => "there" }.to raise_error(ArgumentError) - expect { @resource.content "hi" }.not_to raise_error + it "only accept strings for content" do + expect { resource.content 5 }.to raise_error(ArgumentError) + expect { resource.content :foo }.to raise_error(ArgumentError) + expect { resource.content "hello" => "there" }.to raise_error(ArgumentError) + expect { resource.content "hi" }.not_to raise_error end - it "should only accept false or a number for backup" do - expect { @resource.backup true }.to raise_error(ArgumentError) - expect { @resource.backup false }.not_to raise_error - expect { @resource.backup 10 }.not_to raise_error - expect { @resource.backup "blues" }.to raise_error(ArgumentError) + it "only accept false or a number for backup" do + expect { resource.backup true }.to raise_error(ArgumentError) + expect { resource.backup false }.not_to raise_error + expect { resource.backup 10 }.not_to raise_error + expect { resource.backup "blues" }.to raise_error(ArgumentError) end - it "should accept a sha256 for checksum" do - expect { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.not_to raise_error - expect { @resource.checksum "monkey!" }.to raise_error(ArgumentError) + it "accepts a sha256 for checksum" do + expect { resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.not_to raise_error + expect { resource.checksum "monkey!" }.to raise_error(ArgumentError) end - it "should accept create, delete or touch for action" do - expect { @resource.action :create }.not_to raise_error - expect { @resource.action :delete }.not_to raise_error - expect { @resource.action :touch }.not_to raise_error - expect { @resource.action :blues }.to raise_error(ArgumentError) + it "accepts create, delete or touch for action" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :touch }.not_to raise_error + expect { resource.action :blues }.to raise_error(ArgumentError) end - it "should accept a block, symbol, or string for verify" do - expect { @resource.verify {} }.not_to raise_error - expect { @resource.verify "" }.not_to raise_error - expect { @resource.verify :json }.not_to raise_error - expect { @resource.verify true }.to raise_error(ArgumentError) - expect { @resource.verify false }.to raise_error(ArgumentError) + it "accepts a block, symbol, or string for verify" do + expect { resource.verify {} }.not_to raise_error + expect { resource.verify "" }.not_to raise_error + expect { resource.verify :json }.not_to raise_error + expect { resource.verify true }.to raise_error(ArgumentError) + expect { resource.verify false }.to raise_error(ArgumentError) end - it "should accept multiple verify statements" do - @resource.verify "foo" - @resource.verify "bar" - @resource.verify.length == 2 + it "accepts multiple verify statements" do + resource.verify "foo" + resource.verify "bar" + resource.verify.length == 2 end - it "should use the object name as the path by default" do - expect(@resource.path).to eql("fakey_fakerton") + it "uses the object name as the path by default" do + expect(resource.path).to eql("fakey_fakerton") end - it "should accept a string as the path" do - expect { @resource.path "/tmp" }.not_to raise_error - expect(@resource.path).to eql("/tmp") - expect { @resource.path Hash.new }.to raise_error(ArgumentError) + it "accepts a string as the path" do + expect { resource.path "/tmp" }.not_to raise_error + expect(resource.path).to eql("/tmp") + expect { resource.path Hash.new }.to raise_error(ArgumentError) end describe "when it has a path, owner, group, mode, and checksum" do before do - @resource.path("/tmp/foo.txt") - @resource.owner("root") - @resource.group("wheel") - @resource.mode("0644") - @resource.checksum("1" * 64) + resource.path("/tmp/foo.txt") + resource.owner("root") + resource.group("wheel") + resource.mode("0644") + resource.checksum("1" * 64) end context "on unix", :unix_only do it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:owner]).to eq("root") expect(state[:group]).to eq("wheel") expect(state[:mode]).to eq("0644") @@ -110,21 +108,20 @@ describe Chef::Resource::File do end it "returns the file path as its identity" do - expect(@resource.identity).to eq("/tmp/foo.txt") + expect(resource.identity).to eq("/tmp/foo.txt") end end describe "when access controls are set on windows", :windows_only => true do before do - @resource.rights :read, "Everyone" - @resource.rights :full_control, "DOMAIN\User" + resource.rights :read, "Everyone" + resource.rights :full_control, "DOMAIN\User" end it "describes its state including windows ACL attributes" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:rights]).to eq([ { :permissions => :read, :principals => "Everyone" }, { :permissions => :full_control, :principals => "DOMAIN\User" } ]) end end - end diff --git a/spec/unit/resource/freebsd_package_spec.rb b/spec/unit/resource/freebsd_package_spec.rb index ce4300497e..4c8ac1c395 100644 --- a/spec/unit/resource/freebsd_package_spec.rb +++ b/spec/unit/resource/freebsd_package_spec.rb @@ -30,22 +30,22 @@ describe Chef::Resource::FreebsdPackage do end describe "Initialization" do - it "should return a Chef::Resource::FreebsdPackage" do + it "returns a Chef::Resource::FreebsdPackage" do expect(@resource).to be_a_kind_of(Chef::Resource::FreebsdPackage) end - it "should set the resource_name to :freebsd_package" do + it "sets the resource_name to :freebsd_package" do expect(@resource.resource_name).to eql(:freebsd_package) end - it "should not set the provider" do + it "does not set the provider" do expect(@resource.provider).to be_nil end end describe "Assigning provider after creation" do describe "if ports specified as source" do - it "should be Freebsd::Port" do + it "is Freebsd::Port" do @resource.source("ports") @resource.after_created expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Port) @@ -53,7 +53,7 @@ describe Chef::Resource::FreebsdPackage do end describe "if freebsd_version is greater than or equal to 1000017" do - it "should be Freebsd::Pkgng" do + it "is Freebsd::Pkgng" do [1000017, 1000018, 1000500, 1001001, 1100000].each do |freebsd_version| @node.automatic_attrs[:os_version] = freebsd_version @resource.after_created @@ -63,7 +63,7 @@ describe Chef::Resource::FreebsdPackage do end describe "if pkgng enabled" do - it "should be Freebsd::Pkgng" do + it "is Freebsd::Pkgng" do pkg_enabled = OpenStruct.new(:stdout => "yes\n") allow(@resource).to receive(:shell_out!).with("make", "-V", "WITH_PKGNG", :env => nil).and_return(pkg_enabled) @resource.after_created @@ -72,7 +72,7 @@ describe Chef::Resource::FreebsdPackage do end describe "if freebsd_version is less than 1000017 and pkgng not enabled" do - it "should be Freebsd::Pkg" do + it "is Freebsd::Pkg" do pkg_enabled = OpenStruct.new(:stdout => "\n") allow(@resource).to receive(:shell_out!).with("make", "-V", "WITH_PKGNG", :env => nil).and_return(pkg_enabled) diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb index a1571ab9bb..7caf248ad8 100644 --- a/spec/unit/resource/gem_package_spec.rb +++ b/spec/unit/resource/gem_package_spec.rb @@ -35,7 +35,7 @@ describe Chef::Resource::GemPackage, "gem_binary" do @resource = Chef::Resource::GemPackage.new("foo") end - it "should set the gem_binary variable to whatever is passed in" do + it "sets the gem_binary variable to whatever is passed in" do @resource.gem_binary("/opt/local/bin/gem") expect(@resource.gem_binary).to eql("/opt/local/bin/gem") end diff --git a/spec/unit/resource/git_spec.rb b/spec/unit/resource/git_spec.rb index 15c1e54f25..be2592432b 100644 --- a/spec/unit/resource/git_spec.rb +++ b/spec/unit/resource/git_spec.rb @@ -28,23 +28,21 @@ describe Chef::Resource::Git do action: :sync ) - before(:each) do - @git = Chef::Resource::Git.new("my awesome webapp") - end + let(:resource) { Chef::Resource::Git.new("my awesome webapp") } it "is a kind of Scm Resource" do - expect(@git).to be_a_kind_of(Chef::Resource::Scm) - expect(@git).to be_an_instance_of(Chef::Resource::Git) + expect(resource).to be_a_kind_of(Chef::Resource::Scm) + expect(resource).to be_an_instance_of(Chef::Resource::Git) end it "uses aliases revision as branch" do - @git.branch "HEAD" - expect(@git.revision).to eql("HEAD") + resource.branch "HEAD" + expect(resource.revision).to eql("HEAD") end it "aliases revision as reference" do - @git.reference "v1.0 tag" - expect(@git.revision).to eql("v1.0 tag") + resource.reference "v1.0 tag" + expect(resource.revision).to eql("v1.0 tag") end end diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 8772f37a2b..6d9610e99d 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -20,143 +20,133 @@ require "spec_helper" describe Chef::Resource::Group, "initialize" do - before(:each) do - @resource = Chef::Resource::Group.new("admin") - end + let(:resource) { Chef::Resource::Group.new("admin") } - it "should create a new Chef::Resource::Group" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Group) + it "creates a new Chef::Resource::Group" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Group) end - it "should set the resource_name to :group" do - expect(@resource.resource_name).to eql(:group) + it "sets the resource_name to :group" do + expect(resource.resource_name).to eql(:group) end - it "should set the group_name equal to the argument to initialize" do - expect(@resource.group_name).to eql("admin") + it "sets the group_name equal to the argument to initialize" do + expect(resource.group_name).to eql("admin") end - it "should default gid to nil" do - expect(@resource.gid).to eql(nil) + it "defaults gid to nil" do + expect(resource.gid).to eql(nil) end - it "should default members to an empty array" do - expect(@resource.members).to eql([]) + it "defaults members to an empty array" do + expect(resource.members).to eql([]) end - it "should alias users to members, also an empty array" do - expect(@resource.users).to eql([]) + it "aliases users to members, also an empty array" do + expect(resource.users).to eql([]) end - it "should set action to :create" do - expect(@resource.action).to eql([:create]) + it "sets action to :create" do + expect(resource.action).to eql([:create]) end %w{create remove modify manage}.each do |action| - it "should allow action #{action}" do - expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) + it "allows action #{action}" do + expect(resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end - it "should accept domain groups (@ or \ separator) on non-windows" do - expect { @resource.group_name "domain\@group" }.not_to raise_error - expect(@resource.group_name).to eq("domain\@group") - expect { @resource.group_name "domain\\group" }.not_to raise_error - expect(@resource.group_name).to eq("domain\\group") - expect { @resource.group_name "domain\\group^name" }.not_to raise_error - expect(@resource.group_name).to eq("domain\\group^name") + it "accepts domain groups (@ or \ separator) on non-windows" do + expect { resource.group_name "domain\@group" }.not_to raise_error + expect(resource.group_name).to eq("domain\@group") + expect { resource.group_name "domain\\group" }.not_to raise_error + expect(resource.group_name).to eq("domain\\group") + expect { resource.group_name "domain\\group^name" }.not_to raise_error + expect(resource.group_name).to eq("domain\\group^name") end end describe Chef::Resource::Group, "group_name" do - before(:each) do - @resource = Chef::Resource::Group.new("admin") - end + let(:resource) { Chef::Resource::Group.new("admin") } - it "should allow a string" do - @resource.group_name "pirates" - expect(@resource.group_name).to eql("pirates") + it "allows a string" do + resource.group_name "pirates" + expect(resource.group_name).to eql("pirates") end - it "should not allow a hash" do - expect { @resource.send(:group_name, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(:group_name, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end describe Chef::Resource::Group, "gid" do - before(:each) do - @resource = Chef::Resource::Group.new("admin") - end + let(:resource) { Chef::Resource::Group.new("admin") } - it "should allow an integer" do - @resource.gid 100 - expect(@resource.gid).to eql(100) + it "allows an integer" do + resource.gid 100 + expect(resource.gid).to eql(100) end - it "should not allow a hash" do - expect { @resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end describe Chef::Resource::Group, "members" do - before(:each) do - @resource = Chef::Resource::Group.new("admin") - end + let(:resource) { Chef::Resource::Group.new("admin") } [ :users, :members].each do |method| - it "(#{method}) should allow and convert a string" do - @resource.send(method, "aj") - expect(@resource.send(method)).to eql(["aj"]) + it "(#{method}) allows and convert a string" do + resource.send(method, "aj") + expect(resource.send(method)).to eql(["aj"]) end it "(#{method}) should split a string on commas" do - @resource.send(method, "aj,adam") - expect(@resource.send(method)).to eql( %w{aj adam} ) + resource.send(method, "aj,adam") + expect(resource.send(method)).to eql( %w{aj adam} ) end - it "(#{method}) should allow an array" do - @resource.send(method, %w{aj adam}) - expect(@resource.send(method)).to eql( %w{aj adam} ) + it "(#{method}) allows an array" do + resource.send(method, %w{aj adam}) + expect(resource.send(method)).to eql( %w{aj adam} ) end - it "(#{method}) should not allow a hash" do - expect { @resource.send(method, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) + it "(#{method}) does not allow a hash" do + expect { resource.send(method, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end end describe Chef::Resource::Group, "append" do - before(:each) do - @resource = Chef::Resource::Group.new("admin") - end + let(:resource) { Chef::Resource::Group.new("admin") } - it "should default to false" do - expect(@resource.append).to eql(false) + it "defaults to false" do + expect(resource.append).to eql(false) end - it "should allow a boolean" do - @resource.append true - expect(@resource.append).to eql(true) + it "allows a boolean" do + resource.append true + expect(resource.append).to eql(true) end - it "should not allow a hash" do - expect { @resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end describe "when it has members" do before do - @resource.group_name("pokemon") - @resource.members(%w{blastoise pikachu}) + resource.group_name("pokemon") + resource.members(%w{blastoise pikachu}) end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:members]).to eql(%w{blastoise pikachu}) end it "returns the group name as its identity" do - expect(@resource.identity).to eq("pokemon") + expect(resource.identity).to eq("pokemon") end end end diff --git a/spec/unit/resource/http_request_spec.rb b/spec/unit/resource/http_request_spec.rb index 318a154b88..9f6f674a5b 100644 --- a/spec/unit/resource/http_request_spec.rb +++ b/spec/unit/resource/http_request_spec.rb @@ -20,39 +20,36 @@ require "spec_helper" describe Chef::Resource::HttpRequest do + let(:resource) { Chef::Resource::HttpRequest.new("fakey_fakerton") } - before(:each) do - @resource = Chef::Resource::HttpRequest.new("fakey_fakerton") + it "creates a new Chef::Resource::HttpRequest" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::HttpRequest) end - it "should create a new Chef::Resource::HttpRequest" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::HttpRequest) + it "sets url to a string" do + resource.url "http://slashdot.org" + expect(resource.url).to eql("http://slashdot.org") end - it "should set url to a string" do - @resource.url "http://slashdot.org" - expect(@resource.url).to eql("http://slashdot.org") + it "sets the message to the name by default" do + expect(resource.message).to eql("fakey_fakerton") end - it "should set the message to the name by default" do - expect(@resource.message).to eql("fakey_fakerton") - end - - it "should set message to a string" do - @resource.message "monkeybars" - expect(@resource.message).to eql("monkeybars") + it "sets message to a string" do + resource.message "monkeybars" + expect(resource.message).to eql("monkeybars") end describe "when it has a message and headers" do before do - @resource.url("http://www.trololol.net") - @resource.message("Get sum post brah.") - @resource.headers({ "head" => "tail" }) + resource.url("http://www.trololol.net") + resource.message("Get sum post brah.") + resource.headers({ "head" => "tail" }) end it "returns the url as its identity" do - expect(@resource.identity).to eq("http://www.trololol.net") + expect(resource.identity).to eq("http://www.trololol.net") end end diff --git a/spec/unit/resource/ifconfig_spec.rb b/spec/unit/resource/ifconfig_spec.rb index 699ebf1233..3221d0b864 100644 --- a/spec/unit/resource/ifconfig_spec.rb +++ b/spec/unit/resource/ifconfig_spec.rb @@ -55,7 +55,7 @@ describe Chef::Resource::Ifconfig do @node.automatic_attrs[:platform_version] = version end - it "should use an ordinary Provider::Ifconfig as a provider for #{platform} #{version}" do + it "uses an ordinary Provider::Ifconfig as a provider for #{platform} #{version}" do expect(@resource.provider_for_action(:add).class).to eq(Chef::Provider::Ifconfig) end end @@ -68,7 +68,7 @@ describe Chef::Resource::Ifconfig do @node.automatic_attrs[:platform_version] = version end - it "should use an Provider::Ifconfig::Redhat as a provider for #{platform} #{version}" do + it "uses an Provider::Ifconfig::Redhat as a provider for #{platform} #{version}" do expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig::Redhat) end end @@ -81,7 +81,7 @@ describe Chef::Resource::Ifconfig do @node.automatic_attrs[:platform_version] = version end - it "should use an Ifconfig::Debian as a provider for #{platform} #{version}" do + it "uses an Ifconfig::Debian as a provider for #{platform} #{version}" do expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig::Debian) end end diff --git a/spec/unit/resource/ips_package_spec.rb b/spec/unit/resource/ips_package_spec.rb index fd1fe2840c..09f9c5d880 100644 --- a/spec/unit/resource/ips_package_spec.rb +++ b/spec/unit/resource/ips_package_spec.rb @@ -29,12 +29,10 @@ describe Chef::Resource::IpsPackage, "initialize" do os: "solaris2" ) - before(:each) do - @resource = Chef::Resource::IpsPackage.new("crypto/gnupg") - end + let(:resource) { Chef::Resource::IpsPackage.new("crypto/gnupg") } it "should support accept_license" do - @resource.accept_license(true) - expect(@resource.accept_license).to eql(true) + resource.accept_license(true) + expect(resource.accept_license).to eql(true) end end diff --git a/spec/unit/resource/ksh_spec.rb b/spec/unit/resource/ksh_spec.rb index 6c3ba291b4..76128e1c57 100644 --- a/spec/unit/resource/ksh_spec.rb +++ b/spec/unit/resource/ksh_spec.rb @@ -20,21 +20,19 @@ require "spec_helper" describe Chef::Resource::Ksh do - before(:each) do - @resource = Chef::Resource::Ksh.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Ksh.new("fakey_fakerton") } - it "should create a new Chef::Resource::Ksh" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Ksh) + it "creates a new Chef::Resource::Ksh" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Ksh) end - it "should have a resource name of :ksh" do - expect(@resource.resource_name).to eql(:ksh) + it "has a resource name of :ksh" do + expect(resource.resource_name).to eql(:ksh) end - it "should have an interpreter of ksh" do - expect(@resource.interpreter).to eql("ksh") + it "has an interpreter of ksh" do + expect(resource.interpreter).to eql("ksh") end end diff --git a/spec/unit/resource/launchd_spec.rb b/spec/unit/resource/launchd_spec.rb index 98d21a8234..7c8f7c46a4 100644 --- a/spec/unit/resource/launchd_spec.rb +++ b/spec/unit/resource/launchd_spec.rb @@ -1,29 +1,36 @@ # +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# require "spec_helper" describe Chef::Resource::Launchd do - @launchd = Chef::Resource::Launchd.new("io.chef.chef-client") - let(:resource) do - Chef::Resource::Launchd.new( - "io.chef.chef-client", - run_context - ) end + let(:resource) { Chef::Resource::Launchd.new("io.chef.chef-client" ) } - it "should create a new Chef::Resource::Launchd" do + it "creates a new Chef::Resource::Launchd" do expect(resource).to be_a_kind_of(Chef::Resource) expect(resource).to be_a_kind_of(Chef::Resource::Launchd) end - it "should have a resource name of Launchd" do + it "has a resource name of Launchd" do expect(resource.resource_name).to eql(:launchd) end - it "should have a default action of create" do + it "has a default action of create" do expect(resource.action).to eql([:create]) end - it "should accept enable, disable, create, and delete as actions" do + it "accepts enable, disable, create, and delete as actions" do expect { resource.action :enable }.not_to raise_error expect { resource.action :disable }.not_to raise_error expect { resource.action :create }.not_to raise_error diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index adfd0020f5..2006aa55e3 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -20,115 +20,115 @@ require "spec_helper" describe Chef::Resource::Link do + let(:resource) { Chef::Resource::Link.new("fakey_fakerton") } before(:each) do expect_any_instance_of(Chef::Resource::Link).to receive(:verify_links_supported!).and_return(true) - @resource = Chef::Resource::Link.new("fakey_fakerton") end - it "should create a new Chef::Resource::Link" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Link) + it "creates a new Chef::Resource::Link" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Link) end - it "should have a name" do - expect(@resource.name).to eql("fakey_fakerton") + it "has a name" do + expect(resource.name).to eql("fakey_fakerton") end - it "should have a default action of 'create'" do - expect(@resource.action).to eql([:create]) + it "has a default action of 'create'" do + expect(resource.action).to eql([:create]) end { :create => false, :delete => false, :blues => true }.each do |action, bad_value| it "should #{bad_value ? 'not' : ''} accept #{action}" do if bad_value - expect { @resource.action action }.to raise_error(ArgumentError) + expect { resource.action action }.to raise_error(ArgumentError) else - expect { @resource.action action }.not_to raise_error + expect { resource.action action }.not_to raise_error end end end - it "should use the object name as the target_file by default" do - expect(@resource.target_file).to eql("fakey_fakerton") + it "uses the object name as the target_file by default" do + expect(resource.target_file).to eql("fakey_fakerton") end - it "should accept a delayed evaluator as the target path" do - @resource.target_file Chef::DelayedEvaluator.new { "my_lazy_name" } - expect(@resource.target_file).to eql("my_lazy_name") + it "accepts a delayed evaluator as the target path" do + resource.target_file Chef::DelayedEvaluator.new { "my_lazy_name" } + expect(resource.target_file).to eql("my_lazy_name") end - it "should accept a delayed evaluator when accessing via 'path'" do - @resource.target_file Chef::DelayedEvaluator.new { "my_lazy_name" } - expect(@resource.path).to eql("my_lazy_name") + it "accepts a delayed evaluator when accessing via 'path'" do + resource.target_file Chef::DelayedEvaluator.new { "my_lazy_name" } + expect(resource.path).to eql("my_lazy_name") end - it "should accept a delayed evaluator via 'to'" do - @resource.to Chef::DelayedEvaluator.new { "my_lazy_name" } - expect(@resource.to).to eql("my_lazy_name") + it "accepts a delayed evaluator via 'to'" do + resource.to Chef::DelayedEvaluator.new { "my_lazy_name" } + expect(resource.to).to eql("my_lazy_name") end - it "should accept a string as the link source via 'to'" do - expect { @resource.to "/tmp" }.not_to raise_error + it "accepts a string as the link source via 'to'" do + expect { resource.to "/tmp" }.not_to raise_error end - it "should not accept a Hash for the link source via 'to'" do - expect { @resource.to Hash.new }.to raise_error(ArgumentError) + it "does not accept a Hash for the link source via 'to'" do + expect { resource.to Hash.new }.to raise_error(ArgumentError) end - it "should allow you to set a link source via 'to'" do - @resource.to "/tmp/foo" - expect(@resource.to).to eql("/tmp/foo") + it "allows you to set a link source via 'to'" do + resource.to "/tmp/foo" + expect(resource.to).to eql("/tmp/foo") end - it "should allow you to specify the link type" do - @resource.link_type "symbolic" - expect(@resource.link_type).to eql(:symbolic) + it "allows you to specify the link type" do + resource.link_type "symbolic" + expect(resource.link_type).to eql(:symbolic) end - it "should default to a symbolic link" do - expect(@resource.link_type).to eql(:symbolic) + it "defaults to a symbolic link" do + expect(resource.link_type).to eql(:symbolic) end - it "should accept a hard link_type" do - @resource.link_type :hard - expect(@resource.link_type).to eql(:hard) + it "accepts a hard link_type" do + resource.link_type :hard + expect(resource.link_type).to eql(:hard) end - it "should reject any other link_type but :hard and :symbolic" do - expect { @resource.link_type "x-men" }.to raise_error(ArgumentError) + it "rejects any other link_type but :hard and :symbolic" do + expect { resource.link_type "x-men" }.to raise_error(ArgumentError) end - it "should accept a group name or id for group" do - expect { @resource.group "root" }.not_to raise_error - expect { @resource.group 123 }.not_to raise_error - expect { @resource.group "root:goo" }.to raise_error(ArgumentError) + it "accepts a group name or id for group" do + expect { resource.group "root" }.not_to raise_error + expect { resource.group 123 }.not_to raise_error + expect { resource.group "root:goo" }.to raise_error(ArgumentError) end - it "should accept a user name or id for owner" do - expect { @resource.owner "root" }.not_to raise_error - expect { @resource.owner 123 }.not_to raise_error - expect { @resource.owner "root:goo" }.to raise_error(ArgumentError) + it "accepts a user name or id for owner" do + expect { resource.owner "root" }.not_to raise_error + expect { resource.owner 123 }.not_to raise_error + expect { resource.owner "root:goo" }.to raise_error(ArgumentError) end describe "when it has to, link_type, owner, and group" do before do - @resource.target_file("/var/target.tar") - @resource.to("/to/dir/file.tar") - @resource.link_type(:symbolic) - @resource.owner("root") - @resource.group("0664") + resource.target_file("/var/target.tar") + resource.to("/to/dir/file.tar") + resource.link_type(:symbolic) + resource.owner("root") + resource.group("0664") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:to]).to eq("/to/dir/file.tar") expect(state[:owner]).to eq("root") expect(state[:group]).to eq("0664") end it "returns the target file as its identity" do - expect(@resource.identity).to eq("/var/target.tar") + expect(resource.identity).to eq("/var/target.tar") end end end diff --git a/spec/unit/resource/log_spec.rb b/spec/unit/resource/log_spec.rb index 18a1eb65bf..4459762687 100644 --- a/spec/unit/resource/log_spec.rb +++ b/spec/unit/resource/log_spec.rb @@ -21,53 +21,49 @@ require "spec_helper" describe Chef::Resource::Log do - before(:each) do - @log_str = "this is my string to log" - @resource = Chef::Resource::Log.new(@log_str) - end + let(:log_str) { "this is my string to log" } + let(:resource) { Chef::Resource::Log.new(log_str) } - it "should create a new Chef::Resource::Log" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Log) + it "creates a new Chef::Resource::Log" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Log) end it "supports the :write actions" do - expect(@resource.allowed_actions).to include(:write) + expect(resource.allowed_actions).to include(:write) end - it "should have a name of log" do - expect(@resource.resource_name).to eq(:log) + it "has a name of log" do + expect(resource.resource_name).to eq(:log) end - it "should allow you to set a log string" do - expect(@resource.name).to eq(@log_str) + it "allows you to set a log string" do + expect(resource.name).to eq(log_str) end - it "should set the message to the first argument to new" do - expect(@resource.message).to eq(@log_str) + it "sets the message to the first argument to new" do + expect(resource.message).to eq(log_str) end - it "should accept a string for the log message" do - @resource.message "this is different" - expect(@resource.message).to eq("this is different") + it "accepts a string for the log message" do + resource.message "this is different" + expect(resource.message).to eq("this is different") end - it "should accept a vaild level option" do - @resource.level :debug - @resource.level :info - @resource.level :warn - @resource.level :error - @resource.level :fatal - expect { @resource.level :unsupported }.to raise_error(ArgumentError) + it "accepts a vaild level option" do + resource.level :debug + resource.level :info + resource.level :warn + resource.level :error + resource.level :fatal + expect { resource.level :unsupported }.to raise_error(ArgumentError) end describe "when the identity is defined" do - before do - @resource = Chef::Resource::Log.new("ery day I'm loggin-in") - end + let(:resource) { Chef::Resource::Log.new("ery day I'm loggin-in") } it "returns the log string as its identity" do - expect(@resource.identity).to eq("ery day I'm loggin-in") + expect(resource.identity).to eq("ery day I'm loggin-in") end end end diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index f3cadbe499..d31b4cb486 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -21,86 +21,84 @@ require "spec_helper" describe Chef::Resource::Mdadm do - before(:each) do - @resource = Chef::Resource::Mdadm.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Mdadm.new("fakey_fakerton") } - it "should create a new Chef::Resource::Mdadm" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Mdadm) + it "creates a new Chef::Resource::Mdadm" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Mdadm) end - it "should have a resource name of :mdadm" do - expect(@resource.resource_name).to eql(:mdadm) + it "has a resource name of :mdadm" do + expect(resource.resource_name).to eql(:mdadm) end - it "should have a default action of create" do - expect(@resource.action).to eql([:create]) + it "has a default action of create" do + expect(resource.action).to eql([:create]) end - it "should accept create, assemble, stop as actions" do - expect { @resource.action :create }.not_to raise_error - expect { @resource.action :assemble }.not_to raise_error - expect { @resource.action :stop }.not_to raise_error + it "accepts create, assemble, stop as actions" do + expect { resource.action :create }.not_to raise_error + expect { resource.action :assemble }.not_to raise_error + expect { resource.action :stop }.not_to raise_error end - it "should allow you to set the raid_device attribute" do - @resource.raid_device "/dev/md3" - expect(@resource.raid_device).to eql("/dev/md3") + it "allows you to set the raid_device attribute" do + resource.raid_device "/dev/md3" + expect(resource.raid_device).to eql("/dev/md3") end - it "should allow you to set the chunk attribute" do - @resource.chunk 256 - expect(@resource.chunk).to eql(256) + it "allows you to set the chunk attribute" do + resource.chunk 256 + expect(resource.chunk).to eql(256) end - it "should allow you to set the level attribute" do - @resource.level 1 - expect(@resource.level).to eql(1) + it "allows you to set the level attribute" do + resource.level 1 + expect(resource.level).to eql(1) end - it "should allow you to set the metadata attribute" do - @resource.metadata "1.2" - expect(@resource.metadata).to eql("1.2") + it "allows you to set the metadata attribute" do + resource.metadata "1.2" + expect(resource.metadata).to eql("1.2") end - it "should allow you to set the bitmap attribute" do - @resource.bitmap "internal" - expect(@resource.bitmap).to eql("internal") + it "allows you to set the bitmap attribute" do + resource.bitmap "internal" + expect(resource.bitmap).to eql("internal") end - it "should allow you to set the layout attribute" do - @resource.layout "f2" - expect(@resource.layout).to eql("f2") + it "allows you to set the layout attribute" do + resource.layout "f2" + expect(resource.layout).to eql("f2") end - it "should allow you to set the devices attribute" do - @resource.devices ["/dev/sda", "/dev/sdb"] - expect(@resource.devices).to eql(["/dev/sda", "/dev/sdb"]) + it "allows you to set the devices attribute" do + resource.devices ["/dev/sda", "/dev/sdb"] + expect(resource.devices).to eql(["/dev/sda", "/dev/sdb"]) end - it "should allow you to set the exists attribute" do - @resource.exists true - expect(@resource.exists).to eql(true) + it "allows you to set the exists attribute" do + resource.exists true + expect(resource.exists).to eql(true) end describe "when it has devices, level, and chunk" do before do - @resource.raid_device("raider") - @resource.devices(%w{device1 device2}) - @resource.level(1) - @resource.chunk(42) + resource.raid_device("raider") + resource.devices(%w{device1 device2}) + resource.level(1) + resource.chunk(42) end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:devices]).to eql(%w{device1 device2}) expect(state[:level]).to eq(1) expect(state[:chunk]).to eq(42) end it "returns the raid device as its identity" do - expect(@resource.identity).to eq("raider") + expect(resource.identity).to eq("raider") end end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index caa2e2f65a..da181b7f8c 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -20,189 +20,187 @@ require "spec_helper" describe Chef::Resource::Mount do - before(:each) do - @resource = Chef::Resource::Mount.new("filesystem") - end + let(:resource) { Chef::Resource::Mount.new("filesystem") } - it "should create a new Chef::Resource::Mount" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Mount) + it "creates a new Chef::Resource::Mount" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Mount) end - it "should have a name" do - expect(@resource.name).to eql("filesystem") + it "has a name" do + expect(resource.name).to eql("filesystem") end - it "should set mount_point to the name" do - expect(@resource.mount_point).to eql("filesystem") + it "sets mount_point to the name" do + expect(resource.mount_point).to eql("filesystem") end - it "should have a default action of mount" do - expect(@resource.action).to eql([:mount]) + it "has a default action of mount" do + expect(resource.action).to eql([:mount]) end - it "should accept mount, umount, unmount and remount as actions" do - expect { @resource.action :mount }.not_to raise_error - expect { @resource.action :umount }.not_to raise_error - expect { @resource.action :unmount }.not_to raise_error - expect { @resource.action :remount }.not_to raise_error - expect { @resource.action :brooklyn }.to raise_error(ArgumentError) + it "accepts mount, umount, unmount and remount as actions" do + expect { resource.action :mount }.not_to raise_error + expect { resource.action :umount }.not_to raise_error + expect { resource.action :unmount }.not_to raise_error + expect { resource.action :remount }.not_to raise_error + expect { resource.action :brooklyn }.to raise_error(ArgumentError) end - it "should allow you to set the device attribute" do - @resource.device "/dev/sdb3" - expect(@resource.device).to eql("/dev/sdb3") + it "allows you to set the device attribute" do + resource.device "/dev/sdb3" + expect(resource.device).to eql("/dev/sdb3") end - it "should set fsck_device to '-' by default" do - expect(@resource.fsck_device).to eql("-") + it "sets fsck_device to '-' by default" do + expect(resource.fsck_device).to eql("-") end - it "should allow you to set the fsck_device attribute" do - @resource.fsck_device "/dev/rdsk/sdb3" - expect(@resource.fsck_device).to eql("/dev/rdsk/sdb3") + it "allows you to set the fsck_device attribute" do + resource.fsck_device "/dev/rdsk/sdb3" + expect(resource.fsck_device).to eql("/dev/rdsk/sdb3") end - it "should allow you to set the fstype attribute" do - @resource.fstype "nfs" - expect(@resource.fstype).to eql("nfs") + it "allows you to set the fstype attribute" do + resource.fstype "nfs" + expect(resource.fstype).to eql("nfs") end - it "should allow you to set the dump attribute" do - @resource.dump 1 - expect(@resource.dump).to eql(1) + it "allows you to set the dump attribute" do + resource.dump 1 + expect(resource.dump).to eql(1) end - it "should allow you to set the pass attribute" do - @resource.pass 1 - expect(@resource.pass).to eql(1) + it "allows you to set the pass attribute" do + resource.pass 1 + expect(resource.pass).to eql(1) end - it "should set the options attribute to defaults" do - expect(@resource.options).to eql(["defaults"]) + it "sets the options attribute to defaults" do + expect(resource.options).to eql(["defaults"]) end - it "should allow options to be sent as a string, and convert to array" do - @resource.options "rw,noexec" - expect(@resource.options).to be_a_kind_of(Array) + it "allows options to be sent as a string, and convert to array" do + resource.options "rw,noexec" + expect(resource.options).to be_a_kind_of(Array) end - it "should allow options attribute as an array" do - @resource.options %w{ro nosuid} - expect(@resource.options).to be_a_kind_of(Array) + it "allows options attribute as an array" do + resource.options %w{ro nosuid} + expect(resource.options).to be_a_kind_of(Array) end - it "should allow options to be sent as a delayed evaluator" do - @resource.options Chef::DelayedEvaluator.new { %w{rw noexec} } - expect(@resource.options).to eql(%w{rw noexec}) + it "allows options to be sent as a delayed evaluator" do + resource.options Chef::DelayedEvaluator.new { %w{rw noexec} } + expect(resource.options).to eql(%w{rw noexec}) end - it "should allow options to be sent as a delayed evaluator, and convert to array" do - @resource.options Chef::DelayedEvaluator.new { "rw,noexec" } - expect(@resource.options).to be_a_kind_of(Array) - expect(@resource.options).to eql(%w{rw noexec}) + it "allows options to be sent as a delayed evaluator, and convert to array" do + resource.options Chef::DelayedEvaluator.new { "rw,noexec" } + expect(resource.options).to be_a_kind_of(Array) + expect(resource.options).to eql(%w{rw noexec}) end - it "should accept true for mounted" do - @resource.mounted(true) - expect(@resource.mounted).to eql(true) + it "accepts true for mounted" do + resource.mounted(true) + expect(resource.mounted).to eql(true) end - it "should accept false for mounted" do - @resource.mounted(false) - expect(@resource.mounted).to eql(false) + it "accepts false for mounted" do + resource.mounted(false) + expect(resource.mounted).to eql(false) end - it "should set mounted to false by default" do - expect(@resource.mounted).to eql(false) + it "sets mounted to false by default" do + expect(resource.mounted).to eql(false) end - it "should not accept a string for mounted" do - expect { @resource.mounted("poop") }.to raise_error(ArgumentError) + it "does not accept a string for mounted" do + expect { resource.mounted("poop") }.to raise_error(ArgumentError) end - it "should accept true for enabled" do - @resource.enabled(true) - expect(@resource.enabled).to eql(true) + it "accepts true for enabled" do + resource.enabled(true) + expect(resource.enabled).to eql(true) end - it "should accept false for enabled" do - @resource.enabled(false) - expect(@resource.enabled).to eql(false) + it "accepts false for enabled" do + resource.enabled(false) + expect(resource.enabled).to eql(false) end - it "should set enabled to false by default" do - expect(@resource.enabled).to eql(false) + it "sets enabled to false by default" do + expect(resource.enabled).to eql(false) end - it "should not accept a string for enabled" do - expect { @resource.enabled("poop") }.to raise_error(ArgumentError) + it "does not accept a string for enabled" do + expect { resource.enabled("poop") }.to raise_error(ArgumentError) end - it "should default all feature support to false" do + it "defaults all feature support to false" do support_hash = { :remount => false } - expect(@resource.supports).to eq(support_hash) + expect(resource.supports).to eq(support_hash) end - it "should allow you to set feature support as an array" do + it "allows you to set feature support as an array" do support_array = [ :remount ] support_hash = { :remount => true } - @resource.supports(support_array) - expect(@resource.supports).to eq(support_hash) + resource.supports(support_array) + expect(resource.supports).to eq(support_hash) end - it "should allow you to set feature support as a hash" do + it "allows you to set feature support as a hash" do support_hash = { :remount => true } - @resource.supports(support_hash) - expect(@resource.supports).to eq(support_hash) + resource.supports(support_hash) + expect(resource.supports).to eq(support_hash) end - it "should allow you to set username" do - @resource.username("Administrator") - expect(@resource.username).to eq("Administrator") + it "allows you to set username" do + resource.username("Administrator") + expect(resource.username).to eq("Administrator") end - it "should allow you to set password" do - @resource.password("Jetstream123!") - expect(@resource.password).to eq("Jetstream123!") + it "allows you to set password" do + resource.password("Jetstream123!") + expect(resource.password).to eq("Jetstream123!") end - it "should allow you to set domain" do - @resource.domain("TEST_DOMAIN") - expect(@resource.domain).to eq("TEST_DOMAIN") + it "allows you to set domain" do + resource.domain("TEST_DOMAIN") + expect(resource.domain).to eq("TEST_DOMAIN") end describe "when it has mount point, device type, and fstype" do before do - @resource.device("charmander") - @resource.mount_point("123.456") - @resource.device_type(:device) - @resource.fstype("ranked") + resource.device("charmander") + resource.mount_point("123.456") + resource.device_type(:device) + resource.fstype("ranked") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:mount_point]).to eq("123.456") expect(state[:device_type]).to eql(:device) expect(state[:fstype]).to eq("ranked") end it "returns the device as its identity" do - expect(@resource.identity).to eq("charmander") + expect(resource.identity).to eq("charmander") end end describe "when it has username, password and domain" do before do - @resource.mount_point("T:") - @resource.device("charmander") - @resource.username("Administrator") - @resource.password("Jetstream123!") - @resource.domain("TEST_DOMAIN") + resource.mount_point("T:") + resource.device("charmander") + resource.username("Administrator") + resource.password("Jetstream123!") + resource.domain("TEST_DOMAIN") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:mount_point]).to eq("T:") expect(state[:username]).to eq("Administrator") expect(state[:password]).to eq("*sensitive value suppressed*") diff --git a/spec/unit/resource/ohai_spec.rb b/spec/unit/resource/ohai_spec.rb index 574c09eeba..fdd38ecf39 100644 --- a/spec/unit/resource/ohai_spec.rb +++ b/spec/unit/resource/ohai_spec.rb @@ -20,41 +20,39 @@ require "spec_helper" describe Chef::Resource::Ohai do - before(:each) do - @resource = Chef::Resource::Ohai.new("ohai_reload") - end + let(:resource) { Chef::Resource::Ohai.new("ohai_reload") } - it "should create a new Chef::Resource::Ohai" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Ohai) + it "creates a new Chef::Resource::Ohai" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Ohai) end - it "should have a resource name of :ohai" do - expect(@resource.resource_name).to eql(:ohai) + it "has a resource name of :ohai" do + expect(resource.resource_name).to eql(:ohai) end - it "should have a default action of reload" do - expect(@resource.action).to eql([:reload]) + it "has a default action of reload" do + expect(resource.action).to eql([:reload]) end - it "should allow you to set the plugin attribute" do - @resource.plugin "passwd" - expect(@resource.plugin).to eql("passwd") + it "allows you to set the plugin attribute" do + resource.plugin "passwd" + expect(resource.plugin).to eql("passwd") end describe "when it has a plugin value" do before do - @resource.name("test") - @resource.plugin("passwd") + resource.name("test") + resource.plugin("passwd") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:plugin]).to eq("passwd") end it "returns the name as its identity" do - expect(@resource.identity).to eq("test") + expect(resource.identity).to eq("test") end end diff --git a/spec/unit/resource/openbsd_package_spec.rb b/spec/unit/resource/openbsd_package_spec.rb index 9bdc823576..96b9a5fb2d 100644 --- a/spec/unit/resource/openbsd_package_spec.rb +++ b/spec/unit/resource/openbsd_package_spec.rb @@ -32,15 +32,15 @@ describe Chef::Resource::OpenbsdPackage do end describe "Initialization" do - it "should return a Chef::Resource::OpenbsdPackage" do + it "returns a Chef::Resource::OpenbsdPackage" do expect(@resource).to be_a_kind_of(Chef::Resource::OpenbsdPackage) end - it "should set the resource_name to :openbsd_package" do + it "sets the resource_name to :openbsd_package" do expect(@resource.resource_name).to eql(:openbsd_package) end - it "should not set the provider" do + it "does not set the provider" do expect(@resource.provider).to be_nil end end diff --git a/spec/unit/resource/osx_profile_spec.rb b/spec/unit/resource/osx_profile_spec.rb index 513e570e7c..0399922612 100644 --- a/spec/unit/resource/osx_profile_spec.rb +++ b/spec/unit/resource/osx_profile_spec.rb @@ -25,36 +25,36 @@ describe Chef::Resource::OsxProfile do run_context) end - it "should create a new Chef::Resource::OsxProfile" do + it "creates a new Chef::Resource::OsxProfile" do expect(resource).to be_a_kind_of(Chef::Resource) expect(resource).to be_a_kind_of(Chef::Resource::OsxProfile) end - it "should have a resource name of profile" do + it "has a resource name of profile" do expect(resource.resource_name).to eql(:osx_profile) end - it "should have a default action of install" do + it "has a default action of install" do expect(resource.action).to eql([:install]) end - it "should accept install and remove as actions" do + it "accepts install and remove as actions" do expect { resource.action :install }.not_to raise_error expect { resource.action :remove }.not_to raise_error end - it "should allow you to set the profile attribute" do + it "allows you to set the profile attribute" do resource.profile "com.testprofile.screensaver" expect(resource.profile).to eql("com.testprofile.screensaver") end - it "should allow you to set the profile attribute to a string" do + it "allows you to set the profile attribute to a string" do resource.profile "com.testprofile.screensaver" expect(resource.profile).to be_a(String) expect(resource.profile).to eql("com.testprofile.screensaver") end - it "should allow you to set the profile attribute to a hash" do + it "allows you to set the profile attribute to a hash" do test_profile = { "profile" => false } resource.profile test_profile expect(resource.profile).to be_a(Hash) diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb index 84f92f26b5..72fcb0a180 100644 --- a/spec/unit/resource/package_spec.rb +++ b/spec/unit/resource/package_spec.rb @@ -20,84 +20,80 @@ require "spec_helper" describe Chef::Resource::Package do + let(:resource) { Chef::Resource::Package.new("emacs") } - before(:each) do - @resource = Chef::Resource::Package.new("emacs") + it "creates a new Chef::Resource::Package" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Package) end - it "should create a new Chef::Resource::Package" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Package) + it "sets the package_name to the first argument to new" do + expect(resource.package_name).to eql("emacs") end - it "should set the package_name to the first argument to new" do - expect(@resource.package_name).to eql("emacs") + it "accepts a string for the package name" do + resource.package_name "something" + expect(resource.package_name).to eql("something") end - it "should accept a string for the package name" do - @resource.package_name "something" - expect(@resource.package_name).to eql("something") + it "accepts a string for the version" do + resource.version "something" + expect(resource.version).to eql("something") end - it "should accept a string for the version" do - @resource.version "something" - expect(@resource.version).to eql("something") + it "accepts a string for the response file" do + resource.response_file "something" + expect(resource.response_file).to eql("something") end - it "should accept a string for the response file" do - @resource.response_file "something" - expect(@resource.response_file).to eql("something") + it "accepts a hash for response file template variables" do + resource.response_file_variables({ :variables => true }) + expect(resource.response_file_variables).to eql({ :variables => true }) end - it "should accept a hash for response file template variables" do - @resource.response_file_variables({ :variables => true }) - expect(@resource.response_file_variables).to eql({ :variables => true }) + it "accepts a string for the source" do + resource.source "something" + expect(resource.source).to eql("something") end - it "should accept a string for the source" do - @resource.source "something" - expect(@resource.source).to eql("something") + it "accepts a string for the options" do + resource.options "something" + expect(resource.options).to eql(["something"]) end - it "should accept a string for the options" do - @resource.options "something" - expect(@resource.options).to eql(["something"]) - end - - it "should split options" do - @resource.options "-a -b 'arg with spaces' -b \"and quotes\"" - expect(@resource.options).to eql(["-a", "-b", "arg with spaces", "-b", "and quotes"]) + it "splits options" do + resource.options "-a -b 'arg with spaces' -b \"and quotes\"" + expect(resource.options).to eql(["-a", "-b", "arg with spaces", "-b", "and quotes"]) end describe "when it has a package_name and version" do before do - @resource.package_name("tomcat") - @resource.version("10.9.8") - @resource.options("-al") + resource.package_name("tomcat") + resource.version("10.9.8") + resource.options("-al") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:version]).to eq("10.9.8") expect(state[:options]).to eq(["-al"]) end it "returns the file path as its identity" do - expect(@resource.identity).to eq("tomcat") + expect(resource.identity).to eq("tomcat") end it "takes options as an array" do - @resource.options [ "-a", "-l" ] - expect(@resource.options).to eq(["-a", "-l" ]) + resource.options [ "-a", "-l" ] + expect(resource.options).to eq(["-a", "-l" ]) end end # String, Integer [ "600", 600 ].each do |val| it "supports setting a timeout as a #{val.class}" do - @resource.timeout(val) - expect(@resource.timeout).to eql(val) + resource.timeout(val) + expect(resource.timeout).to eql(val) end end - end diff --git a/spec/unit/resource/perl_spec.rb b/spec/unit/resource/perl_spec.rb index 417d74a8c2..d1af86a90b 100644 --- a/spec/unit/resource/perl_spec.rb +++ b/spec/unit/resource/perl_spec.rb @@ -20,21 +20,18 @@ require "spec_helper" describe Chef::Resource::Perl do - before(:each) do - @resource = Chef::Resource::Perl.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Perl.new("fakey_fakerton") } - it "should create a new Chef::Resource::Perl" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Perl) + it "creates a new Chef::Resource::Perl" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Perl) end - it "should have a resource name of :perl" do - expect(@resource.resource_name).to eql(:perl) + it "has a resource name of :perl" do + expect(resource.resource_name).to eql(:perl) end - it "should have an interpreter of perl" do - expect(@resource.interpreter).to eql("perl") + it "has an interpreter of perl" do + expect(resource.interpreter).to eql("perl") end - end diff --git a/spec/unit/resource/portage_package_spec.rb b/spec/unit/resource/portage_package_spec.rb index d2336744bf..a52e2fb763 100644 --- a/spec/unit/resource/portage_package_spec.rb +++ b/spec/unit/resource/portage_package_spec.rb @@ -16,23 +16,21 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) +require "spec_helper" describe Chef::Resource::PortagePackage, "initialize" do - before(:each) do - @resource = Chef::Resource::PortagePackage.new("foo") - end + let(:resource) { Chef::Resource::PortagePackage.new("foo") } - it "should return a Chef::Resource::PortagePackage" do - expect(@resource).to be_a_kind_of(Chef::Resource::PortagePackage) + it "returns a Chef::Resource::PortagePackage" do + expect(resource).to be_a_kind_of(Chef::Resource::PortagePackage) end - it "should set the resource_name to :portage_package" do - expect(@resource.resource_name).to eql(:portage_package) + it "sets the resource_name to :portage_package" do + expect(resource.resource_name).to eql(:portage_package) end - it "should set the provider to Chef::Provider::Package::Portage" do - expect(@resource.provider).to eql(Chef::Provider::Package::Portage) + it "sets the provider to Chef::Provider::Package::Portage" do + expect(resource.provider).to eql(Chef::Provider::Package::Portage) end end diff --git a/spec/unit/resource/powershell_package_spec.rb b/spec/unit/resource/powershell_package_spec.rb index ff4aa991a7..884d61806f 100644 --- a/spec/unit/resource/powershell_package_spec.rb +++ b/spec/unit/resource/powershell_package_spec.rb @@ -22,46 +22,46 @@ describe Chef::Resource::PowershellPackage do let(:resource) { Chef::Resource::PowershellPackage.new("test_package") } - it "should create a new Chef::Resource::PowershellPackage" do + it "creates a new Chef::Resource::PowershellPackage" do expect(resource).to be_a_kind_of(Chef::Resource) expect(resource).to be_a_kind_of(Chef::Resource::Package) expect(resource).to be_a_instance_of(Chef::Resource::PowershellPackage) end #to check the value of resource.resource_name - it "should have a resource name of :python" do + it "has a resource name of :python" do expect(resource.resource_name).to eql(:powershell_package) end - it "should coerce its name to a package_name array" do + it "coerces its name to a package_name array" do expect(resource.package_name).to eql(["test_package"]) end - it "the package_name setter should coerce to arrays" do + it "the package_name setter coerces to arrays" do resource.package_name("git") expect(resource.package_name).to eql(["git"]) end - it "the package_name setter should accept arrays" do + it "the package_name setter accepts arrays" do resource.package_name(%w{git unzip}) expect(resource.package_name).to eql(%w{git unzip}) end - it "the name should accept arrays" do + it "the name accepts arrays" do resource = Chef::Resource::PowershellPackage.new(%w{git unzip}) expect(resource.package_name).to eql(%w{git unzip}) end - it "the default version should be nil" do + it "the default version is nil" do expect(resource.version).to eql(nil) end - it "the version setter should coerce to arrays" do + it "the version setter coerces to arrays" do resource.version("1.2.3") expect(resource.version).to eql(["1.2.3"]) end - it "the version setter should accept arrays" do + it "the version setter accepts arrays" do resource.version(["1.2.3", "4.5.6"]) expect(resource.version).to eql(["1.2.3", "4.5.6"]) end diff --git a/spec/unit/resource/python_spec.rb b/spec/unit/resource/python_spec.rb index aba84c4000..72b1105ea9 100644 --- a/spec/unit/resource/python_spec.rb +++ b/spec/unit/resource/python_spec.rb @@ -20,21 +20,18 @@ require "spec_helper" describe Chef::Resource::Python do - before(:each) do - @resource = Chef::Resource::Python.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Python.new("fakey_fakerton") } - it "should create a new Chef::Resource::Python" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Python) + it "creates a new Chef::Resource::Python" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Python) end - it "should have a resource name of :python" do - expect(@resource.resource_name).to eql(:python) + it "has a resource name of :python" do + expect(resource.resource_name).to eql(:python) end - it "should have an interpreter of python" do - expect(@resource.interpreter).to eql("python") + it "has an interpreter of python" do + expect(resource.interpreter).to eql("python") end - end diff --git a/spec/unit/resource/reboot_spec.rb b/spec/unit/resource/reboot_spec.rb index 36e9f705a1..4cd959d2db 100644 --- a/spec/unit/resource/reboot_spec.rb +++ b/spec/unit/resource/reboot_spec.rb @@ -19,34 +19,32 @@ require "spec_helper" describe Chef::Resource::Reboot do - before(:each) do - @resource = Chef::Resource::Reboot.new("reboot me!") - end + let(:resource) { Chef::Resource::Reboot.new("reboot me!") } - it "should create a new Chef::Resource::Reboot" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Reboot) + it "creates a new Chef::Resource::Reboot" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Reboot) end - it "should have a default action of :nothing" do - expect(@resource.action).to eql([:nothing]) + it "has a default action of :nothing" do + expect(resource.action).to eql([:nothing]) end it "supports the :nothing, :request_reboot, :reboot_now, and :cancel actions" do - expect(@resource.allowed_actions).to include(:nothing, :request_reboot, :reboot_now, :cancel) + expect(resource.allowed_actions).to include(:nothing, :request_reboot, :reboot_now, :cancel) end - it "should have a resource_name of :reboot" do - expect(@resource.resource_name).to eq(:reboot) + it "has a resource_name of :reboot" do + expect(resource.resource_name).to eq(:reboot) end - it "should accept a String for the reboot reason" do - @resource.reason "reasons" - expect(@resource.reason).to eq("reasons") + it "accepts a String for the reboot reason" do + resource.reason "reasons" + expect(resource.reason).to eq("reasons") end - it "should accept an Integer for delay_mins" do - @resource.delay_mins 100 - expect { @resource.delay_mins "100" }.to raise_error(ArgumentError) + it "accepts an Integer for delay_mins" do + resource.delay_mins 100 + expect { resource.delay_mins "100" }.to raise_error(ArgumentError) end end diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb index 067f2da36a..3fe991aef2 100644 --- a/spec/unit/resource/registry_key_spec.rb +++ b/spec/unit/resource/registry_key_spec.rb @@ -19,197 +19,183 @@ require "spec_helper" describe Chef::Resource::RegistryKey, "initialize" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should create a new Chef::Resource::RegistryKey" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::RegistryKey) + it "creates a new Chef::Resource::RegistryKey" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::RegistryKey) end - it "should set the resource_name to :registry_key" do - expect(@resource.resource_name).to eql(:registry_key) + it "sets the resource_name to :registry_key" do + expect(resource.resource_name).to eql(:registry_key) end - it "should set the key equal to the argument to initialize" do - expect(@resource.key).to eql('HKCU\Software\Raxicoricofallapatorius') + it "sets the key equal to the argument to initialize" do + expect(resource.key).to eql('HKCU\Software\Raxicoricofallapatorius') end - it "should default recursive to false" do - expect(@resource.recursive).to eql(false) + it "defaults recursive to false" do + expect(resource.recursive).to eql(false) end - it "should default architecture to :machine" do - expect(@resource.architecture).to eql(:machine) + it "defaults architecture to :machine" do + expect(resource.architecture).to eql(:machine) end - it "should set action to :create" do - expect(@resource.action).to eql([:create]) + it "sets action to :create" do + expect(resource.action).to eql([:create]) end %w{create create_if_missing delete delete_key}.each do |action| - it "should allow action #{action}" do - expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) + it "allows action #{action}" do + expect(resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end end describe Chef::Resource::RegistryKey, "key" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should allow a string" do - @resource.key 'HKCU\Software\Poosh' - expect(@resource.key).to eql('HKCU\Software\Poosh') + it "allows a string" do + resource.key 'HKCU\Software\Poosh' + expect(resource.key).to eql('HKCU\Software\Poosh') end - it "should not allow an integer" do - expect { @resource.send(:key, 100) }.to raise_error(ArgumentError) + it "does not allow an integer" do + expect { resource.send(:key, 100) }.to raise_error(ArgumentError) end - it "should not allow a hash" do - expect { @resource.send(:key, { :sonic => "screwdriver" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(:key, { :sonic => "screwdriver" }) }.to raise_error(ArgumentError) end end describe Chef::Resource::RegistryKey, "values" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should allow a single proper hash of registry values" do - @resource.values( { :name => "poosh", :type => :string, :data => "carmen" } ) - expect(@resource.values).to eql([ { :name => "poosh", :type => :string, :data => "carmen" } ]) + it "allows a single proper hash of registry values" do + resource.values( { :name => "poosh", :type => :string, :data => "carmen" } ) + expect(resource.values).to eql([ { :name => "poosh", :type => :string, :data => "carmen" } ]) end - it "should allow an array of proper hashes of registry values" do - @resource.values [ { :name => "poosh", :type => :string, :data => "carmen" } ] - expect(@resource.values).to eql([ { :name => "poosh", :type => :string, :data => "carmen" } ]) + it "allows an array of proper hashes of registry values" do + resource.values [ { :name => "poosh", :type => :string, :data => "carmen" } ] + expect(resource.values).to eql([ { :name => "poosh", :type => :string, :data => "carmen" } ]) end - it "should return checksummed data if the type is unsafe" do - @resource.values( { :name => "poosh", :type => :binary, :data => 255.chr * 1 }) - expect(@resource.values).to eql([ { :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" } ]) + it "returns checksummed data if the type is unsafe" do + resource.values( { :name => "poosh", :type => :binary, :data => 255.chr * 1 }) + expect(resource.values).to eql([ { :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" } ]) end - it "should raise an exception if the name field is missing" do - expect { @resource.values [ { :type => :string, :data => "carmen" } ] }.to raise_error(ArgumentError) + it "raises an exception if the name field is missing" do + expect { resource.values [ { :type => :string, :data => "carmen" } ] }.to raise_error(ArgumentError) end - it "should raise an exception if extra fields are present" do - expect { @resource.values [ { :name => "poosh", :type => :string, :data => "carmen", :screwdriver => "sonic" } ] }.to raise_error(ArgumentError) + it "raises an exception if extra fields are present" do + expect { resource.values [ { :name => "poosh", :type => :string, :data => "carmen", :screwdriver => "sonic" } ] }.to raise_error(ArgumentError) end - it "should not allow a string" do - expect { @resource.send(:values, "souffle") }.to raise_error(ArgumentError) + it "does not allow a string" do + expect { resource.send(:values, "souffle") }.to raise_error(ArgumentError) end - it "should not allow an integer" do - expect { @resource.send(:values, 100) }.to raise_error(ArgumentError) + it "does not allow an integer" do + expect { resource.send(:values, 100) }.to raise_error(ArgumentError) end - it "should raise an exception if type of name is not string" do - expect { @resource.values([ { :name => 123, :type => :string, :data => "carmen" } ]) }.to raise_error(ArgumentError) + it "raises an exception if type of name is not string" do + expect { resource.values([ { :name => 123, :type => :string, :data => "carmen" } ]) }.to raise_error(ArgumentError) end - it "should not raise an exception if type of name is string" do - expect { @resource.values([ { :name => "123", :type => :string, :data => "carmen" } ]) }.to_not raise_error + it "does not raise an exception if type of name is string" do + expect { resource.values([ { :name => "123", :type => :string, :data => "carmen" } ]) }.to_not raise_error end context "type key not given" do - it "should not raise an exception" do - expect { @resource.values([ { :name => "123", :data => "carmen" } ]) }.to_not raise_error + it "does not raise an exception" do + expect { resource.values([ { :name => "123", :data => "carmen" } ]) }.to_not raise_error end end context "type key given" do - it "should raise an exception if type of type is not symbol" do - expect { @resource.values([ { :name => "123", :type => "string", :data => "carmen" } ]) }.to raise_error(ArgumentError) + it "raises an exception if type of type is not symbol" do + expect { resource.values([ { :name => "123", :type => "string", :data => "carmen" } ]) }.to raise_error(ArgumentError) end - it "should not raise an exception if type of type is symbol" do - expect { @resource.values([ { :name => "123", :type => :string, :data => "carmen" } ]) }.to_not raise_error + it "does not raise an exception if type of type is symbol" do + expect { resource.values([ { :name => "123", :type => :string, :data => "carmen" } ]) }.to_not raise_error end end end describe Chef::Resource::RegistryKey, "recursive" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should allow a boolean" do - @resource.recursive(true) - expect(@resource.recursive).to eql(true) + it "allows a boolean" do + resource.recursive(true) + expect(resource.recursive).to eql(true) end - it "should not allow a hash" do - expect { @resource.recursive({ :sonic => :screwdriver }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.recursive({ :sonic => :screwdriver }) }.to raise_error(ArgumentError) end - it "should not allow an array" do - expect { @resource.recursive([:nose, :chin]) }.to raise_error(ArgumentError) + it "does not allow an array" do + expect { resource.recursive([:nose, :chin]) }.to raise_error(ArgumentError) end - it "should not allow a string" do - expect { @resource.recursive("souffle") }.to raise_error(ArgumentError) + it "does not allow a string" do + expect { resource.recursive("souffle") }.to raise_error(ArgumentError) end - it "should not allow an integer" do - expect { @resource.recursive(100) }.to raise_error(ArgumentError) + it "does not allow an integer" do + expect { resource.recursive(100) }.to raise_error(ArgumentError) end end describe Chef::Resource::RegistryKey, "architecture" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } [ :i386, :x86_64, :machine ].each do |arch| - it "should allow #{arch} as a symbol" do - @resource.architecture(arch) - expect(@resource.architecture).to eql(arch) + it "allows #{arch} as a symbol" do + resource.architecture(arch) + expect(resource.architecture).to eql(arch) end end - it "should not allow a hash" do - expect { @resource.architecture({ :sonic => :screwdriver }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.architecture({ :sonic => :screwdriver }) }.to raise_error(ArgumentError) end - it "should not allow an array" do - expect { @resource.architecture([:nose, :chin]) }.to raise_error(ArgumentError) + it "does not allow an array" do + expect { resource.architecture([:nose, :chin]) }.to raise_error(ArgumentError) end - it "should not allow a string" do - expect { @resource.architecture("souffle") }.to raise_error(ArgumentError) + it "does not allow a string" do + expect { resource.architecture("souffle") }.to raise_error(ArgumentError) end - it "should not allow an integer" do - expect { @resource.architecture(100) }.to raise_error(ArgumentError) + it "does not allow an integer" do + expect { resource.architecture(100) }.to raise_error(ArgumentError) end end describe Chef::Resource::RegistryKey, ":unscrubbed_values" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should return unsafe data as-is" do + it "returns unsafe data as-is" do key_values = [ { :name => "poosh", :type => :binary, :data => 255.chr * 1 } ] - @resource.values(key_values) - expect(@resource.unscrubbed_values).to eql(key_values) + resource.values(key_values) + expect(resource.unscrubbed_values).to eql(key_values) end end describe Chef::Resource::RegistryKey, "state" do - before(:each) do - @resource = Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') - end + let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - it "should return scrubbed values" do - @resource.values([ { :name => "poosh", :type => :binary, :data => 255.chr * 1 } ]) - expect(@resource.state_for_resource_reporter).to eql( { :values => [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] } ) + it "returns scrubbed values" do + resource.values([ { :name => "poosh", :type => :binary, :data => 255.chr * 1 } ]) + expect(resource.state_for_resource_reporter).to eql( { :values => [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] } ) end end diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb index 370b8d8225..1f3cd3394f 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/spec/unit/resource/remote_directory_spec.rb @@ -20,78 +20,76 @@ require "spec_helper" describe Chef::Resource::RemoteDirectory do - before(:each) do - @resource = Chef::Resource::RemoteDirectory.new("/etc/dunk") - end + let(:resource) { Chef::Resource::RemoteDirectory.new("/etc/dunk") } - it "should create a new Chef::Resource::RemoteDirectory" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::RemoteDirectory) + it "creates a new Chef::Resource::RemoteDirectory" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::RemoteDirectory) end - it "should set the path to the first argument to new" do - expect(@resource.path).to eql("/etc/dunk") + it "sets the path to the first argument to new" do + expect(resource.path).to eql("/etc/dunk") end - it "should accept a string for the remote directory source" do - @resource.source "foo" - expect(@resource.source).to eql("foo") + it "accepts a string for the remote directory source" do + resource.source "foo" + expect(resource.source).to eql("foo") end - it "should have the basename of the remote directory resource as the default source" do - expect(@resource.source).to eql("dunk") + it "has the basename of the remote directory resource as the default source" do + expect(resource.source).to eql("dunk") end - it "should accept a number for the remote files backup" do - @resource.files_backup 1 - expect(@resource.files_backup).to eql(1) + it "accepts a number for the remote files backup" do + resource.files_backup 1 + expect(resource.files_backup).to eql(1) end - it "should accept false for the remote files backup" do - @resource.files_backup false - expect(@resource.files_backup).to eql(false) + it "accepts false for the remote files backup" do + resource.files_backup false + expect(resource.files_backup).to eql(false) end - it "should accept 3 or 4 digets for the files_mode" do - @resource.files_mode 100 - expect(@resource.files_mode).to eql(100) - @resource.files_mode 1000 - expect(@resource.files_mode).to eql(1000) + it "accepts 3 or 4 digets for the files_mode" do + resource.files_mode 100 + expect(resource.files_mode).to eql(100) + resource.files_mode 1000 + expect(resource.files_mode).to eql(1000) end - it "should accept a string or number for the files group" do - @resource.files_group "heart" - expect(@resource.files_group).to eql("heart") - @resource.files_group 1000 - expect(@resource.files_group).to eql(1000) + it "accepts a string or number for the files group" do + resource.files_group "heart" + expect(resource.files_group).to eql("heart") + resource.files_group 1000 + expect(resource.files_group).to eql(1000) end - it "should accept a string or number for the files owner" do - @resource.files_owner "heart" - expect(@resource.files_owner).to eql("heart") - @resource.files_owner 1000 - expect(@resource.files_owner).to eql(1000) + it "accepts a string or number for the files owner" do + resource.files_owner "heart" + expect(resource.files_owner).to eql("heart") + resource.files_owner 1000 + expect(resource.files_owner).to eql(1000) end describe "when it has cookbook, files owner, files mode, and source" do before do - @resource.path("/var/path/") - @resource.cookbook("pokemon.rb") - @resource.files_owner("root") - @resource.files_group("supergroup") - @resource.files_mode("0664") - @resource.source("/var/source/") + resource.path("/var/path/") + resource.cookbook("pokemon.rb") + resource.files_owner("root") + resource.files_group("supergroup") + resource.files_mode("0664") + resource.source("/var/source/") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:files_owner]).to eq("root") expect(state[:files_group]).to eq("supergroup") expect(state[:files_mode]).to eq("0664") end it "returns the path as its identity" do - expect(@resource.identity).to eq("/var/path/") + expect(resource.identity).to eq("/var/path/") end end end diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index eca3db3420..6381226e27 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -21,147 +21,145 @@ require "spec_helper" describe Chef::Resource::RemoteFile do - before(:each) do - @resource = Chef::Resource::RemoteFile.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::RemoteFile.new("fakey_fakerton") } describe "initialize" do - it "should create a new Chef::Resource::RemoteFile" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::File) - expect(@resource).to be_a_kind_of(Chef::Resource::RemoteFile) + it "creates a new Chef::Resource::RemoteFile" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::File) + expect(resource).to be_a_kind_of(Chef::Resource::RemoteFile) end end it "says its provider is RemoteFile when the source is an absolute URI" do - @resource.source("http://www.google.com/robots.txt") - expect(@resource.provider).to eq(Chef::Provider::RemoteFile) - expect(@resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) + resource.source("http://www.google.com/robots.txt") + expect(resource.provider).to eq(Chef::Provider::RemoteFile) + expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) end it "says its provider is RemoteFile when the source is a network share" do - @resource.source("\\\\fakey\\fakerton\\fake.txt") - expect(@resource.provider).to eq(Chef::Provider::RemoteFile) - expect(@resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) + resource.source("\\\\fakey\\fakerton\\fake.txt") + expect(resource.provider).to eq(Chef::Provider::RemoteFile) + expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) end describe "source" do it "does not have a default value for 'source'" do - expect(@resource.source).to eql([]) + expect(resource.source).to eql([]) end - it "should accept a URI for the remote file source" do - @resource.source "http://opscode.com/" - expect(@resource.source).to eql([ "http://opscode.com/" ]) + it "accepts a URI for the remote file source" do + resource.source "http://opscode.com/" + expect(resource.source).to eql([ "http://opscode.com/" ]) end - it "should accept a windows network share source" do - @resource.source "\\\\fakey\\fakerton\\fake.txt" - expect(@resource.source).to eql([ "\\\\fakey\\fakerton\\fake.txt" ]) + it "accepts a windows network share source" do + resource.source "\\\\fakey\\fakerton\\fake.txt" + expect(resource.source).to eql([ "\\\\fakey\\fakerton\\fake.txt" ]) end - it "should accept file URIs with spaces" do - @resource.source("file:///C:/foo bar") - expect(@resource.source).to eql(["file:///C:/foo bar"]) + it "accepts file URIs with spaces" do + resource.source("file:///C:/foo bar") + expect(resource.source).to eql(["file:///C:/foo bar"]) end - it "should accept a delayed evalutator (string) for the remote file source" do - @resource.source Chef::DelayedEvaluator.new { "http://opscode.com/" } - expect(@resource.source).to eql([ "http://opscode.com/" ]) + it "accepts a delayed evalutator (string) for the remote file source" do + resource.source Chef::DelayedEvaluator.new { "http://opscode.com/" } + expect(resource.source).to eql([ "http://opscode.com/" ]) end - it "should accept an array of URIs for the remote file source" do - @resource.source([ "http://opscode.com/", "http://puppetlabs.com/" ]) - expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + it "accepts an array of URIs for the remote file source" do + resource.source([ "http://opscode.com/", "http://puppetlabs.com/" ]) + expect(resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end - it "should accept a delated evaluator (array) for the remote file source" do - @resource.source Chef::DelayedEvaluator.new { [ "http://opscode.com/", "http://puppetlabs.com/" ] } - expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + it "accepts a delated evaluator (array) for the remote file source" do + resource.source Chef::DelayedEvaluator.new { [ "http://opscode.com/", "http://puppetlabs.com/" ] } + expect(resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end - it "should accept an multiple URIs as arguments for the remote file source" do - @resource.source("http://opscode.com/", "http://puppetlabs.com/") - expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + it "accepts an multiple URIs as arguments for the remote file source" do + resource.source("http://opscode.com/", "http://puppetlabs.com/") + expect(resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end - it "should only accept a single argument if a delayed evalutor is used" do + it "only accept a single argument if a delayed evalutor is used" do expect do - @resource.source("http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }) + resource.source("http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }) end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end - it "should only accept a single array item if a delayed evalutor is used" do + it "only accept a single array item if a delayed evalutor is used" do expect do - @resource.source(["http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }]) + resource.source(["http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }]) end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source" do - expect { @resource.source("not-a-uri") }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + expect { resource.source("not-a-uri") }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source when read from a delayed evaluator" do expect do - @resource.source(Chef::DelayedEvaluator.new { "not-a-uri" }) - @resource.source + resource.source(Chef::DelayedEvaluator.new { "not-a-uri" }) + resource.source end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end - it "should raise an exception when source is an empty array" do - expect { @resource.source([]) }.to raise_error(ArgumentError) + it "raises an exception when source is an empty array" do + expect { resource.source([]) }.to raise_error(ArgumentError) end end describe "checksum" do - it "should accept a string for the checksum object" do - @resource.checksum "asdf" - expect(@resource.checksum).to eql("asdf") + it "accepts a string for the checksum object" do + resource.checksum "asdf" + expect(resource.checksum).to eql("asdf") end - it "should default to nil" do - expect(@resource.checksum).to eq(nil) + it "defaults to nil" do + expect(resource.checksum).to eq(nil) end end describe "ftp_active_mode" do - it "should accept a boolean for the ftp_active_mode object" do - @resource.ftp_active_mode true - expect(@resource.ftp_active_mode).to be_truthy + it "accepts a boolean for the ftp_active_mode object" do + resource.ftp_active_mode true + expect(resource.ftp_active_mode).to be_truthy end - it "should default to false" do - expect(@resource.ftp_active_mode).to be_falsey + it "defaults to false" do + expect(resource.ftp_active_mode).to be_falsey end end describe "conditional get options" do it "defaults to using etags and last modified" do - expect(@resource.use_etags).to be_truthy - expect(@resource.use_last_modified).to be_truthy + expect(resource.use_etags).to be_truthy + expect(resource.use_last_modified).to be_truthy end it "enable or disables etag and last modified options as a group" do - @resource.use_conditional_get(false) - expect(@resource.use_etags).to be_falsey - expect(@resource.use_last_modified).to be_falsey + resource.use_conditional_get(false) + expect(resource.use_etags).to be_falsey + expect(resource.use_last_modified).to be_falsey - @resource.use_conditional_get(true) - expect(@resource.use_etags).to be_truthy - expect(@resource.use_last_modified).to be_truthy + resource.use_conditional_get(true) + expect(resource.use_etags).to be_truthy + expect(resource.use_last_modified).to be_truthy end it "disables etags indivdually" do - @resource.use_etags(false) - expect(@resource.use_etags).to be_falsey - expect(@resource.use_last_modified).to be_truthy + resource.use_etags(false) + expect(resource.use_etags).to be_falsey + expect(resource.use_last_modified).to be_truthy end it "disables last modified individually" do - @resource.use_last_modified(false) - expect(@resource.use_last_modified).to be_falsey - expect(@resource.use_etags).to be_truthy + resource.use_last_modified(false) + expect(resource.use_last_modified).to be_falsey + expect(resource.use_etags).to be_truthy end end @@ -169,21 +167,21 @@ describe Chef::Resource::RemoteFile do describe "when it has group, mode, owner, source, and checksum" do before do if Chef::Platform.windows? - @resource.path("C:/temp/origin/file.txt") - @resource.rights(:read, "Everyone") - @resource.deny_rights(:full_control, "Clumsy_Sam") + resource.path("C:/temp/origin/file.txt") + resource.rights(:read, "Everyone") + resource.deny_rights(:full_control, "Clumsy_Sam") else - @resource.path("/this/path/") - @resource.group("pokemon") - @resource.mode("0664") - @resource.owner("root") + resource.path("/this/path/") + resource.group("pokemon") + resource.mode("0664") + resource.owner("root") end - @resource.source("https://www.google.com/images/srpr/logo3w.png") - @resource.checksum("1" * 26) + resource.source("https://www.google.com/images/srpr/logo3w.png") + resource.checksum("1" * 26) end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter if Chef::Platform.windows? puts state expect(state[:rights]).to eq([{ :permissions => :read, :principals => "Everyone" }]) @@ -198,9 +196,9 @@ describe Chef::Resource::RemoteFile do it "returns the path as its identity" do if Chef::Platform.windows? - expect(@resource.identity).to eq("C:/temp/origin/file.txt") + expect(resource.identity).to eq("C:/temp/origin/file.txt") else - expect(@resource.identity).to eq("/this/path/") + expect(resource.identity).to eq("/this/path/") end end end diff --git a/spec/unit/resource/route_spec.rb b/spec/unit/resource/route_spec.rb index 884b477365..351272c42c 100644 --- a/spec/unit/resource/route_spec.rb +++ b/spec/unit/resource/route_spec.rb @@ -21,87 +21,85 @@ require "spec_helper" describe Chef::Resource::Route do - before(:each) do - @resource = Chef::Resource::Route.new("10.0.0.10") - end + let(:resource) { Chef::Resource::Route.new("10.0.0.10") } - it "should create a new Chef::Resource::Route" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Route) + it "creates a new Chef::Resource::Route" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Route) end - it "should have a name" do - expect(@resource.name).to eql("10.0.0.10") + it "has a name" do + expect(resource.name).to eql("10.0.0.10") end - it "should have a default action of 'add'" do - expect(@resource.action).to eql([:add]) + it "has a default action of 'add'" do + expect(resource.action).to eql([:add]) end - it "should accept add or delete for action" do - expect { @resource.action :add }.not_to raise_error - expect { @resource.action :delete }.not_to raise_error - expect { @resource.action :lolcat }.to raise_error(ArgumentError) + it "accepts add or delete for action" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :lolcat }.to raise_error(ArgumentError) end - it "should use the object name as the target by default" do - expect(@resource.target).to eql("10.0.0.10") + it "uses the object name as the target by default" do + expect(resource.target).to eql("10.0.0.10") end - it "should allow you to specify the netmask" do - @resource.netmask "255.255.255.0" - expect(@resource.netmask).to eql("255.255.255.0") + it "allows you to specify the netmask" do + resource.netmask "255.255.255.0" + expect(resource.netmask).to eql("255.255.255.0") end - it "should allow you to specify the gateway" do - @resource.gateway "10.0.0.1" - expect(@resource.gateway).to eql("10.0.0.1") + it "allows you to specify the gateway" do + resource.gateway "10.0.0.1" + expect(resource.gateway).to eql("10.0.0.1") end - it "should allow you to specify the metric" do - @resource.metric 10 - expect(@resource.metric).to eql(10) + it "allows you to specify the metric" do + resource.metric 10 + expect(resource.metric).to eql(10) end - it "should allow you to specify the device" do - @resource.device "eth0" - expect(@resource.device).to eql("eth0") + it "allows you to specify the device" do + resource.device "eth0" + expect(resource.device).to eql("eth0") end - it "should allow you to specify the route type" do - @resource.route_type "host" - expect(@resource.route_type).to eql(:host) + it "allows you to specify the route type" do + resource.route_type "host" + expect(resource.route_type).to eql(:host) end - it "should default to a host route type" do - expect(@resource.route_type).to eql(:host) + it "defaults to a host route type" do + expect(resource.route_type).to eql(:host) end - it "should accept a net route type" do - @resource.route_type :net - expect(@resource.route_type).to eql(:net) + it "accepts a net route type" do + resource.route_type :net + expect(resource.route_type).to eql(:net) end - it "should reject any other route_type but :host and :net" do - expect { @resource.route_type "lolcat" }.to raise_error(ArgumentError) + it "rejects any other route_type but :host and :net" do + expect { resource.route_type "lolcat" }.to raise_error(ArgumentError) end describe "when it has netmask, gateway, and device" do before do - @resource.target("charmander") - @resource.netmask("lemask") - @resource.gateway("111.111.111") - @resource.device("forcefield") + resource.target("charmander") + resource.netmask("lemask") + resource.gateway("111.111.111") + resource.device("forcefield") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:netmask]).to eq("lemask") expect(state[:gateway]).to eq("111.111.111") end it "returns the target as its identity" do - expect(@resource.identity).to eq("charmander") + expect(resource.identity).to eq("charmander") end end end diff --git a/spec/unit/resource/rpm_package_spec.rb b/spec/unit/resource/rpm_package_spec.rb index e1488f1dd1..3f742e6636 100644 --- a/spec/unit/resource/rpm_package_spec.rb +++ b/spec/unit/resource/rpm_package_spec.rb @@ -34,13 +34,11 @@ describe Chef::Resource::RpmPackage, "initialize" do end describe Chef::Resource::RpmPackage, "allow_downgrade" do - before(:each) do - @resource = Chef::Resource::RpmPackage.new("foo") - end + let(:resource) { Chef::Resource::RpmPackage.new("foo") } - it "should allow you to specify whether allow_downgrade is true or false" do - expect { @resource.allow_downgrade true }.not_to raise_error - expect { @resource.allow_downgrade false }.not_to raise_error - expect { @resource.allow_downgrade "monkey" }.to raise_error(ArgumentError) + it "allows you to specify whether allow_downgrade is true or false" do + expect { resource.allow_downgrade true }.not_to raise_error + expect { resource.allow_downgrade false }.not_to raise_error + expect { resource.allow_downgrade "monkey" }.to raise_error(ArgumentError) end end diff --git a/spec/unit/resource/ruby_block_spec.rb b/spec/unit/resource/ruby_block_spec.rb index f393fbea46..e5fad958dd 100644 --- a/spec/unit/resource/ruby_block_spec.rb +++ b/spec/unit/resource/ruby_block_spec.rb @@ -21,41 +21,39 @@ require "spec_helper" describe Chef::Resource::RubyBlock do - before(:each) do - @resource = Chef::Resource::RubyBlock.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::RubyBlock.new("fakey_fakerton") } - it "should create a new Chef::Resource::RubyBlock" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::RubyBlock) + it "creates a new Chef::Resource::RubyBlock" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::RubyBlock) end - it "should have a default action of 'run'" do - expect(@resource.action).to eql([:run]) + it "has a default action of 'run'" do + expect(resource.action).to eql([:run]) end - it "should have a resource name of :ruby_block" do - expect(@resource.resource_name).to eql(:ruby_block) + it "has a resource name of :ruby_block" do + expect(resource.resource_name).to eql(:ruby_block) end - it "should accept a ruby block/proc/.. for the 'block' parameter" do - expect(@resource.block do + it "accepts a ruby block/proc/.. for the 'block' parameter" do + expect(resource.block do "foo" end.call).to eql("foo") end it "allows the action to be 'create'" do - @resource.action :create - expect(@resource.action).to eq([:create]) + resource.action :create + expect(resource.action).to eq([:create]) end describe "when it has been initialized with block code" do before do - @resource.block_name("puts 'harrrr'") + resource.block_name("puts 'harrrr'") end it "returns the block as its identity" do - expect(@resource.identity).to eq("puts 'harrrr'") + expect(resource.identity).to eq("puts 'harrrr'") end end end diff --git a/spec/unit/resource/ruby_spec.rb b/spec/unit/resource/ruby_spec.rb index d7b6759462..4fc62269bc 100644 --- a/spec/unit/resource/ruby_spec.rb +++ b/spec/unit/resource/ruby_spec.rb @@ -19,22 +19,18 @@ require "spec_helper" describe Chef::Resource::Ruby do + let(:resource) { Chef::Resource::Ruby.new("fakey_fakerton") } - before(:each) do - @resource = Chef::Resource::Ruby.new("fakey_fakerton") + it "creates a new Chef::Resource::Ruby" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Ruby) end - it "should create a new Chef::Resource::Ruby" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Ruby) + it "has a resource name of :ruby" do + expect(resource.resource_name).to eql(:ruby) end - it "should have a resource name of :ruby" do - expect(@resource.resource_name).to eql(:ruby) + it "has an interpreter of ruby" do + expect(resource.interpreter).to eql("ruby") end - - it "should have an interpreter of ruby" do - expect(@resource.interpreter).to eql("ruby") - end - end diff --git a/spec/unit/resource/scm_spec.rb b/spec/unit/resource/scm_spec.rb index 679b3bc1fc..8e49cd3383 100644 --- a/spec/unit/resource/scm_spec.rb +++ b/spec/unit/resource/scm_spec.rb @@ -20,174 +20,171 @@ require "spec_helper" describe Chef::Resource::Scm do + let(:resource) { Chef::Resource::Scm.new("my awesome app") } - before(:each) do - @resource = Chef::Resource::Scm.new("my awesome app") - end - - it "should be a SCM resource" do - expect(@resource).to be_a_kind_of(Chef::Resource::Scm) + it "is a SCM resource" do + expect(resource).to be_a_kind_of(Chef::Resource::Scm) end it "supports :checkout, :export, :sync, :diff, and :log actions" do - expect(@resource.allowed_actions).to include(:checkout) - expect(@resource.allowed_actions).to include(:export) - expect(@resource.allowed_actions).to include(:sync) - expect(@resource.allowed_actions).to include(:diff) - expect(@resource.allowed_actions).to include(:log) + expect(resource.allowed_actions).to include(:checkout) + expect(resource.allowed_actions).to include(:export) + expect(resource.allowed_actions).to include(:sync) + expect(resource.allowed_actions).to include(:diff) + expect(resource.allowed_actions).to include(:log) end it "takes the destination path as a string" do - @resource.destination "/path/to/deploy/dir" - expect(@resource.destination).to eql("/path/to/deploy/dir") + resource.destination "/path/to/deploy/dir" + expect(resource.destination).to eql("/path/to/deploy/dir") end it "takes a string for the repository URL" do - @resource.repository "git://github.com/opscode/chef.git" - expect(@resource.repository).to eql("git://github.com/opscode/chef.git") + resource.repository "git://github.com/opscode/chef.git" + expect(resource.repository).to eql("git://github.com/opscode/chef.git") end it "takes a string for the revision" do - @resource.revision "abcdef" - expect(@resource.revision).to eql("abcdef") + resource.revision "abcdef" + expect(resource.revision).to eql("abcdef") end it "defaults to the ``HEAD'' revision" do - expect(@resource.revision).to eql("HEAD") + expect(resource.revision).to eql("HEAD") end it "takes a string for the user to run as" do - @resource.user "dr_deploy" - expect(@resource.user).to eql("dr_deploy") + resource.user "dr_deploy" + expect(resource.user).to eql("dr_deploy") end it "also takes an integer for the user to run as" do - @resource.user 0 - expect(@resource.user).to eql(0) + resource.user 0 + expect(resource.user).to eql(0) end it "takes a string for the group to run as, defaulting to nil" do - expect(@resource.group).to be_nil - @resource.group "opsdevs" - expect(@resource.group).to eq("opsdevs") + expect(resource.group).to be_nil + resource.group "opsdevs" + expect(resource.group).to eq("opsdevs") end it "also takes an integer for the group to run as" do - @resource.group 23 - expect(@resource.group).to eq(23) + resource.group 23 + expect(resource.group).to eq(23) end it "has a svn_username String attribute" do - @resource.svn_username "moartestsplz" - expect(@resource.svn_username).to eql("moartestsplz") + resource.svn_username "moartestsplz" + expect(resource.svn_username).to eql("moartestsplz") end it "has a svn_password String attribute" do - @resource.svn_password "taftplz" - expect(@resource.svn_password).to eql("taftplz") + resource.svn_password "taftplz" + expect(resource.svn_password).to eql("taftplz") end it "has a svn_arguments String attribute" do - @resource.svn_arguments "--more-taft plz" - expect(@resource.svn_arguments).to eql("--more-taft plz") + resource.svn_arguments "--more-taft plz" + expect(resource.svn_arguments).to eql("--more-taft plz") end it "has a svn_info_args String attribute" do - expect(@resource.svn_info_args).to be_nil - @resource.svn_info_args("--no-moar-plaintext-creds yep") - expect(@resource.svn_info_args).to eq("--no-moar-plaintext-creds yep") + expect(resource.svn_info_args).to be_nil + resource.svn_info_args("--no-moar-plaintext-creds yep") + expect(resource.svn_info_args).to eq("--no-moar-plaintext-creds yep") end it "takes the depth as an integer for shallow clones" do - @resource.depth 5 - expect(@resource.depth).to eq(5) - expect { @resource.depth "five" }.to raise_error(ArgumentError) + resource.depth 5 + expect(resource.depth).to eq(5) + expect { resource.depth "five" }.to raise_error(ArgumentError) end it "defaults to nil depth for a full clone" do - expect(@resource.depth).to be_nil + expect(resource.depth).to be_nil end it "takes a boolean for #enable_submodules" do - @resource.enable_submodules true - expect(@resource.enable_submodules).to be_truthy - expect { @resource.enable_submodules "lolz" }.to raise_error(ArgumentError) + resource.enable_submodules true + expect(resource.enable_submodules).to be_truthy + expect { resource.enable_submodules "lolz" }.to raise_error(ArgumentError) end it "defaults to not enabling submodules" do - expect(@resource.enable_submodules).to be_falsey + expect(resource.enable_submodules).to be_falsey end it "takes a boolean for #enable_checkout" do - @resource.enable_checkout true - expect(@resource.enable_checkout).to be_truthy - expect { @resource.enable_checkout "lolz" }.to raise_error(ArgumentError) + resource.enable_checkout true + expect(resource.enable_checkout).to be_truthy + expect { resource.enable_checkout "lolz" }.to raise_error(ArgumentError) end it "defaults to enabling checkout" do - expect(@resource.enable_checkout).to be_truthy + expect(resource.enable_checkout).to be_truthy end it "takes a string for the remote" do - @resource.remote "opscode" - expect(@resource.remote).to eql("opscode") - expect { @resource.remote 1337 }.to raise_error(ArgumentError) + resource.remote "opscode" + expect(resource.remote).to eql("opscode") + expect { resource.remote 1337 }.to raise_error(ArgumentError) end it "defaults to ``origin'' for the remote" do - expect(@resource.remote).to eq("origin") + expect(resource.remote).to eq("origin") end it "takes a string for the ssh wrapper" do - @resource.ssh_wrapper "with_ssh_fu" - expect(@resource.ssh_wrapper).to eql("with_ssh_fu") + resource.ssh_wrapper "with_ssh_fu" + expect(resource.ssh_wrapper).to eql("with_ssh_fu") end it "defaults to nil for the ssh wrapper" do - expect(@resource.ssh_wrapper).to be_nil + expect(resource.ssh_wrapper).to be_nil end it "defaults to nil for the environment" do - expect(@resource.environment).to be_nil + expect(resource.environment).to be_nil end describe "when it has a timeout attribute" do let(:ten_seconds) { 10 } - before { @resource.timeout(ten_seconds) } + before { resource.timeout(ten_seconds) } it "stores this timeout" do - expect(@resource.timeout).to eq(ten_seconds) + expect(resource.timeout).to eq(ten_seconds) end end describe "when it has no timeout attribute" do - it "should have no default timeout" do - expect(@resource.timeout).to be_nil + it "has no default timeout" do + expect(resource.timeout).to be_nil end end describe "when it has repository, revision, user, and group" do before do - @resource.destination("hell") - @resource.repository("apt") - @resource.revision("1.2.3") - @resource.user("root") - @resource.group("super_adventure_club") + resource.destination("hell") + resource.repository("apt") + resource.revision("1.2.3") + resource.user("root") + resource.group("super_adventure_club") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:revision]).to eq("1.2.3") end it "returns the destination as its identity" do - expect(@resource.identity).to eq("hell") + expect(resource.identity).to eq("hell") end end describe "when it has a environment attribute" do let(:test_environment) { { "CHEF_ENV" => "/tmp" } } - before { @resource.environment(test_environment) } + before { resource.environment(test_environment) } it "stores this environment" do - expect(@resource.environment).to eq(test_environment) + expect(resource.environment).to eq(test_environment) end end end diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb index 16f7650712..554d99710e 100644 --- a/spec/unit/resource/script_spec.rb +++ b/spec/unit/resource/script_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::Script do let(:script_resource) { Chef::Resource::Script.new(resource_instance_name) } let(:resource_name) { :script } - it "should accept a string for the interpreter" do + it "accepts a string for the interpreter" do script_resource.interpreter "naaaaNaNaNaaNaaNaaNaa" expect(script_resource.interpreter).to eql("naaaaNaNaNaaNaaNaaNaa") end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 67a4635983..83d996f4fd 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -20,180 +20,177 @@ require "spec_helper" describe Chef::Resource::Service do + let(:resource) { Chef::Resource::Service.new("chef") } - before(:each) do - @resource = Chef::Resource::Service.new("chef") + it "creates a new Chef::Resource::Service" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::Service) end - it "should create a new Chef::Resource::Service" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::Service) + it "does not set a provider unless node[:init_package] is defined as systemd" do + expect(resource.provider).to eq(nil) end - it "should not set a provider unless node[:init_package] is defined as systemd" do - expect(@resource.provider).to eq(nil) + it "sets the service_name to the first argument to new" do + expect(resource.service_name).to eql("chef") end - it "should set the service_name to the first argument to new" do - expect(@resource.service_name).to eql("chef") + it "sets the pattern to be the service name by default" do + expect(resource.pattern).to eql("chef") end - it "should set the pattern to be the service name by default" do - expect(@resource.pattern).to eql("chef") + it "accepts a string for the service name" do + resource.service_name "something" + expect(resource.service_name).to eql("something") end - it "should accept a string for the service name" do - @resource.service_name "something" - expect(@resource.service_name).to eql("something") + it "accepts a string for the service pattern" do + resource.pattern ".*" + expect(resource.pattern).to eql(".*") end - it "should accept a string for the service pattern" do - @resource.pattern ".*" - expect(@resource.pattern).to eql(".*") - end - - it "should not accept a regexp for the service pattern" do + it "does not accept a regexp for the service pattern" do expect do - @resource.pattern /.*/ + resource.pattern /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service start command" do - @resource.start_command "/etc/init.d/chef start" - expect(@resource.start_command).to eql("/etc/init.d/chef start") + it "accepts a string for the service start command" do + resource.start_command "/etc/init.d/chef start" + expect(resource.start_command).to eql("/etc/init.d/chef start") end - it "should not accept a regexp for the service start command" do + it "does not accept a regexp for the service start command" do expect do - @resource.start_command /.*/ + resource.start_command /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service stop command" do - @resource.stop_command "/etc/init.d/chef stop" - expect(@resource.stop_command).to eql("/etc/init.d/chef stop") + it "accepts a string for the service stop command" do + resource.stop_command "/etc/init.d/chef stop" + expect(resource.stop_command).to eql("/etc/init.d/chef stop") end - it "should not accept a regexp for the service stop command" do + it "does not accept a regexp for the service stop command" do expect do - @resource.stop_command /.*/ + resource.stop_command /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service status command" do - @resource.status_command "/etc/init.d/chef status" - expect(@resource.status_command).to eql("/etc/init.d/chef status") + it "accepts a string for the service status command" do + resource.status_command "/etc/init.d/chef status" + expect(resource.status_command).to eql("/etc/init.d/chef status") end - it "should not accept a regexp for the service status command" do + it "does not accept a regexp for the service status command" do expect do - @resource.status_command /.*/ + resource.status_command /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service restart command" do - @resource.restart_command "/etc/init.d/chef restart" - expect(@resource.restart_command).to eql("/etc/init.d/chef restart") + it "accepts a string for the service restart command" do + resource.restart_command "/etc/init.d/chef restart" + expect(resource.restart_command).to eql("/etc/init.d/chef restart") end - it "should not accept a regexp for the service restart command" do + it "does not accept a regexp for the service restart command" do expect do - @resource.restart_command /.*/ + resource.restart_command /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service reload command" do - @resource.reload_command "/etc/init.d/chef reload" - expect(@resource.reload_command).to eql("/etc/init.d/chef reload") + it "accepts a string for the service reload command" do + resource.reload_command "/etc/init.d/chef reload" + expect(resource.reload_command).to eql("/etc/init.d/chef reload") end - it "should not accept a regexp for the service reload command" do + it "does not accept a regexp for the service reload command" do expect do - @resource.reload_command /.*/ + resource.reload_command /.*/ end.to raise_error(ArgumentError) end - it "should accept a string for the service init command" do - @resource.init_command "/etc/init.d/chef" - expect(@resource.init_command).to eql("/etc/init.d/chef") + it "accepts a string for the service init command" do + resource.init_command "/etc/init.d/chef" + expect(resource.init_command).to eql("/etc/init.d/chef") end - it "should not accept a regexp for the service init command" do + it "does not accept a regexp for the service init command" do expect do - @resource.init_command /.*/ + resource.init_command /.*/ end.to raise_error(ArgumentError) end - it "should accept an array for options" do - @resource.options ["-r", "-s"] - expect(@resource.options).to eql(["-r", "-s"]) + it "accepts an array for options" do + resource.options ["-r", "-s"] + expect(resource.options).to eql(["-r", "-s"]) end - it "should accept a string for options" do - @resource.options "-r" - expect(@resource.options).to eql(["-r"]) + it "accepts a string for options" do + resource.options "-r" + expect(resource.options).to eql(["-r"]) end - it "should accept a string with multiple flags for options" do - @resource.options "-r -s" - expect(@resource.options).to eql(["-r", "-s"]) + it "accepts a string with multiple flags for options" do + resource.options "-r -s" + expect(resource.options).to eql(["-r", "-s"]) end - it "should not accept a boolean for options" do + it "does not accept a boolean for options" do expect do - @resource.options true + resource.options true end.to raise_error(ArgumentError) end %w{enabled running}.each do |attrib| - it "should accept true for #{attrib}" do - @resource.send(attrib, true) - expect(@resource.send(attrib)).to eql(true) + it "accepts true for #{attrib}" do + resource.send(attrib, true) + expect(resource.send(attrib)).to eql(true) end - it "should accept false for #{attrib}" do - @resource.send(attrib, false) - expect(@resource.send(attrib)).to eql(false) + it "accepts false for #{attrib}" do + resource.send(attrib, false) + expect(resource.send(attrib)).to eql(false) end - it "should not accept a string for #{attrib}" do - expect { @resource.send(attrib, "poop") }.to raise_error(ArgumentError) + it "does not accept a string for #{attrib}" do + expect { resource.send(attrib, "poop") }.to raise_error(ArgumentError) end - it "should default all the feature support to nil" do + it "defaults all the feature support to nil" do support_hash = { :status => nil, :restart => nil, :reload => nil } - expect(@resource.supports).to eq(support_hash) + expect(resource.supports).to eq(support_hash) end - it "should allow you to set what features this resource supports as a array" do + it "allows you to set what features this resource supports as a array" do support_array = [ :status, :restart ] support_hash = { :status => true, :restart => true } - @resource.supports(support_array) - expect(@resource.supports).to eq(support_hash) + resource.supports(support_array) + expect(resource.supports).to eq(support_hash) end - it "should allow you to set what features this resource supports as a hash" do + it "allows you to set what features this resource supports as a hash" do support_hash = { :status => true, :restart => true } - @resource.supports(support_hash) - expect(@resource.supports).to eq(support_hash) + resource.supports(support_hash) + expect(resource.supports).to eq(support_hash) end end describe "when it has pattern and supports" do before do - @resource.service_name("superfriend") - @resource.enabled(true) - @resource.running(false) + resource.service_name("superfriend") + resource.enabled(true) + resource.running(false) end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:enabled]).to eql(true) expect(state[:running]).to eql(false) end it "returns the service name as its identity" do - expect(@resource.identity).to eq("superfriend") + expect(resource.identity).to eq("superfriend") end end end diff --git a/spec/unit/resource/smartos_package_spec.rb b/spec/unit/resource/smartos_package_spec.rb index 56c0fbdb8b..a0bd5853f5 100644 --- a/spec/unit/resource/smartos_package_spec.rb +++ b/spec/unit/resource/smartos_package_spec.rb @@ -30,4 +30,9 @@ describe Chef::Resource::SmartosPackage, "initialize" do platform_family: "smartos" ) + let(:resource) { Chef::Resource::SmartosPackage.new("foo") } + + it "sets the package_name to the name provided" do + expect(resource.package_name).to eql("foo") + end end diff --git a/spec/unit/resource/solaris_package_spec.rb b/spec/unit/resource/solaris_package_spec.rb index 1f1ef4da30..dda8240af8 100644 --- a/spec/unit/resource/solaris_package_spec.rb +++ b/spec/unit/resource/solaris_package_spec.rb @@ -32,11 +32,9 @@ describe Chef::Resource::SolarisPackage, "initialize" do ) end - before(:each) do - @resource = Chef::Resource::SolarisPackage.new("foo") - end + let(:resource) { Chef::Resource::SolarisPackage.new("foo") } - it "should set the package_name to the name provided" do - expect(@resource.package_name).to eql("foo") + it "sets the package_name to the name provided" do + expect(resource.package_name).to eql("foo") end end diff --git a/spec/unit/resource/subversion_spec.rb b/spec/unit/resource/subversion_spec.rb index a2901bf53b..2b86587f1a 100644 --- a/spec/unit/resource/subversion_spec.rb +++ b/spec/unit/resource/subversion_spec.rb @@ -28,44 +28,46 @@ describe Chef::Resource::Subversion do action: :install ) - before do - @svn = Chef::Resource::Subversion.new("ohai, svn project!") - end + let(:resource) { Chef::Resource::Subversion.new("ohai, svn project!") } it "is a subclass of Resource::Scm" do - expect(@svn).to be_an_instance_of(Chef::Resource::Subversion) - expect(@svn).to be_a_kind_of(Chef::Resource::Scm) + expect(resource).to be_an_instance_of(Chef::Resource::Subversion) + expect(resource).to be_a_kind_of(Chef::Resource::Scm) + end + + it "set destination property to the name_property" do + expect(resource.destination).to eq("ohai, svn project!") end it "allows the force_export action" do - expect(@svn.allowed_actions).to include(:force_export) + expect(resource.allowed_actions).to include(:force_export) end it "sets svn info arguments to --no-auth-cache by default" do - expect(@svn.svn_info_args).to eq("--no-auth-cache") + expect(resource.svn_info_args).to eq("--no-auth-cache") end it "resets svn info arguments to nil when given false in the setter" do - @svn.svn_info_args(false) - expect(@svn.svn_info_args).to be_nil + resource.svn_info_args(false) + expect(resource.svn_info_args).to be_nil end it "sets svn arguments to --no-auth-cache by default" do - expect(@svn.svn_arguments).to eq("--no-auth-cache") + expect(resource.svn_arguments).to eq("--no-auth-cache") end it "sets svn binary to nil by default" do - expect(@svn.svn_binary).to be_nil + expect(resource.svn_binary).to be_nil end it "resets svn arguments to nil when given false in the setter" do - @svn.svn_arguments(false) - expect(@svn.svn_arguments).to be_nil + resource.svn_arguments(false) + expect(resource.svn_arguments).to be_nil end it "hides password from custom exception message" do - @svn.svn_password "l33th4x0rpa$$w0rd" - e = @svn.customize_exception(Chef::Exceptions::Exec.new "Exception with password #{@svn.svn_password}") - expect(e.message.include?(@svn.svn_password)).to be_falsey + resource.svn_password "l33th4x0rpa$$w0rd" + e = resource.customize_exception(Chef::Exceptions::Exec.new "Exception with password #{resource.svn_password}") + expect(e.message.include?(resource.svn_password)).to be_falsey end end diff --git a/spec/unit/resource/systemd_unit_spec.rb b/spec/unit/resource/systemd_unit_spec.rb index ab1004fab0..00db3ee5ec 100644 --- a/spec/unit/resource/systemd_unit_spec.rb +++ b/spec/unit/resource/systemd_unit_spec.rb @@ -19,12 +19,8 @@ require "spec_helper" describe Chef::Resource::SystemdUnit do - before(:each) do - @resource = Chef::Resource::SystemdUnit.new("sysstat-collect.timer") - end - + let(:resource) { Chef::Resource::SystemdUnit.new("sysstat-collect.timer") } let(:unit_content_string) { "[Unit]\nDescription = Run system activity accounting tool every 10 minutes\n\n[Timer]\nOnCalendar = *:00/10\n\n[Install]\nWantedBy = sysstat.service\n" } - let(:unit_content_hash) do { "Unit" => { @@ -40,76 +36,76 @@ describe Chef::Resource::SystemdUnit do end it "creates a new Chef::Resource::SystemdUnit" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::SystemdUnit) + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::SystemdUnit) end - it "should have a name" do - expect(@resource.name).to eql("sysstat-collect.timer") + it "has a name" do + expect(resource.name).to eql("sysstat-collect.timer") end it "has a default action of nothing" do - expect(@resource.action).to eql([:nothing]) + expect(resource.action).to eql([:nothing]) end it "supports appropriate unit actions" do - expect { @resource.action :create }.not_to raise_error - expect { @resource.action :delete }.not_to raise_error - expect { @resource.action :enable }.not_to raise_error - expect { @resource.action :disable }.not_to raise_error - expect { @resource.action :mask }.not_to raise_error - expect { @resource.action :unmask }.not_to raise_error - expect { @resource.action :start }.not_to raise_error - expect { @resource.action :stop }.not_to raise_error - expect { @resource.action :restart }.not_to raise_error - expect { @resource.action :reload }.not_to raise_error - expect { @resource.action :wrong }.to raise_error(ArgumentError) + expect { resource.action :create }.not_to raise_error + expect { resource.action :delete }.not_to raise_error + expect { resource.action :enable }.not_to raise_error + expect { resource.action :disable }.not_to raise_error + expect { resource.action :mask }.not_to raise_error + expect { resource.action :unmask }.not_to raise_error + expect { resource.action :start }.not_to raise_error + expect { resource.action :stop }.not_to raise_error + expect { resource.action :restart }.not_to raise_error + expect { resource.action :reload }.not_to raise_error + expect { resource.action :wrong }.to raise_error(ArgumentError) end it "accepts boolean state properties" do - expect { @resource.active false }.not_to raise_error - expect { @resource.active true }.not_to raise_error - expect { @resource.active "yes" }.to raise_error(ArgumentError) + expect { resource.active false }.not_to raise_error + expect { resource.active true }.not_to raise_error + expect { resource.active "yes" }.to raise_error(ArgumentError) - expect { @resource.enabled true }.not_to raise_error - expect { @resource.enabled false }.not_to raise_error - expect { @resource.enabled "no" }.to raise_error(ArgumentError) + expect { resource.enabled true }.not_to raise_error + expect { resource.enabled false }.not_to raise_error + expect { resource.enabled "no" }.to raise_error(ArgumentError) - expect { @resource.masked true }.not_to raise_error - expect { @resource.masked false }.not_to raise_error - expect { @resource.masked :nope }.to raise_error(ArgumentError) + expect { resource.masked true }.not_to raise_error + expect { resource.masked false }.not_to raise_error + expect { resource.masked :nope }.to raise_error(ArgumentError) - expect { @resource.static true }.not_to raise_error - expect { @resource.static false }.not_to raise_error - expect { @resource.static "yep" }.to raise_error(ArgumentError) + expect { resource.static true }.not_to raise_error + expect { resource.static false }.not_to raise_error + expect { resource.static "yep" }.to raise_error(ArgumentError) end it "accepts the content property" do - expect { @resource.content nil }.not_to raise_error - expect { @resource.content "test" }.not_to raise_error - expect { @resource.content({}) }.not_to raise_error - expect { @resource.content 5 }.to raise_error(ArgumentError) + expect { resource.content nil }.not_to raise_error + expect { resource.content "test" }.not_to raise_error + expect { resource.content({}) }.not_to raise_error + expect { resource.content 5 }.to raise_error(ArgumentError) end it "accepts the user property" do - expect { @resource.user nil }.not_to raise_error - expect { @resource.user "deploy" }.not_to raise_error - expect { @resource.user 5 }.to raise_error(ArgumentError) + expect { resource.user nil }.not_to raise_error + expect { resource.user "deploy" }.not_to raise_error + expect { resource.user 5 }.to raise_error(ArgumentError) end it "accepts the triggers_reload property" do - expect { @resource.triggers_reload true }.not_to raise_error - expect { @resource.triggers_reload false }.not_to raise_error - expect { @resource.triggers_reload "no" }.to raise_error(ArgumentError) + expect { resource.triggers_reload true }.not_to raise_error + expect { resource.triggers_reload false }.not_to raise_error + expect { resource.triggers_reload "no" }.to raise_error(ArgumentError) end it "reports its state" do - @resource.active true - @resource.enabled true - @resource.masked false - @resource.static false - @resource.content "test" - state = @resource.state_for_resource_reporter + resource.active true + resource.enabled true + resource.masked false + resource.static false + resource.content "test" + state = resource.state_for_resource_reporter expect(state[:active]).to eq(true) expect(state[:enabled]).to eq(true) expect(state[:masked]).to eq(false) @@ -118,16 +114,16 @@ describe Chef::Resource::SystemdUnit do end it "returns the unit name as its identity" do - expect(@resource.identity).to eq("sysstat-collect.timer") + expect(resource.identity).to eq("sysstat-collect.timer") end it "serializes to ini with a string-formatted content property" do - @resource.content(unit_content_string) - expect(@resource.to_ini).to eq unit_content_string + resource.content(unit_content_string) + expect(resource.to_ini).to eq unit_content_string end it "serializes to ini with a hash-formatted content property" do - @resource.content(unit_content_hash) - expect(@resource.to_ini).to eq unit_content_string + resource.content(unit_content_hash) + expect(resource.to_ini).to eq unit_content_string end end diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb index 966a86ba6b..017c98517c 100644 --- a/spec/unit/resource/template_spec.rb +++ b/spec/unit/resource/template_spec.rb @@ -19,76 +19,73 @@ require "spec_helper" describe Chef::Resource::Template do - - before(:each) do - @resource = Chef::Resource::Template.new("fakey_fakerton") - end + let(:resource) { Chef::Resource::Template.new("fakey_fakerton") } describe "initialize" do - it "should create a new Chef::Resource::Template" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::File) - expect(@resource).to be_a_kind_of(Chef::Resource::Template) + it "creates a new Chef::Resource::Template" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::File) + expect(resource).to be_a_kind_of(Chef::Resource::Template) end end describe "source" do - it "should accept a string for the template source" do - @resource.source "something" - expect(@resource.source).to eql("something") + it "accepts a string for the template source" do + resource.source "something" + expect(resource.source).to eql("something") end - it "should have a default based on the param name with .erb appended" do - expect(@resource.source).to eql("fakey_fakerton.erb") + it "has a default based on the param name with .erb appended" do + expect(resource.source).to eql("fakey_fakerton.erb") end - it "should use only the basename of the file as the default" do + it "uses only the basename of the file as the default" do r = Chef::Resource::Template.new("/tmp/obit/fakey_fakerton") expect(r.source).to eql("fakey_fakerton.erb") end end describe "variables" do - it "should accept a hash for the variable list" do - @resource.variables({ :reluctance => :awkward }) - expect(@resource.variables).to eq({ :reluctance => :awkward }) + it "accepts a hash for the variable list" do + resource.variables({ :reluctance => :awkward }) + expect(resource.variables).to eq({ :reluctance => :awkward }) end end describe "cookbook" do - it "should accept a string for the cookbook name" do - @resource.cookbook("foo") - expect(@resource.cookbook).to eq("foo") + it "accepts a string for the cookbook name" do + resource.cookbook("foo") + expect(resource.cookbook).to eq("foo") end - it "should default to nil" do - expect(@resource.cookbook).to eq(nil) + it "defaults to nil" do + expect(resource.cookbook).to eq(nil) end end describe "local" do - it "should accept a boolean for whether a template is local or remote" do - @resource.local(true) - expect(@resource.local).to eq(true) + it "accepts a boolean for whether a template is local or remote" do + resource.local(true) + expect(resource.local).to eq(true) end - it "should default to false" do - expect(@resource.local).to eq(false) + it "defaults to false" do + expect(resource.local).to eq(false) end end describe "when it has a path, owner, group, mode, and checksum" do before do - @resource.path("/tmp/foo.txt") - @resource.owner("root") - @resource.group("wheel") - @resource.mode("0644") - @resource.checksum("1" * 64) + resource.path("/tmp/foo.txt") + resource.owner("root") + resource.group("wheel") + resource.mode("0644") + resource.checksum("1" * 64) end context "on unix", :unix_only do it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:owner]).to eq("root") expect(state[:group]).to eq("wheel") expect(state[:mode]).to eq("0644") @@ -102,7 +99,7 @@ describe Chef::Resource::Template do end it "returns the file path as its identity" do - expect(@resource.identity).to eq("/tmp/foo.txt") + expect(resource.identity).to eq("/tmp/foo.txt") end end @@ -115,16 +112,16 @@ describe Chef::Resource::Template do end it "collects helper method bodies as blocks" do - @resource.helper(:example_1) { "example_1" } - @resource.helper(:example_2) { "example_2" } - expect(@resource.inline_helper_blocks[:example_1].call).to eq("example_1") - expect(@resource.inline_helper_blocks[:example_2].call).to eq("example_2") + resource.helper(:example_1) { "example_1" } + resource.helper(:example_2) { "example_2" } + expect(resource.inline_helper_blocks[:example_1].call).to eq("example_1") + expect(resource.inline_helper_blocks[:example_2].call).to eq("example_2") end it "compiles helper methods into a module" do - @resource.helper(:example_1) { "example_1" } - @resource.helper(:example_2) { "example_2" } - modules = @resource.helper_modules + resource.helper(:example_1) { "example_1" } + resource.helper(:example_2) { "example_2" } + modules = resource.helper_modules expect(modules.size).to eq(1) o = Object.new modules.each { |m| o.extend(m) } @@ -133,38 +130,38 @@ describe Chef::Resource::Template do end it "compiles helper methods with arguments into a module" do - @resource.helper(:shout) { |quiet| quiet.upcase } - modules = @resource.helper_modules + resource.helper(:shout) { |quiet| quiet.upcase } + modules = resource.helper_modules o = Object.new modules.each { |m| o.extend(m) } expect(o.shout("shout")).to eq("SHOUT") end it "raises an error when attempting to define a helper method without a method body" do - expect { @resource.helper(:example) }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helper(:example) }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when attempting to define a helper method with a non-Symbod method name" do - expect { @resource.helper("example") { "fail" } }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helper("example") { "fail" } }.to raise_error(Chef::Exceptions::ValidationFailed) end it "collects helper module bodies as blocks" do - @resource.helpers do + resource.helpers do def example_1 "example_1" end end - module_body = @resource.inline_helper_modules.first + module_body = resource.inline_helper_modules.first expect(module_body).to be_a(Proc) end it "compiles helper module bodies into modules" do - @resource.helpers do + resource.helpers do def example_1 "example_1" end end - modules = @resource.helper_modules + modules = resource.helper_modules expect(modules.size).to eq(1) o = Object.new modules.each { |m| o.extend(m) } @@ -172,39 +169,37 @@ describe Chef::Resource::Template do end it "raises an error when no block or module name is given for helpers definition" do - expect { @resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when a non-module is given for helpers definition" do - expect { @resource.helpers("NotAModule") }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helpers("NotAModule") }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when a module name and block are both given for helpers definition" do - expect { @resource.helpers(ExampleHelpers) { module_code } }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helpers(ExampleHelpers) { module_code } }.to raise_error(Chef::Exceptions::ValidationFailed) end it "collects helper modules" do - @resource.helpers(ExampleHelpers) - expect(@resource.helper_modules).to include(ExampleHelpers) + resource.helpers(ExampleHelpers) + expect(resource.helper_modules).to include(ExampleHelpers) end it "combines all helpers into a set of compiled modules" do - @resource.helpers(ExampleHelpers) - @resource.helpers do + resource.helpers(ExampleHelpers) + resource.helpers do def inline_module "inline_module" end end - @resource.helper(:inline_method) { "inline_method" } - expect(@resource.helper_modules.size).to eq(3) + resource.helper(:inline_method) { "inline_method" } + expect(resource.helper_modules.size).to eq(3) o = Object.new - @resource.helper_modules.each { |m| o.extend(m) } + resource.helper_modules.each { |m| o.extend(m) } expect(o.static_example).to eq("static_example") expect(o.inline_module).to eq("inline_module") expect(o.inline_method).to eq("inline_method") end - end - end diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb index 1a3f0284e3..1017f2d65a 100644 --- a/spec/unit/resource/user_spec.rb +++ b/spec/unit/resource/user_spec.rb @@ -19,115 +19,109 @@ require "spec_helper" describe Chef::Resource::User, "initialize" do - before(:each) do - @resource = Chef::Resource::User.new("adam") - end + let(:resource) { Chef::Resource::User.new("adam") } - it "should create a new Chef::Resource::User" do - expect(@resource).to be_a_kind_of(Chef::Resource) - expect(@resource).to be_a_kind_of(Chef::Resource::User) + it "creates a new Chef::Resource::User" do + expect(resource).to be_a_kind_of(Chef::Resource) + expect(resource).to be_a_kind_of(Chef::Resource::User) end - it "should set the resource_name to :user" do - expect(@resource.resource_name).to eql(:user_resource_abstract_base_class) + it "sets the resource_name to :user" do + expect(resource.resource_name).to eql(:user_resource_abstract_base_class) end - it "should set the username equal to the argument to initialize" do - expect(@resource.username).to eql("adam") + it "sets the username equal to the argument to initialize" do + expect(resource.username).to eql("adam") end %w{comment uid gid home shell password}.each do |attrib| - it "should set #{attrib} to nil" do - expect(@resource.send(attrib)).to eql(nil) + it "sets #{attrib} to nil" do + expect(resource.send(attrib)).to eql(nil) end end - it "should set action to :create" do - expect(@resource.action).to eql([:create]) + it "sets action to :create" do + expect(resource.action).to eql([:create]) end - it "should set manage_home to false" do - expect(@resource.manage_home).to eql(false) + it "sets manage_home to false" do + expect(resource.manage_home).to eql(false) end - it "should set non_unique to false" do - expect(@resource.non_unique).to eql(false) + it "sets non_unique to false" do + expect(resource.non_unique).to eql(false) end - it "should set force to false" do - expect(@resource.force).to eql(false) + it "sets force to false" do + expect(resource.force).to eql(false) end %w{create remove modify manage lock unlock}.each do |action| - it "should allow action #{action}" do - expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) + it "allows action #{action}" do + expect(resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end - it "should accept domain users (@ or \ separator) on non-windows" do - expect { @resource.username "domain\@user" }.not_to raise_error - expect(@resource.username).to eq("domain\@user") - expect { @resource.username "domain\\user" }.not_to raise_error - expect(@resource.username).to eq("domain\\user") + it "accepts domain users (@ or \ separator) on non-windows" do + expect { resource.username "domain\@user" }.not_to raise_error + expect(resource.username).to eq("domain\@user") + expect { resource.username "domain\\user" }.not_to raise_error + expect(resource.username).to eq("domain\\user") end end %w{username comment home shell password}.each do |attrib| describe Chef::Resource::User, attrib do - before(:each) do - @resource = Chef::Resource::User.new("adam") - end + let(:resource) { Chef::Resource::User.new("adam") } - it "should allow a string" do - @resource.send(attrib, "adam") - expect(@resource.send(attrib)).to eql("adam") + it "allows a string" do + resource.send(attrib, "adam") + expect(resource.send(attrib)).to eql("adam") end - it "should not allow a hash" do - expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) end end end %w{uid gid}.each do |attrib| describe Chef::Resource::User, attrib do - before(:each) do - @resource = Chef::Resource::User.new("adam") - end + let(:resource) { Chef::Resource::User.new("adam") } - it "should allow a string" do - @resource.send(attrib, "100") - expect(@resource.send(attrib)).to eql("100") + it "allows a string" do + resource.send(attrib, "100") + expect(resource.send(attrib)).to eql("100") end - it "should allow an integer" do - @resource.send(attrib, 100) - expect(@resource.send(attrib)).to eql(100) + it "allows an integer" do + resource.send(attrib, 100) + expect(resource.send(attrib)).to eql(100) end - it "should not allow a hash" do - expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) + it "does not allow a hash" do + expect { resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) end end describe "when it has uid, gid, and home" do + let(:resource) { Chef::Resource::User.new("root") } + before do - @resource = Chef::Resource::User.new("root") - @resource.uid(123) - @resource.gid(456) - @resource.home("/usr/local/root/") + resource.uid(123) + resource.gid(456) + resource.home("/usr/local/root/") end it "describes its state" do - state = @resource.state_for_resource_reporter + state = resource.state_for_resource_reporter expect(state[:uid]).to eq(123) expect(state[:gid]).to eq(456) expect(state[:home]).to eq("/usr/local/root/") end it "returns the username as its identity" do - expect(@resource.identity).to eq("root") + expect(resource.identity).to eq("root") end end - end diff --git a/spec/unit/resource/windows_package_spec.rb b/spec/unit/resource/windows_package_spec.rb index 5aa3707199..0da58ab46e 100644 --- a/spec/unit/resource/windows_package_spec.rb +++ b/spec/unit/resource/windows_package_spec.rb @@ -88,7 +88,7 @@ describe Chef::Resource::WindowsPackage, "initialize" do let(:resource_source) { "https://foo.bar/solitare.msi" } let(:resource) { Chef::Resource::WindowsPackage.new(resource_source) } - it "should return the source unmodified" do + it "returns the source unmodified" do expect(resource.source).to eq(resource_source) end end diff --git a/spec/unit/resource/windows_path_spec.rb b/spec/unit/resource/windows_path_spec.rb index e48e9e14ae..bde39fec9e 100644 --- a/spec/unit/resource/windows_path_spec.rb +++ b/spec/unit/resource/windows_path_spec.rb @@ -19,20 +19,23 @@ require "spec_helper" describe Chef::Resource::WindowsPath do - subject { Chef::Resource::WindowsPath.new("some_path") } - - it { is_expected.to be_a_kind_of(Chef::Resource) } - it { is_expected.to be_a_instance_of(Chef::Resource::WindowsPath) } + let(:resource) { Chef::Resource::WindowsPath.new("some_path") } it "sets resource name as :windows_path" do - expect(subject.resource_name).to eql(:windows_path) + expect(resource.resource_name).to eql(:windows_path) end it "sets the path as its name" do - expect(subject.path).to eql("some_path") + expect(resource.path).to eql("some_path") end it "sets the default action as :add" do - expect(subject.action).to eql(:add) + expect(resource.action).to eql(:add) + end + + it "supports :add and :remove actions" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :delete }.to raise_error(ArgumentError) end end diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb index a1e8417e0e..ce289ce45a 100644 --- a/spec/unit/resource/yum_package_spec.rb +++ b/spec/unit/resource/yum_package_spec.rb @@ -78,7 +78,7 @@ describe Chef::Resource::YumPackage, "arch" do @resource = Chef::Resource::YumPackage.new("foo") end - it "should set the arch variable to whatever is passed in" do + it "sets the arch variable to whatever is passed in" do @resource.arch("i386") expect(@resource.arch).to eql("i386") end diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb index afd6c6739a..3ff9b85f88 100644 --- a/spec/unit/resource/yum_repository_spec.rb +++ b/spec/unit/resource/yum_repository_spec.rb @@ -24,25 +24,78 @@ describe Chef::Resource::YumRepository do let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:resource) { Chef::Resource::YumRepository.new("multiverse", run_context) } - context "on linux", :linux_only do - it "should create a new Chef::Resource::YumRepository" do - expect(resource).to be_a_kind_of(Chef::Resource) - expect(resource).to be_a_kind_of(Chef::Resource::YumRepository) - end + it "has a resource_name of :yum_repository" do + expect(resource.resource_name).to eq(:yum_repository) + end + + it "the repositoryid property is the name_property" do + expect(resource.repositoryid).to eq("multiverse") + end + + it "the timeout property expects numeric Strings" do + expect { resource.timeout "123" }.not_to raise_error(ArgumentError) + expect { resource.timeout "123foo" }.to raise_error(ArgumentError) + end + + it "the priority property expects numeric Strings from '1' to '99'" do + expect { resource.priority "99" }.not_to raise_error(ArgumentError) + expect { resource.priority "1" }.not_to raise_error(ArgumentError) + expect { resource.priority "100" }.to raise_error(ArgumentError) + expect { resource.priority "0" }.to raise_error(ArgumentError) + end + + it "the failovermethod property accepts 'priority' or 'roundrobin'" do + expect { resource.failovermethod "priority" }.not_to raise_error(ArgumentError) + expect { resource.failovermethod "roundrobin" }.not_to raise_error(ArgumentError) + expect { resource.failovermethod "bob" }.to raise_error(ArgumentError) + end + + it "the http_caching property accepts 'packages', 'all', or 'none'" do + expect { resource.http_caching "packages" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "all" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "none" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "bob" }.to raise_error(ArgumentError) + end + + it "the metadata_expire property accepts a time value or 'never'" do + expect { resource.metadata_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "never" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100s" }.to raise_error(ArgumentError) + end - it "should resolve to a Noop class when yum is not found" do + it "the mirror_expire property accepts a time value" do + expect { resource.mirror_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "never" }.to raise_error(ArgumentError) + end + + it "the mirrorlist_expire property accepts a time value" do + expect { resource.mirrorlist_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError) + end + + context "on linux", :linux_only do + it "resolves to a Noop class when yum is not found" do expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(false) expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop) end - it "should resolve to a YumRepository class when yum is found" do + it "resolves to a YumRepository class when yum is found" do expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(true) expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::YumRepository) end end context "on windows", :windows_only do - it "should resolve to a NoOp provider" do + it "resolves to a NoOp provider" do expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop) end end diff --git a/spec/unit/resource/zypper_repository_spec.rb b/spec/unit/resource/zypper_repository_spec.rb index de08b183a5..889a1e1e9a 100644 --- a/spec/unit/resource/zypper_repository_spec.rb +++ b/spec/unit/resource/zypper_repository_spec.rb @@ -24,28 +24,27 @@ describe Chef::Resource::ZypperRepository do let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:resource) { Chef::Resource::ZypperRepository.new("repo-source", run_context) } - context "on linux", :linux_only do - it "should create a new Chef::Resource::ZypperRepository" do - expect(resource).to be_a_kind_of(Chef::Resource) - expect(resource).to be_a_kind_of(Chef::Resource::ZypperRepository) - end + it "has a resource_name of :zypper_repository" do + expect(resource.resource_name).to eq(:zypper_repository) + end - it "should have a name of repo-source" do - expect(resource.name).to eql("repo-source") - end + it "repo_name is the name_property" do + expect(resource.repo_name).to eql("repo-source") + end - it "should have a default action of create" do - expect(resource.action).to eql([:create]) - end + it "has a default action of create" do + expect(resource.action).to eql([:create]) + end - it "supports all valid actions" do - expect { resource.action :add }.not_to raise_error - expect { resource.action :remove }.not_to raise_error - expect { resource.action :create }.not_to raise_error - expect { resource.action :refresh }.not_to raise_error - expect { resource.action :delete }.to raise_error(ArgumentError) - end + it "supports all valid actions" do + expect { resource.action :add }.not_to raise_error + expect { resource.action :remove }.not_to raise_error + expect { resource.action :create }.not_to raise_error + expect { resource.action :refresh }.not_to raise_error + expect { resource.action :delete }.to raise_error(ArgumentError) + end + context "on linux", :linux_only do it "resolves to a Noop class when on non-linux OS" do node.automatic[:os] = "windows" node.automatic[:platform_family] = "windows" |