Class: Inspec::OrTest

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/objects/or_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tests) ⇒ OrTest

Returns a new instance of OrTest.



9
10
11
12
13
14
# File 'lib/inspec/objects/or_test.rb', line 9

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

Instance Attribute Details

#testsObject (readonly)

Returns the value of attribute tests.



8
9
10
# File 'lib/inspec/objects/or_test.rb', line 8

def tests
  @tests
end

Instance Method Details

#negate!Object



20
21
22
# File 'lib/inspec/objects/or_test.rb', line 20

def negate!
  @negated = !@negated
end

#skipObject



16
17
18
# File 'lib/inspec/objects/or_test.rb', line 16

def skip
  nil
end

#to_hashObject



41
42
43
# File 'lib/inspec/objects/or_test.rb', line 41

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

#to_rubyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inspec/objects/or_test.rb', line 24

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