Sha256: 970c6039927a49e215cae22c087701cb806b07c83186846a30b1b6a098b14558

Contents?: true

Size: 1.12 KB

Versions: 77

Compression:

Stored size: 1.12 KB

Contents

# This class is deprecated and will be removed in the next major release of InSpec.
# Use the Inspec::Object classes from the inspec-objects rubygem instead.

require "inspec/utils/deprecation"

module Inspec
  class OrTest
    attr_reader :tests
    def initialize(tests)
      @tests = tests
      @negated = false

      Inspec.deprecate(:object_classes, "The Inspec::OrTest class is deprecated. Use the Inspec::Object::OrTest class from the inspec-objects Ruby library.")
    end

    def skip
      nil
    end

    def negate!
      @negated = !@negated
    end

    def to_ruby
      if @negated
        # We don't use the describe.one wrapper when negated because:
        # !(test1 || test2)     same as    (!test1 && !test2)    where && is implicit in inspec
        all_tests = @tests.map do |test|
          test.negate!
          test
        end.map(&:to_ruby).join("\n")

        all_tests
      else
        all_tests = @tests.map(&:to_ruby).join("\n").gsub("\n", "\n  ")

        format("describe.one do\n  %s\nend", all_tests)
      end
    end

    def to_hash
      { describe_one: @tests.map(&:to_hash) }
    end
  end
end

Version data entries

77 entries across 77 versions & 2 rubygems

Version Path
inspec-core-6.8.11 lib/inspec/objects/or_test.rb
inspec-core-5.22.58 lib/inspec/objects/or_test.rb
inspec-core-5.22.55 lib/inspec/objects/or_test.rb
inspec-core-6.8.1 lib/inspec/objects/or_test.rb
inspec-core-5.22.40 lib/inspec/objects/or_test.rb
inspec-core-6.6.0 lib/inspec/objects/or_test.rb
inspec-core-5.22.36 lib/inspec/objects/or_test.rb
inspec-core-5.22.29 lib/inspec/objects/or_test.rb
inspec-core-4.56.58 lib/inspec/objects/or_test.rb
inspec-core-5.22.3 lib/inspec/objects/or_test.rb
inspec-core-5.21.29 lib/inspec/objects/or_test.rb
inspec-core-5.18.14 lib/inspec/objects/or_test.rb
inspec-core-5.17.4 lib/inspec/objects/or_test.rb
inspec-core-5.14.0 lib/inspec/objects/or_test.rb
inspec-core-4.56.20 lib/inspec/objects/or_test.rb
inspec-core-5.12.2 lib/inspec/objects/or_test.rb
inspec-core-5.10.5 lib/inspec/objects/or_test.rb
inspec-core-4.56.19 lib/inspec/objects/or_test.rb
inspec-core-5.7.9 lib/inspec/objects/or_test.rb
inspec-core-4.56.17 lib/inspec/objects/or_test.rb