chefspec 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chefspec.rb +6 -0
- data/lib/chefspec/chef_runner.rb +58 -1
- data/lib/chefspec/helpers/describe.rb +13 -0
- data/lib/chefspec/monkey_patches/conditional.rb +19 -0
- data/lib/chefspec/version.rb +1 -1
- metadata +23 -21
    
        data/lib/chefspec.rb
    CHANGED
    
    | @@ -20,9 +20,15 @@ if defined?(RSpec) | |
| 20 20 | 
             
              require 'chefspec/matchers/env'
         | 
| 21 21 | 
             
              require 'chefspec/matchers/include_recipe'
         | 
| 22 22 | 
             
              require 'chefspec/matchers/script'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              require 'chefspec/helpers/describe'
         | 
| 25 | 
            +
              RSpec.configure do |c|
         | 
| 26 | 
            +
                c.include ChefSpec::Helpers::Describe
         | 
| 27 | 
            +
              end
         | 
| 23 28 | 
             
            end
         | 
| 24 29 |  | 
| 25 30 | 
             
            require 'chefspec/minitest'
         | 
| 31 | 
            +
            require 'chefspec/monkey_patches/conditional'
         | 
| 26 32 | 
             
            require 'chefspec/monkey_patches/hash'
         | 
| 27 33 | 
             
            require 'chefspec/monkey_patches/lwrp_base'
         | 
| 28 34 | 
             
            require 'chefspec/monkey_patches/provider'
         | 
    
        data/lib/chefspec/chef_runner.rb
    CHANGED
    
    | @@ -22,6 +22,7 @@ module ChefSpec | |
| 22 22 | 
             
                attr_reader :step_into
         | 
| 23 23 | 
             
                attr_reader :run_context
         | 
| 24 24 | 
             
                attr_reader :node
         | 
| 25 | 
            +
                attr_reader :stubbed_commands
         | 
| 25 26 |  | 
| 26 27 | 
             
                # Instantiate a new runner to run examples with.
         | 
| 27 28 | 
             
                #
         | 
| @@ -33,7 +34,13 @@ module ChefSpec | |
| 33 34 | 
             
                # @option options [String] :ohai_data_path Path of a json file that will be passed to fauxhai as :path option
         | 
| 34 35 | 
             
                # @yield [node] Configuration block for Chef::Node
         | 
| 35 36 | 
             
                def initialize(options={})
         | 
| 36 | 
            -
                  defaults = { | 
| 37 | 
            +
                  defaults = {
         | 
| 38 | 
            +
                    :cookbook_path => default_cookbook_path,
         | 
| 39 | 
            +
                    :log_level => :warn,
         | 
| 40 | 
            +
                    :dry_run => false,
         | 
| 41 | 
            +
                    :step_into => [],
         | 
| 42 | 
            +
                    :evaluate_guards => false
         | 
| 43 | 
            +
                  }
         | 
| 37 44 | 
             
                  options = {:cookbook_path => options} unless options.respond_to?(:to_hash) # backwards-compatibility
         | 
| 38 45 | 
             
                  @options = defaults.merge(options)
         | 
| 39 46 |  | 
| @@ -41,6 +48,24 @@ module ChefSpec | |
| 41 48 | 
             
                  @resources = []
         | 
| 42 49 | 
             
                  @step_into = @options[:step_into]
         | 
| 43 50 | 
             
                  @do_dry_run = @options[:dry_run]
         | 
| 51 | 
            +
                  @evaluate_guards = @options[:evaluate_guards]
         | 
| 52 | 
            +
                  @actually_run_shell_guards = @options[:actually_run_shell_guards]
         | 
| 53 | 
            +
                  @stubbed_commands = []
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  Chef::Resource::Conditional.class_eval do
         | 
| 56 | 
            +
                    if self.class.methods.include?(:class_variable_set)
         | 
| 57 | 
            +
                      self.class_variable_set :@@runner, the_runner
         | 
| 58 | 
            +
                    else
         | 
| 59 | 
            +
                      @@runner = the_runner
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
                    def runner
         | 
| 62 | 
            +
                      if self.class.methods.include?(:class_variable_get)
         | 
| 63 | 
            +
                        self.class.send(:class_variable_get, :@@runner)
         | 
| 64 | 
            +
                      else
         | 
| 65 | 
            +
                        @@runner
         | 
| 66 | 
            +
                      end
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
                  end
         | 
| 44 69 |  | 
| 45 70 | 
             
                  Chef::Resource.class_eval do
         | 
| 46 71 | 
             
                    alias :old_run_action :run_action unless method_defined?(:old_run_action)
         | 
| @@ -59,6 +84,16 @@ module ChefSpec | |
| 59 84 | 
             
                        @@runner
         | 
| 60 85 | 
             
                      end
         | 
| 61 86 |  | 
| 87 | 
            +
                      if runner.evaluate_guards?
         | 
| 88 | 
            +
                        if self.respond_to?(:should_skip?) # Chef >= 0.10
         | 
| 89 | 
            +
                          if self.method(:should_skip?).arity == 1
         | 
| 90 | 
            +
                            return if self.should_skip?(action)
         | 
| 91 | 
            +
                          else
         | 
| 92 | 
            +
                            return if self.should_skip?
         | 
| 93 | 
            +
                          end
         | 
| 94 | 
            +
                        end
         | 
| 95 | 
            +
                      end
         | 
| 96 | 
            +
             | 
| 62 97 | 
             
                      if runner.step_into.include?(self.resource_name.to_s)
         | 
| 63 98 | 
             
                        # Ignore not_if / only_if guards
         | 
| 64 99 | 
             
                        if self.only_if.is_a?(Array) # 0.10.x
         | 
| @@ -82,6 +117,11 @@ module ChefSpec | |
| 82 117 | 
             
                  Chef::Config[:cookbook_path] = cookbook_paths
         | 
| 83 118 | 
             
                  Chef::Config[:client_key] = nil
         | 
| 84 119 |  | 
| 120 | 
            +
                  # it should be saved to an instance variable to prevent automatic
         | 
| 121 | 
            +
                  # unlinking during garbage collection
         | 
| 122 | 
            +
                  @dummy_config = Tempfile.new 'chef-config'
         | 
| 123 | 
            +
                  Chef::Config[:config_file] = @dummy_config.path
         | 
| 124 | 
            +
             | 
| 85 125 | 
             
                  # As of Chef 11, Chef uses custom formatters which munge the RSpec output.
         | 
| 86 126 | 
             
                  # This uses a custom formatter which basically tells Chef to shut up.
         | 
| 87 127 | 
             
                  Chef::Config.add_formatter('chefspec') if Chef::Config.respond_to?(:add_formatter)
         | 
| @@ -97,6 +137,15 @@ module ChefSpec | |
| 97 137 | 
             
                  end
         | 
| 98 138 | 
             
                end
         | 
| 99 139 |  | 
| 140 | 
            +
                def stub_command(command, result)
         | 
| 141 | 
            +
                  # We want to preserve insertion order so that stubs are applied in a
         | 
| 142 | 
            +
                  # known order. Ruby 1.9 hashes behave like this but we are still
         | 
| 143 | 
            +
                  # supporting 1.8.
         | 
| 144 | 
            +
                  @stubbed_commands.reject!{|existing_cmd, _| existing_cmd == command}
         | 
| 145 | 
            +
                  @stubbed_commands << [command, result]
         | 
| 146 | 
            +
                  self
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 100 149 | 
             
                # Run the specified recipes, but without actually converging the node.
         | 
| 101 150 | 
             
                #
         | 
| 102 151 | 
             
                # @param [array] recipe_names The names of the recipes to execute
         | 
| @@ -126,6 +175,14 @@ module ChefSpec | |
| 126 175 | 
             
                  self
         | 
| 127 176 | 
             
                end
         | 
| 128 177 |  | 
| 178 | 
            +
                def evaluate_guards?
         | 
| 179 | 
            +
                  !! @evaluate_guards
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                def actually_run_shell_guards?
         | 
| 183 | 
            +
                  !! @actually_run_shell_guards
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
             | 
| 129 186 | 
             
                FILE_RESOURCES    = %w(directory cookbook_file file template link remote_directory remote_file)
         | 
| 130 187 | 
             
                PACKAGE_RESOURCES = %w(package apt_package dpkg_package easy_install_package freebsd_package macports_package portage_package rpm_package chef_gem solaris_package yum_package zypper_package)
         | 
| 131 188 | 
             
                SCRIPT_RESOURCES  = %w(script powershell bash csh perl python ruby)
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            class Chef
         | 
| 2 | 
            +
              class Resource
         | 
| 3 | 
            +
                class Conditional
         | 
| 4 | 
            +
                  alias_method :original_evaluate_command, :evaluate_command
         | 
| 5 | 
            +
                  def evaluate_command
         | 
| 6 | 
            +
                    runner.stubbed_commands.each do |stubbed_cmd, result|
         | 
| 7 | 
            +
                      case command
         | 
| 8 | 
            +
                        when stubbed_cmd then return result
         | 
| 9 | 
            +
                      end
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                    if runner.actually_run_shell_guards?
         | 
| 12 | 
            +
                      return original_evaluate_command
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                    raise RSpec::Mocks::MockExpectationError.new(
         | 
| 15 | 
            +
                      "The following shell guard was unstubbed: #{description}")
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/chefspec/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: chefspec
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.3.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-06-06 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: chef
         | 
| @@ -201,29 +201,31 @@ extra_rdoc_files: [] | |
| 201 201 | 
             
            files:
         | 
| 202 202 | 
             
            - lib/chef/formatters/chefspec.rb
         | 
| 203 203 | 
             
            - lib/chef/knife/cookbook_create_specs.rb
         | 
| 204 | 
            +
            - lib/chefspec.rb
         | 
| 204 205 | 
             
            - lib/chefspec/chef_runner.rb
         | 
| 206 | 
            +
            - lib/chefspec/helpers/describe.rb
         | 
| 207 | 
            +
            - lib/chefspec/minitest.rb
         | 
| 208 | 
            +
            - lib/chefspec/monkey_patches/lwrp_base.rb
         | 
| 209 | 
            +
            - lib/chefspec/monkey_patches/hash.rb
         | 
| 210 | 
            +
            - lib/chefspec/monkey_patches/conditional.rb
         | 
| 211 | 
            +
            - lib/chefspec/monkey_patches/provider.rb
         | 
| 212 | 
            +
            - lib/chefspec/version.rb
         | 
| 213 | 
            +
            - lib/chefspec/matchers/file_content.rb
         | 
| 214 | 
            +
            - lib/chefspec/matchers/ruby_block.rb
         | 
| 215 | 
            +
            - lib/chefspec/matchers/execute.rb
         | 
| 205 216 | 
             
            - lib/chefspec/matchers/cron.rb
         | 
| 217 | 
            +
            - lib/chefspec/matchers/link.rb
         | 
| 218 | 
            +
            - lib/chefspec/matchers/user.rb
         | 
| 206 219 | 
             
            - lib/chefspec/matchers/env.rb
         | 
| 207 | 
            -
            - lib/chefspec/matchers/ | 
| 220 | 
            +
            - lib/chefspec/matchers/script.rb
         | 
| 221 | 
            +
            - lib/chefspec/matchers/package.rb
         | 
| 208 222 | 
             
            - lib/chefspec/matchers/file.rb
         | 
| 209 | 
            -
            - lib/chefspec/matchers/file_content.rb
         | 
| 210 | 
            -
            - lib/chefspec/matchers/group.rb
         | 
| 211 223 | 
             
            - lib/chefspec/matchers/include_recipe.rb
         | 
| 212 | 
            -
            - lib/chefspec/matchers/link.rb
         | 
| 213 224 | 
             
            - lib/chefspec/matchers/log.rb
         | 
| 214 | 
            -
            - lib/chefspec/matchers/notifications.rb
         | 
| 215 | 
            -
            - lib/chefspec/matchers/package.rb
         | 
| 216 | 
            -
            - lib/chefspec/matchers/ruby_block.rb
         | 
| 217 | 
            -
            - lib/chefspec/matchers/script.rb
         | 
| 218 225 | 
             
            - lib/chefspec/matchers/service.rb
         | 
| 219 226 | 
             
            - lib/chefspec/matchers/shared.rb
         | 
| 220 | 
            -
            - lib/chefspec/matchers/ | 
| 221 | 
            -
            - lib/chefspec/ | 
| 222 | 
            -
            - lib/chefspec/monkey_patches/hash.rb
         | 
| 223 | 
            -
            - lib/chefspec/monkey_patches/lwrp_base.rb
         | 
| 224 | 
            -
            - lib/chefspec/monkey_patches/provider.rb
         | 
| 225 | 
            -
            - lib/chefspec/version.rb
         | 
| 226 | 
            -
            - lib/chefspec.rb
         | 
| 227 | 
            +
            - lib/chefspec/matchers/group.rb
         | 
| 228 | 
            +
            - lib/chefspec/matchers/notifications.rb
         | 
| 227 229 | 
             
            homepage: http://acrmp.github.com/chefspec
         | 
| 228 230 | 
             
            licenses:
         | 
| 229 231 | 
             
            - MIT
         | 
| @@ -239,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 239 241 | 
             
                  version: '0'
         | 
| 240 242 | 
             
                  segments:
         | 
| 241 243 | 
             
                  - 0
         | 
| 242 | 
            -
                  hash:  | 
| 244 | 
            +
                  hash: 768299270690559200
         | 
| 243 245 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 244 246 | 
             
              none: false
         | 
| 245 247 | 
             
              requirements:
         | 
| @@ -248,12 +250,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 248 250 | 
             
                  version: '0'
         | 
| 249 251 | 
             
                  segments:
         | 
| 250 252 | 
             
                  - 0
         | 
| 251 | 
            -
                  hash:  | 
| 253 | 
            +
                  hash: 768299270690559200
         | 
| 252 254 | 
             
            requirements: []
         | 
| 253 255 | 
             
            rubyforge_project: 
         | 
| 254 | 
            -
            rubygems_version: 1.8. | 
| 256 | 
            +
            rubygems_version: 1.8.25
         | 
| 255 257 | 
             
            signing_key: 
         | 
| 256 258 | 
             
            specification_version: 3
         | 
| 257 | 
            -
            summary: chefspec-1. | 
| 259 | 
            +
            summary: chefspec-1.3.0
         | 
| 258 260 | 
             
            test_files: []
         | 
| 259 261 | 
             
            has_rdoc: 
         |