Class: Inspec::Object::Describe::Test

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

Overview

Internal helper to structure test objects. Should not be exposed to the user as it is hidden behind ‘add_test`, `to_hash`, and `to_ruby` in Inspec::Object::Describe

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expectationObject

Returns the value of attribute expectation

Returns:

  • (Object)

    the current value of expectation



6
7
8
# File 'lib/inspec/objects/describe.rb', line 6

def expectation
  @expectation
end

#itsObject

Returns the value of attribute its

Returns:

  • (Object)

    the current value of its



6
7
8
# File 'lib/inspec/objects/describe.rb', line 6

def its
  @its
end

#matcherObject

Returns the value of attribute matcher

Returns:

  • (Object)

    the current value of matcher



6
7
8
# File 'lib/inspec/objects/describe.rb', line 6

def matcher
  @matcher
end

#negatedObject

Returns the value of attribute negated

Returns:

  • (Object)

    the current value of negated



6
7
8
# File 'lib/inspec/objects/describe.rb', line 6

def negated
  @negated
end

Instance Method Details

#negate!Object



7
8
9
# File 'lib/inspec/objects/describe.rb', line 7

def negate!
  self.negated = !negated
end

#to_rubyObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/inspec/objects/describe.rb', line 11

def to_ruby
  itsy = "it"
  unless its.nil?
    if its.is_a? Array
      itsy = "its(" + its.inspect + ")"
    else
      itsy = "its(" + its.to_s.inspect + ")"
    end
  end
  naughty = negated ? "_not" : ""
  xpect = if expectation.nil?
            ""
          elsif expectation.class == Regexp
            # without this, xpect values like / \/zones\// will not be parsed properly
            "(#{expectation.inspect})"
          else
            " " + expectation.inspect
          end
  format("%s { should%s %s%s }", itsy, naughty, matcher, xpect)
end