Class: Inspec::OrTest
- Inherits:
-
Object
- Object
- Inspec::OrTest
- Defined in:
- lib/inspec/objects/or_test.rb
Instance Attribute Summary collapse
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
-
#initialize(tests) ⇒ OrTest
constructor
A new instance of OrTest.
- #negate! ⇒ Object
- #skip ⇒ Object
- #to_hash ⇒ Object
- #to_ruby ⇒ Object
Constructor Details
#initialize(tests) ⇒ OrTest
Returns a new instance of OrTest.
6 7 8 9 |
# File 'lib/inspec/objects/or_test.rb', line 6 def initialize(tests) @tests = tests @negated = false end |
Instance Attribute Details
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
5 6 7 |
# File 'lib/inspec/objects/or_test.rb', line 5 def tests @tests end |
Instance Method Details
#negate! ⇒ Object
15 16 17 |
# File 'lib/inspec/objects/or_test.rb', line 15 def negate! @negated = !@negated end |
#skip ⇒ Object
11 12 13 |
# File 'lib/inspec/objects/or_test.rb', line 11 def skip nil end |
#to_hash ⇒ Object
36 37 38 |
# File 'lib/inspec/objects/or_test.rb', line 36 def to_hash { describe_one: @tests.map(&:to_hash) } end |
#to_ruby ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/inspec/objects/or_test.rb', line 19 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 |