Class: Brutal::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/brutal/configuration.rb

Overview

Brutal::Configuration

Since:

  • 1.0.0

Constant Summary collapse

ACTUALS_KEY =

Since:

  • 1.0.0

"actuals"
CONTEXTS_KEY =

Since:

  • 1.0.0

"contexts"
HEADER_KEY =

Since:

  • 1.0.0

"header"
SUBJECT_KEY =

Since:

  • 1.0.0

"subject"
DEFAULT_ACTUALS =

Since:

  • 1.0.0

[].freeze
DEFAULT_CONTEXTS =

Since:

  • 1.0.0

{}.freeze
DEFAULT_HEADER =

Since:

  • 1.0.0

"# Brutal test suite"
DEFAULT_SUBJECT =

Since:

  • 1.0.0

""

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actuals:, contexts:, header:, subject:) ⇒ Configuration

Initialize a new configuration.

Raises:

  • (::TypeError)

Since:

  • 1.0.0



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/brutal/configuration.rb', line 43

def initialize(actuals:, contexts:, header:, subject:)
  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, subject.inspect  unless subject.is_a?(::String)

  @actuals  = actuals.sort
  @contexts = contexts
  @header   = header
  @subject  = subject
end

Instance Attribute Details

#actualsObject (readonly)

Specifies templates to challenge evaluated subjects & get results.

Since:

  • 1.0.0



31
32
33
# File 'lib/brutal/configuration.rb', line 31

def actuals
  @actuals
end

#contextsObject (readonly)

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

Since:

  • 1.0.0



34
35
36
# File 'lib/brutal/configuration.rb', line 34

def contexts
  @contexts
end

#headerObject (readonly)

Specifies the code to execute before generating the test suite.

Since:

  • 1.0.0



37
38
39
# File 'lib/brutal/configuration.rb', line 37

def header
  @header
end

#subjectObject (readonly)

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

Since:

  • 1.0.0



40
41
42
# File 'lib/brutal/configuration.rb', line 40

def subject
  @subject
end

Class Method Details

.load(params) ⇒ Object

Load the configuration parameters.

Parameters:

  • params (Hash)

    Receive the 4 top-level section parameters.

Since:

  • 1.0.0



21
22
23
24
25
26
27
28
# File 'lib/brutal/configuration.rb', line 21

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),
    subject:  params.fetch(SUBJECT_KEY, DEFAULT_SUBJECT)
  )
end