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-4.29.3 lib/inspec/objects/or_test.rb
inspec-core-4.28.0 lib/inspec/objects/or_test.rb
inspec-core-4.26.13 lib/inspec/objects/or_test.rb
inspec-core-4.26.4 lib/inspec/objects/or_test.rb
inspec-core-4.25.1 lib/inspec/objects/or_test.rb
inspec-core-4.24.32 lib/inspec/objects/or_test.rb
inspec-core-4.24.28 lib/inspec/objects/or_test.rb
inspec-core-4.24.26 lib/inspec/objects/or_test.rb
inspec-core-4.24.8 lib/inspec/objects/or_test.rb
inspec-core-4.23.15 lib/inspec/objects/or_test.rb
inspec-core-4.23.11 lib/inspec/objects/or_test.rb
inspec-core-4.23.10 lib/inspec/objects/or_test.rb
inspec-core-4.23.4 lib/inspec/objects/or_test.rb
inspec-core-4.22.22 lib/inspec/objects/or_test.rb
inspec-core-4.22.8 lib/inspec/objects/or_test.rb
inspec-core-4.22.1 lib/inspec/objects/or_test.rb
inspec-core-4.22.0 lib/inspec/objects/or_test.rb
inspec-core-4.21.3 lib/inspec/objects/or_test.rb
inspec-core-4.21.1 lib/inspec/objects/or_test.rb
inspec-core-4.20.10 lib/inspec/objects/or_test.rb