chefspec 3.0.1 → 3.0.2
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.
- checksums.yaml +4 -4
- data/lib/chefspec/api/state_attrs.rb +28 -0
- data/lib/chefspec/api.rb +1 -0
- data/lib/chefspec/matchers/state_attrs_matcher.rb +70 -0
- data/lib/chefspec/matchers.rb +1 -0
- data/lib/chefspec/runner.rb +5 -1
- data/lib/chefspec/version.rb +1 -1
- metadata +8 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5c8e999b2df276e377b7c7939430db34e9ba082b
         | 
| 4 | 
            +
              data.tar.gz: 08c074ed6d9633de4e7ea9b83c0f3709c7c91704
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b7f58af30026df43e1c60515e1ba01e6d0dea37443878d3ea10bcec2e47aa4ea91e23c40db8ab8e2a5660255afd6fb6b559d98621bed48999d732bec641bfa2d
         | 
| 7 | 
            +
              data.tar.gz: 1598aefcab47c574882ade3bb99a9f2a4241e26e0c86b791cdce0dabfc7a85a56a7383c148ec2e05568a8a585b865cd54aa69b8c0dac0894ff2998ade28c4701
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module ChefSpec::API
         | 
| 2 | 
            +
              # @since 3.1.0
         | 
| 3 | 
            +
              module StateAttrsMatcher
         | 
| 4 | 
            +
                #
         | 
| 5 | 
            +
                # Assert that a Chef resource has certain state attributes (since Chef
         | 
| 6 | 
            +
                # 11.8.0):
         | 
| 7 | 
            +
                #
         | 
| 8 | 
            +
                #     state_attrs :time, :temperature
         | 
| 9 | 
            +
                #
         | 
| 10 | 
            +
                # @see https://github.com/opscode/chef/blob/e43d7ebda/lib/chef/resource/file.rb#L32-L37
         | 
| 11 | 
            +
                #
         | 
| 12 | 
            +
                # The Examples section demonstrates the different ways to test a
         | 
| 13 | 
            +
                # resource's +state_attrs+ with ChefSpec.
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                # @example Assert the +lwrp+ resource has two state attributes
         | 
| 16 | 
            +
                #   expect(lwrp).to have_state_attrs(:time, :temperature)
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                #
         | 
| 19 | 
            +
                # @param [Array] state_attrs
         | 
| 20 | 
            +
                #   the list of state attributes to assert
         | 
| 21 | 
            +
                #
         | 
| 22 | 
            +
                # @return [ChefSpec::Matchers::StateAttrsMatcher]
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                def have_state_attrs(*state_attrs)
         | 
| 25 | 
            +
                  ChefSpec::Matchers::StateAttrsMatcher.new(state_attrs)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
    
        data/lib/chefspec/api.rb
    CHANGED
    
    | @@ -68,6 +68,7 @@ require_relative 'api/script' | |
| 68 68 | 
             
            require_relative 'api/service'
         | 
| 69 69 | 
             
            require_relative 'api/smartos_package'
         | 
| 70 70 | 
             
            require_relative 'api/solaris_package'
         | 
| 71 | 
            +
            require_relative 'api/state_attrs'
         | 
| 71 72 | 
             
            require_relative 'api/subversion'
         | 
| 72 73 | 
             
            require_relative 'api/template'
         | 
| 73 74 | 
             
            require_relative 'api/user'
         | 
| @@ -0,0 +1,70 @@ | |
| 1 | 
            +
            module ChefSpec::Matchers
         | 
| 2 | 
            +
              class StateAttrsMatcher
         | 
| 3 | 
            +
                #
         | 
| 4 | 
            +
                # Create a new state_attrs matcher.
         | 
| 5 | 
            +
                #
         | 
| 6 | 
            +
                # @param [Array] state_attrs
         | 
| 7 | 
            +
                #
         | 
| 8 | 
            +
                def initialize(state_attrs)
         | 
| 9 | 
            +
                  @expected_attrs = state_attrs.map(&:to_sym)
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def matches?(resource)
         | 
| 13 | 
            +
                  @resource = resource
         | 
| 14 | 
            +
                  @resource && matches_state_attrs?
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def description
         | 
| 18 | 
            +
                  %Q{have state attributes #{@expected_attrs.inspect}}
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def failure_message_for_should
         | 
| 22 | 
            +
                  if @resource
         | 
| 23 | 
            +
                    "expected #{state_attrs.inspect} to equal #{@expected_attrs.inspect}"
         | 
| 24 | 
            +
                  else
         | 
| 25 | 
            +
                    "expected _something_ to have state attributes, but the " \
         | 
| 26 | 
            +
                    "_something_ you gave me was nil!" \
         | 
| 27 | 
            +
                    "\n" \
         | 
| 28 | 
            +
                    "Ensure the resource exists before making assertions:" \
         | 
| 29 | 
            +
                    "\n\n" \
         | 
| 30 | 
            +
                    "  expect(resource).to be" \
         | 
| 31 | 
            +
                    "\n "
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def failure_message_for_should_not
         | 
| 36 | 
            +
                  if @resource
         | 
| 37 | 
            +
                    "expected #{state_attrs.inspect} to not equal " \
         | 
| 38 | 
            +
                    "#{@expected_attrs.inspect}"
         | 
| 39 | 
            +
                  else
         | 
| 40 | 
            +
                    "expected _something_ to not have state attributes, but the " \
         | 
| 41 | 
            +
                    "_something_ you gave me was nil!" \
         | 
| 42 | 
            +
                    "\n" \
         | 
| 43 | 
            +
                    "Ensure the resource exists before making assertions:" \
         | 
| 44 | 
            +
                    "\n\n" \
         | 
| 45 | 
            +
                    "  expect(resource).to be" \
         | 
| 46 | 
            +
                    "\n "
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                private
         | 
| 51 | 
            +
                  #
         | 
| 52 | 
            +
                  # Determine if all the expected state attributes are present on the
         | 
| 53 | 
            +
                  # given resource.
         | 
| 54 | 
            +
                  #
         | 
| 55 | 
            +
                  # @return [Boolean]
         | 
| 56 | 
            +
                  #
         | 
| 57 | 
            +
                  def matches_state_attrs?
         | 
| 58 | 
            +
                    @expected_attrs == state_attrs
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  #
         | 
| 62 | 
            +
                  # The list of state attributes declared on the given resource.
         | 
| 63 | 
            +
                  #
         | 
| 64 | 
            +
                  # @return [Array<Symbol>]
         | 
| 65 | 
            +
                  #
         | 
| 66 | 
            +
                  def state_attrs
         | 
| 67 | 
            +
                    @resource.class.state_attrs.map(&:to_sym)
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
    
        data/lib/chefspec/matchers.rb
    CHANGED
    
    
    
        data/lib/chefspec/runner.rb
    CHANGED
    
    | @@ -239,13 +239,17 @@ module ChefSpec | |
| 239 239 | 
             
                # +step_into+ option takes a string, but this method coerces everything
         | 
| 240 240 | 
             
                # to symbols for safety.
         | 
| 241 241 | 
             
                #
         | 
| 242 | 
            +
                # This method also substitutes any dashes (+-+) with underscores (+_+),
         | 
| 243 | 
            +
                # because that's what Chef does under the hood. (See GitHub issue #254
         | 
| 244 | 
            +
                # for more background)
         | 
| 245 | 
            +
                #
         | 
| 242 246 | 
             
                # @param [Chef::Resource] resource
         | 
| 243 247 | 
             
                #   the Chef resource to try and step in to
         | 
| 244 248 | 
             
                #
         | 
| 245 249 | 
             
                # @return [Boolean]
         | 
| 246 250 | 
             
                #
         | 
| 247 251 | 
             
                def step_into?(resource)
         | 
| 248 | 
            -
                  key = resource.resource_name.to_sym
         | 
| 252 | 
            +
                  key = resource.resource_name.to_s.gsub('-', '_').to_sym
         | 
| 249 253 | 
             
                  Array(options[:step_into]).map(&:to_sym).include?(key)
         | 
| 250 254 | 
             
                end
         | 
| 251 255 |  | 
    
        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: 3.0. | 
| 4 | 
            +
              version: 3.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrew Crump
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-11-06 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: chef
         | 
| @@ -31,14 +31,14 @@ dependencies: | |
| 31 31 | 
             
                requirements:
         | 
| 32 32 | 
             
                - - ~>
         | 
| 33 33 | 
             
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            -
                    version: ' | 
| 34 | 
            +
                    version: '2.0'
         | 
| 35 35 | 
             
              type: :runtime
         | 
| 36 36 | 
             
              prerelease: false
         | 
| 37 37 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 38 | 
             
                requirements:
         | 
| 39 39 | 
             
                - - ~>
         | 
| 40 40 | 
             
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            -
                    version: ' | 
| 41 | 
            +
                    version: '2.0'
         | 
| 42 42 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 43 43 | 
             
              name: rspec
         | 
| 44 44 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -158,6 +158,7 @@ files: | |
| 158 158 | 
             
            - lib/chefspec/api/service.rb
         | 
| 159 159 | 
             
            - lib/chefspec/api/smartos_package.rb
         | 
| 160 160 | 
             
            - lib/chefspec/api/solaris_package.rb
         | 
| 161 | 
            +
            - lib/chefspec/api/state_attrs.rb
         | 
| 161 162 | 
             
            - lib/chefspec/api/subversion.rb
         | 
| 162 163 | 
             
            - lib/chefspec/api/template.rb
         | 
| 163 164 | 
             
            - lib/chefspec/api/user.rb
         | 
| @@ -180,6 +181,7 @@ files: | |
| 180 181 | 
             
            - lib/chefspec/matchers/notifications_matcher.rb
         | 
| 181 182 | 
             
            - lib/chefspec/matchers/render_file_matcher.rb
         | 
| 182 183 | 
             
            - lib/chefspec/matchers/resource_matcher.rb
         | 
| 184 | 
            +
            - lib/chefspec/matchers/state_attrs_matcher.rb
         | 
| 183 185 | 
             
            - lib/chefspec/matchers.rb
         | 
| 184 186 | 
             
            - lib/chefspec/renderer.rb
         | 
| 185 187 | 
             
            - lib/chefspec/rspec.rb
         | 
| @@ -216,9 +218,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 216 218 | 
             
                  version: '0'
         | 
| 217 219 | 
             
            requirements: []
         | 
| 218 220 | 
             
            rubyforge_project: 
         | 
| 219 | 
            -
            rubygems_version: 2. | 
| 221 | 
            +
            rubygems_version: 2.1.10
         | 
| 220 222 | 
             
            signing_key: 
         | 
| 221 223 | 
             
            specification_version: 4
         | 
| 222 | 
            -
            summary: chefspec-3.0. | 
| 224 | 
            +
            summary: chefspec-3.0.2
         | 
| 223 225 | 
             
            test_files: []
         | 
| 224 226 | 
             
            has_rdoc: 
         |