Sha256: 21d4c1a6a6170055ddc2eb42b74cf6e62090fbeb15471bac4f513668b68f1957

Contents?: true

Size: 1.71 KB

Versions: 38

Compression:

Stored size: 1.71 KB

Contents

#
# License:: Apache License, Version 2.0
#
# 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 expressed or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License
#

require "tmpdir"

module IntegrationSupport
  def when_plugins_directory(description, &block)
    context "When the plugins directory #{description}" do

      before(:each) do
        @plugins_directory = Dir.mktmpdir("ohai-plugins")
      end

      after(:each) do
        if @plugins_directory
          begin
            FileUtils.remove_entry_secure(@plugins_directory)
          ensure
            @plugins_directory = nil
          end
        end
      end

      def with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition
        filename = path_to(plugin_path)
        dir = File.dirname(filename)
        FileUtils.mkdir_p(dir) unless dir == "."
        File.open(filename, "w") do |file|
          file.write(contents)
        end
      end

      def path_to(plugin_path) # rubocop:disable Lint/NestedMethodDefinition
        File.expand_path(plugin_path, @plugins_directory)
      end

      def self.with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition
        before :each do
          with_plugin(plugin_path, contents)
        end
      end

      instance_eval(&block)
    end
  end

end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
ohai-14.15.0 spec/support/integration_helper.rb
ohai-14.14.0 spec/support/integration_helper.rb
ohai-15.2.5 spec/support/integration_helper.rb
ohai-15.1.5 spec/support/integration_helper.rb
ohai-15.1.3 spec/support/integration_helper.rb
ohai-14.8.12 spec/support/integration_helper.rb
ohai-15.0.35 spec/support/integration_helper.rb
ohai-14.8.11 spec/support/integration_helper.rb
ohai-13.12.6 spec/support/integration_helper.rb
ohai-14.8.10 spec/support/integration_helper.rb
ohai-13.12.4 spec/support/integration_helper.rb
ohai-14.6.2 spec/support/integration_helper.rb
ohai-14.5.4 spec/support/integration_helper.rb
ohai-14.5.0 spec/support/integration_helper.rb
ohai-14.4.2 spec/support/integration_helper.rb
ohai-14.4.1 spec/support/integration_helper.rb
ohai-14.4.0 spec/support/integration_helper.rb
ohai-13.10.0 spec/support/integration_helper.rb
ohai-14.3.0 spec/support/integration_helper.rb
ohai-13.9.2 spec/support/integration_helper.rb