Sha256: eda24faf7fe89117746ca2907fea139785da87bfcd50034f13d9b7881ea750a2

Contents?: true

Size: 845 Bytes

Versions: 6

Compression:

Stored size: 845 Bytes

Contents

# encoding:utf-8

module Inspec
  class OrTest
    attr_reader :tests
    def initialize(tests)
      @tests = tests
      @negated = false
    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 { |test|
          test.negate!
          test
        }.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

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/inspec/objects/or_test.rb
inspec-2.1.21 lib/inspec/objects/or_test.rb
inspec-2.1.10 lib/inspec/objects/or_test.rb
inspec-2.0.32 lib/inspec/objects/or_test.rb
inspec-2.0.17 lib/inspec/objects/or_test.rb
inspec-1.51.15 lib/inspec/objects/or_test.rb