Class: Inspec::Describe

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

Defined Under Namespace

Classes: Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RubyHelper

#ruby_qualifier

Constructor Details

#initializeDescribe

Returns a new instance of Describe.



47
48
49
50
51
# File 'lib/inspec/objects/describe.rb', line 47

def initialize
  @qualifier = []
  @tests = []
  @variables = []
end

Instance Attribute Details

#qualifierObject

A qualifier describing the resource that will be tested. It may consist of the resource identification and multiple accessors to pinpoint the data the user wants to test.



31
32
33
# File 'lib/inspec/objects/describe.rb', line 31

def qualifier
  @qualifier
end

#skipObject

Optional method to skip this describe block altogether. If ‘skip` is defined it takes precendence and will print the skip statement instead of adding other tests.



43
44
45
# File 'lib/inspec/objects/describe.rb', line 43

def skip
  @skip
end

#testsObject

An array of individual tests for the qualifier. Every entry will be translated into an ‘it` or `its` clause.



35
36
37
# File 'lib/inspec/objects/describe.rb', line 35

def tests
  @tests
end

#variablesObject

Optional variables which are used by tests.



38
39
40
# File 'lib/inspec/objects/describe.rb', line 38

def variables
  @variables
end

Instance Method Details

#add_test(its, matcher, expectation) ⇒ Object



53
54
55
56
57
# File 'lib/inspec/objects/describe.rb', line 53

def add_test(its, matcher, expectation)
  test = Inspec::Describe::Test.new(its, matcher, expectation, false)
  tests.push(test)
  test
end

#resourceObject



68
69
70
71
# File 'lib/inspec/objects/describe.rb', line 68

def resource
  return nil if qualifier.empty? || qualifier[0].empty? || qualifier[0][0].empty?
  qualifier[0][0]
end

#to_hashObject



64
65
66
# File 'lib/inspec/objects/describe.rb', line 64

def to_hash
  { qualifier: qualifier, tests: tests.map(&:to_h), variables: variables, skip: skip }
end

#to_rubyObject



59
60
61
62
# File 'lib/inspec/objects/describe.rb', line 59

def to_ruby
  return rb_skip if !skip.nil?
  rb_describe
end