class Inspec::Object::Describe
Constants
- Test
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
Attributes
qualifier[RW]
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.
skip[RW]
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.
tests[RW]
An array of individual tests for the qualifier. Every entry will be translated into an ‘it` or `its` clause.
variables[RW]
Optional variables which are used by tests.
Public Class Methods
new()
click to toggle source
# File lib/inspec/objects/describe.rb, line 54 def initialize @qualifier = [] @tests = [] @variables = [] end
Public Instance Methods
add_test(its, matcher, expectation, opts = {})
click to toggle source
# File lib/inspec/objects/describe.rb, line 60 def add_test(its, matcher, expectation, opts = {}) test = Inspec::Object::Describe::Test.new(its, matcher, expectation, opts[:negated]) tests.push(test) test end
resource()
click to toggle source
# File lib/inspec/objects/describe.rb, line 76 def resource return if qualifier.empty? || qualifier[0].empty? || qualifier[0][0].empty? qualifier[0][0] end
to_hash()
click to toggle source
# File lib/inspec/objects/describe.rb, line 72 def to_hash { qualifier: qualifier, tests: tests.map(&:to_h), variables: variables, skip: skip } end
to_ruby()
click to toggle source
# File lib/inspec/objects/describe.rb, line 66 def to_ruby return rb_skip unless skip.nil? rb_describe end
Private Instance Methods
rb_describe()
click to toggle source
# File lib/inspec/objects/describe.rb, line 84 def rb_describe vars = variables.map(&:to_ruby).join("\n") vars += "\n" unless vars.empty? objarr = @qualifier objarr = [["unknown object".inspect]] if objarr.nil? || objarr.empty? obj = objarr.map { |q| ruby_qualifier(q) }.join(".") rbtests = tests.map(&:to_ruby).join("\n ") format("%sdescribe %s do\n %s\nend", vars, obj, rbtests) end
rb_skip()
click to toggle source
# File lib/inspec/objects/describe.rb, line 96 def rb_skip obj = @qualifier || skip.inspect format("describe %s do\n skip %s\nend", obj, skip.inspect) end