Class: Brutal::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/brutal/manifest.rb,
lib/brutal/manifest/file.rb,
lib/brutal/manifest/file/name.rb

Overview

Brutal YAML manifest file parser.

Defined Under Namespace

Classes: File

Constant Summary collapse

ACTUALS_KEY =

The actuals top-level section key.

"actuals"
CONTEXTS_KEY =

The contexts top-level section key.

"contexts"
HEADER_KEY =

The header top-level section key.

"header"
BEFORE_KEY =

The before top-level section key.

"before"
SUBJECT_KEY =

The subject top-level section key.

"subject"
AFTER_KEY =

The after top-level section key.

"after"
"footer"
DEFAULT_ACTUALS =

Default actuals collection.

[].freeze
DEFAULT_CONTEXTS =

Default contexts collection.

{}.freeze
DEFAULT_HEADER =

Default header code to evaluate.

""
DEFAULT_BEFORE =

Default before code to evaluate.

""
DEFAULT_AFTER =

Default after code to evaluate.

""
""

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actuals:, contexts:, header:, before:, subject:, after:, footer:) ⇒ Manifest

Initialize a new configuration.

Raises:

  • (::TypeError)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/brutal/manifest.rb', line 89

def initialize(actuals:, contexts:, header:, before:, subject:, after:, footer:)
  raise ::TypeError, actuals.inspect  unless actuals.is_a?(::Array)
  raise ::TypeError, contexts.inspect unless contexts.is_a?(::Hash)
  raise ::TypeError, header.inspect   unless header.is_a?(::String)
  raise ::TypeError, before.inspect   unless before.is_a?(::String)
  raise ::TypeError, subject.inspect  unless subject.is_a?(::String)
  raise ::TypeError, after.inspect    unless after.is_a?(::String)
  raise ::TypeError, footer.inspect   unless footer.is_a?(::String)

  @actuals  = actuals
  @contexts = contexts
  @header   = header
  @before   = before
  @subject  = subject
  @after    = after
  @footer   = footer
end

Instance Attribute Details

#actualsObject (readonly)

Specifies templates to challenge evaluated subjects & get results.



68
69
70
# File 'lib/brutal/manifest.rb', line 68

def actuals
  @actuals
end

#afterObject (readonly)

Specifies a block of lines to be executed after each example.



83
84
85
# File 'lib/brutal/manifest.rb', line 83

def after
  @after
end

#beforeObject (readonly)

Specifies a block of lines to be executed before each example.



77
78
79
# File 'lib/brutal/manifest.rb', line 77

def before
  @before
end

#contextsObject (readonly)

Specifies a list of variables to populate the subject's template.



71
72
73
# File 'lib/brutal/manifest.rb', line 71

def contexts
  @contexts
end

Specifies a block of lines to be executed once after all examples.



86
87
88
# File 'lib/brutal/manifest.rb', line 86

def footer
  @footer
end

#headerObject (readonly)

Specifies a block of lines to be executed once before all examples.



74
75
76
# File 'lib/brutal/manifest.rb', line 74

def header
  @header
end

#subjectObject (readonly)

Specifies the template of the code to be declined across contexts.



80
81
82
# File 'lib/brutal/manifest.rb', line 80

def subject
  @subject
end

Class Method Details

.load(params) ⇒ Object

Load the configuration parameters.

Parameters:

  • params (Hash)

    Receive the 7 top-level section parameters.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/brutal/manifest.rb', line 55

def self.load(params)
  new(
    actuals:  params.fetch(ACTUALS_KEY, DEFAULT_ACTUALS),
    contexts: params.fetch(CONTEXTS_KEY, DEFAULT_CONTEXTS),
    header:   params.fetch(HEADER_KEY, DEFAULT_HEADER),
    before:   params.fetch(BEFORE_KEY, DEFAULT_BEFORE),
    subject:  params.fetch(SUBJECT_KEY),
    after:    params.fetch(AFTER_KEY, DEFAULT_AFTER),
    footer:   params.fetch(FOOTER_KEY, DEFAULT_FOOTER)
  )
end

.parse_file(pathname) ⇒ Object

Parse a file at `pathname`. Returns the YAML manifest instance.



48
49
50
# File 'lib/brutal/manifest.rb', line 48

def self.parse_file(pathname)
  load(File.new(pathname).parse)
end